Commit c023c8dfd3f92f6e651f86f978c2cec0836cbb60
1 parent
26aeb858
Exists in
master
Ajustes nos testes do Core referentes ao ajuste no
ResourceBundleProducer.
Showing
5 changed files
with
24 additions
and
55 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AbstractBootstrap.java
| ... | ... | @@ -49,7 +49,7 @@ import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer; |
| 49 | 49 | import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer; |
| 50 | 50 | import br.gov.frameworkdemoiselle.util.ResourceBundle; |
| 51 | 51 | |
| 52 | -public class AbstractBootstrap implements Extension { | |
| 52 | +public abstract class AbstractBootstrap implements Extension { | |
| 53 | 53 | |
| 54 | 54 | private static ResourceBundleProducer bundleFactory = new ResourceBundleProducer(); |
| 55 | 55 | ... | ... |
impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/bootstrap/AbstractBootstrapTest.java
| ... | ... | @@ -41,11 +41,12 @@ import static org.powermock.api.easymock.PowerMock.mockStatic; |
| 41 | 41 | import static org.powermock.api.easymock.PowerMock.replayAll; |
| 42 | 42 | import static org.powermock.api.easymock.PowerMock.verifyAll; |
| 43 | 43 | |
| 44 | +import java.util.Locale; | |
| 45 | + | |
| 44 | 46 | import javax.enterprise.inject.spi.AfterBeanDiscovery; |
| 45 | 47 | import javax.inject.Scope; |
| 46 | 48 | |
| 47 | 49 | import org.easymock.EasyMock; |
| 48 | -import org.junit.Before; | |
| 49 | 50 | import org.junit.Test; |
| 50 | 51 | import org.junit.runner.RunWith; |
| 51 | 52 | import org.powermock.api.easymock.PowerMock; |
| ... | ... | @@ -63,30 +64,24 @@ import br.gov.frameworkdemoiselle.util.ResourceBundle; |
| 63 | 64 | @RunWith(PowerMockRunner.class) |
| 64 | 65 | @PrepareForTest({ LoggerProducer.class, Contexts.class }) |
| 65 | 66 | public class AbstractBootstrapTest { |
| 66 | - | |
| 67 | - private AbstractBootstrap bootstrap; | |
| 68 | - | |
| 69 | - @Before | |
| 70 | - public void setUp() { | |
| 71 | - bootstrap = new AbstractBootstrap(); | |
| 72 | - } | |
| 73 | - | |
| 74 | - @SuppressWarnings("unchecked") | |
| 67 | + | |
| 75 | 68 | @Test |
| 69 | + @SuppressWarnings("unchecked") | |
| 76 | 70 | public void testAddContext() { |
| 77 | 71 | mockStatic(LoggerProducer.class); |
| 78 | 72 | mockStatic(Contexts.class); |
| 79 | 73 | |
| 80 | 74 | Logger logger = PowerMock.createMock(Logger.class); |
| 81 | 75 | logger.trace(EasyMock.anyObject(String.class)); |
| 82 | - | |
| 76 | + | |
| 83 | 77 | expect(LoggerProducer.create(EasyMock.anyObject(Class.class))).andReturn(logger); |
| 84 | 78 | |
| 85 | 79 | ResourceBundle bundle = PowerMock.createMock(ResourceBundle.class); |
| 86 | 80 | expect(bundle.getString(EasyMock.anyObject(String.class), EasyMock.anyObject(String.class))).andReturn(null); |
| 87 | 81 | |
| 88 | 82 | ResourceBundleProducer bundleFactory = PowerMock.createMock(ResourceBundleProducer.class); |
| 89 | - expect(bundleFactory.create(EasyMock.anyObject(String.class))).andReturn(bundle); | |
| 83 | + expect(bundleFactory.create(EasyMock.anyObject(String.class), EasyMock.anyObject(Locale.class))).andReturn( | |
| 84 | + bundle); | |
| 90 | 85 | |
| 91 | 86 | Whitebox.setInternalState(AbstractBootstrap.class, "bundleFactory", bundleFactory); |
| 92 | 87 | |
| ... | ... | @@ -94,16 +89,14 @@ public class AbstractBootstrapTest { |
| 94 | 89 | Contexts.add(EasyMock.anyObject(ThreadLocalContext.class), EasyMock.anyObject(AfterBeanDiscovery.class)); |
| 95 | 90 | replayAll(bundle, bundleFactory, logger, LoggerProducer.class, Contexts.class); |
| 96 | 91 | |
| 97 | - bootstrap.addContext(context,null); | |
| 92 | + AbstractBootstrap.addContext(context, null); | |
| 98 | 93 | |
| 99 | 94 | verifyAll(); |
| 100 | 95 | } |
| 101 | 96 | |
| 102 | - @SuppressWarnings("unchecked") | |
| 103 | 97 | @Test |
| 98 | + @SuppressWarnings("unchecked") | |
| 104 | 99 | public void testDisableContext() { |
| 105 | - AbstractBootstrap bootstrap = new AbstractBootstrap(); | |
| 106 | - | |
| 107 | 100 | mockStatic(LoggerProducer.class); |
| 108 | 101 | mockStatic(Contexts.class); |
| 109 | 102 | |
| ... | ... | @@ -115,7 +108,8 @@ public class AbstractBootstrapTest { |
| 115 | 108 | expect(bundle.getString(EasyMock.anyObject(String.class), EasyMock.anyObject(String.class))).andReturn(null); |
| 116 | 109 | |
| 117 | 110 | ResourceBundleProducer bundleFactory = PowerMock.createMock(ResourceBundleProducer.class); |
| 118 | - expect(bundleFactory.create(EasyMock.anyObject(String.class))).andReturn(bundle); | |
| 111 | + expect(bundleFactory.create(EasyMock.anyObject(String.class), EasyMock.anyObject(Locale.class))).andReturn( | |
| 112 | + bundle); | |
| 119 | 113 | |
| 120 | 114 | Whitebox.setInternalState(AbstractBootstrap.class, "bundleFactory", bundleFactory); |
| 121 | 115 | |
| ... | ... | @@ -124,7 +118,7 @@ public class AbstractBootstrapTest { |
| 124 | 118 | Contexts.remove(context); |
| 125 | 119 | replayAll(bundle, bundleFactory, logger, LoggerProducer.class, Contexts.class); |
| 126 | 120 | |
| 127 | - bootstrap.disableContext(context); | |
| 121 | + AbstractBootstrap.disableContext(context); | |
| 128 | 122 | |
| 129 | 123 | verifyAll(); |
| 130 | 124 | } | ... | ... |
impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/bootstrap/ShutdownBootstrapTest.java
| ... | ... | @@ -48,6 +48,7 @@ import java.lang.reflect.Field; |
| 48 | 48 | import java.util.ArrayList; |
| 49 | 49 | import java.util.HashSet; |
| 50 | 50 | import java.util.List; |
| 51 | +import java.util.Locale; | |
| 51 | 52 | import java.util.Set; |
| 52 | 53 | |
| 53 | 54 | import javax.enterprise.inject.spi.AfterBeanDiscovery; |
| ... | ... | @@ -151,7 +152,8 @@ public class ShutdownBootstrapTest { |
| 151 | 152 | ResourceBundle bundle = PowerMock.createMock(ResourceBundle.class); |
| 152 | 153 | |
| 153 | 154 | expect(LoggerProducer.create(EasyMock.anyObject(Class.class))).andReturn(logger).anyTimes(); |
| 154 | - expect(bundleFactory.create(EasyMock.anyObject(String.class))).andReturn(bundle).anyTimes(); | |
| 155 | + expect(bundleFactory.create(EasyMock.anyObject(String.class), EasyMock.anyObject(Locale.class))).andReturn( | |
| 156 | + bundle).anyTimes(); | |
| 155 | 157 | expect(bundle.getString(EasyMock.anyObject(String.class), EasyMock.anyObject(String.class))).andReturn("") |
| 156 | 158 | .anyTimes(); |
| 157 | 159 | |
| ... | ... | @@ -175,7 +177,7 @@ public class ShutdownBootstrapTest { |
| 175 | 177 | EasyMock.expectLastCall().anyTimes(); |
| 176 | 178 | |
| 177 | 179 | PowerMock.replayAll(); |
| 178 | - bootstrap.shuttingDown(null); | |
| 180 | + ShutdownBootstrap.shuttingDown(null); | |
| 179 | 181 | |
| 180 | 182 | assertTrue(list.isEmpty()); |
| 181 | 183 | PowerMock.verifyAll(); | ... | ... |
impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/bootstrap/StartupBootstrapTest.java
| ... | ... | @@ -48,6 +48,7 @@ import static org.junit.Assert.fail; |
| 48 | 48 | import java.lang.reflect.Field; |
| 49 | 49 | import java.util.HashSet; |
| 50 | 50 | import java.util.List; |
| 51 | +import java.util.Locale; | |
| 51 | 52 | import java.util.Set; |
| 52 | 53 | |
| 53 | 54 | import javax.enterprise.context.ConversationScoped; |
| ... | ... | @@ -160,7 +161,8 @@ public class StartupBootstrapTest { |
| 160 | 161 | assertTrue(tempContexts.isEmpty()); |
| 161 | 162 | |
| 162 | 163 | expect(LoggerProducer.create(EasyMock.anyObject(Class.class))).andReturn(logger).anyTimes(); |
| 163 | - expect(bundleFactory.create(EasyMock.anyObject(String.class))).andReturn(bundle).anyTimes(); | |
| 164 | + expect(bundleFactory.create(EasyMock.anyObject(String.class), EasyMock.anyObject(Locale.class))).andReturn( | |
| 165 | + bundle).anyTimes(); | |
| 164 | 166 | expect(bundle.getString(EasyMock.anyObject(String.class), EasyMock.anyObject(String.class))).andReturn("") |
| 165 | 167 | .anyTimes(); |
| 166 | 168 | |
| ... | ... | @@ -199,7 +201,8 @@ public class StartupBootstrapTest { |
| 199 | 201 | ResourceBundle bundle = PowerMock.createMock(ResourceBundle.class); |
| 200 | 202 | |
| 201 | 203 | expect(LoggerProducer.create(EasyMock.anyObject(Class.class))).andReturn(logger).anyTimes(); |
| 202 | - expect(bundleFactory.create(EasyMock.anyObject(String.class))).andReturn(bundle).anyTimes(); | |
| 204 | + expect(bundleFactory.create(EasyMock.anyObject(String.class), EasyMock.anyObject(Locale.class))).andReturn( | |
| 205 | + bundle).anyTimes(); | |
| 203 | 206 | expect(bundle.getString(EasyMock.anyObject(String.class), EasyMock.anyObject(String.class))).andReturn("") |
| 204 | 207 | .anyTimes(); |
| 205 | 208 | |
| ... | ... | @@ -236,9 +239,7 @@ public class StartupBootstrapTest { |
| 236 | 239 | } catch (Throwable e) { |
| 237 | 240 | fail(); |
| 238 | 241 | } |
| 239 | - | |
| 240 | 242 | } |
| 241 | - | |
| 242 | 243 | } |
| 243 | 244 | |
| 244 | 245 | @SuppressWarnings("rawtypes") | ... | ... |
impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/producer/ResourceBundleProducerTest.java
| ... | ... | @@ -55,7 +55,6 @@ import org.junit.Test; |
| 55 | 55 | |
| 56 | 56 | import br.gov.frameworkdemoiselle.DemoiselleException; |
| 57 | 57 | import br.gov.frameworkdemoiselle.annotation.Name; |
| 58 | -import br.gov.frameworkdemoiselle.util.ResourceBundle; | |
| 59 | 58 | |
| 60 | 59 | public class ResourceBundleProducerTest { |
| 61 | 60 | |
| ... | ... | @@ -82,28 +81,10 @@ public class ResourceBundleProducerTest { |
| 82 | 81 | } |
| 83 | 82 | |
| 84 | 83 | @Test |
| 85 | - public void testResourceBundleFactoryLocale() { | |
| 86 | - ResourceBundleProducer factory = new ResourceBundleProducer(Locale.getDefault()); | |
| 87 | - Assert.assertNotNull(factory); | |
| 88 | - } | |
| 89 | - | |
| 90 | - @Test | |
| 91 | - public void testCreateString() { | |
| 92 | - ResourceBundleProducer factory = new ResourceBundleProducer(Locale.getDefault()); | |
| 93 | - Assert.assertNotNull(factory.create("demoiselle-core-bundle")); | |
| 94 | - } | |
| 95 | - | |
| 96 | - @Test | |
| 97 | - public void testCreateStringWithoutLocale() { | |
| 98 | - ResourceBundleProducer factory = new ResourceBundleProducer(); | |
| 99 | - Assert.assertNotNull(factory.create("demoiselle-core-bundle")); | |
| 100 | - } | |
| 101 | - | |
| 102 | - @Test | |
| 103 | 84 | public void testCreateWithNonExistentFile() { |
| 104 | - ResourceBundleProducer factory = new ResourceBundleProducer(Locale.getDefault()); | |
| 85 | + ResourceBundleProducer factory = new ResourceBundleProducer(); | |
| 105 | 86 | try { |
| 106 | - factory.create("arquivo_inexistente"); | |
| 87 | + factory.create("arquivo_inexistente", Locale.getDefault()); | |
| 107 | 88 | } catch (Exception e) { |
| 108 | 89 | assertTrue(e instanceof DemoiselleException); |
| 109 | 90 | } |
| ... | ... | @@ -147,13 +128,4 @@ public class ResourceBundleProducerTest { |
| 147 | 128 | ResourceBundleProducer factory = new ResourceBundleProducer(); |
| 148 | 129 | Assert.assertNotNull(factory.create(ip, Locale.getDefault())); |
| 149 | 130 | } |
| 150 | - | |
| 151 | - @Test | |
| 152 | - public void testCreateTwice() { | |
| 153 | - ResourceBundleProducer factory = new ResourceBundleProducer(Locale.getDefault()); | |
| 154 | - ResourceBundle bundle = factory.create("demoiselle-core-bundle"); | |
| 155 | - | |
| 156 | - Assert.assertNotNull(bundle); | |
| 157 | - Assert.assertEquals(bundle, factory.create("demoiselle-core-bundle")); | |
| 158 | - } | |
| 159 | 131 | } | ... | ... |