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