Commit fd0b9bdf9af67627e9ac3de8e66df8d7d8815c21
1 parent
880e82dd
Exists in
master
Ajustes nos testes das extensões referentes à correção do
ResourceBundleProducer.
Showing
3 changed files
with
28 additions
and
22 deletions
Show diff stats
impl/extension/jpa/src/test/java/br/gov/frameworkdemoiselle/internal/producer/EntityManagerFactoryProducerTest.java
@@ -9,6 +9,7 @@ import static org.powermock.reflect.Whitebox.setInternalState; | @@ -9,6 +9,7 @@ import static org.powermock.reflect.Whitebox.setInternalState; | ||
9 | 9 | ||
10 | import java.util.Collections; | 10 | import java.util.Collections; |
11 | import java.util.HashMap; | 11 | import java.util.HashMap; |
12 | +import java.util.Locale; | ||
12 | import java.util.Map; | 13 | import java.util.Map; |
13 | 14 | ||
14 | import javax.persistence.EntityManagerFactory; | 15 | import javax.persistence.EntityManagerFactory; |
@@ -39,7 +40,7 @@ public class EntityManagerFactoryProducerTest { | @@ -39,7 +40,7 @@ public class EntityManagerFactoryProducerTest { | ||
39 | @Before | 40 | @Before |
40 | public void setUp() { | 41 | public void setUp() { |
41 | logger = createMock(Logger.class); | 42 | logger = createMock(Logger.class); |
42 | - bundle = new ResourceBundleProducer().create("demoiselle-jpa-bundle"); | 43 | + bundle = new ResourceBundleProducer().create("demoiselle-jpa-bundle", Locale.getDefault()); |
43 | producer = new EntityManagerFactoryProducer(); | 44 | producer = new EntityManagerFactoryProducer(); |
44 | cache = Collections.synchronizedMap(new HashMap<String, EntityManagerFactory>()); | 45 | cache = Collections.synchronizedMap(new HashMap<String, EntityManagerFactory>()); |
45 | setInternalState(producer, Map.class, cache); | 46 | setInternalState(producer, Map.class, cache); |
impl/extension/jpa/src/test/java/br/gov/frameworkdemoiselle/internal/producer/EntityManagerProducerTest.java
@@ -46,6 +46,7 @@ import static org.powermock.reflect.Whitebox.setInternalState; | @@ -46,6 +46,7 @@ import static org.powermock.reflect.Whitebox.setInternalState; | ||
46 | 46 | ||
47 | import java.util.Collections; | 47 | import java.util.Collections; |
48 | import java.util.HashMap; | 48 | import java.util.HashMap; |
49 | +import java.util.Locale; | ||
49 | import java.util.Map; | 50 | import java.util.Map; |
50 | 51 | ||
51 | import javax.enterprise.inject.spi.Annotated; | 52 | import javax.enterprise.inject.spi.Annotated; |
@@ -86,11 +87,11 @@ public class EntityManagerProducerTest { | @@ -86,11 +87,11 @@ public class EntityManagerProducerTest { | ||
86 | private Annotated annotated; | 87 | private Annotated annotated; |
87 | 88 | ||
88 | private Name name; | 89 | private Name name; |
89 | - | 90 | + |
90 | private EntityManagerFactory emf; | 91 | private EntityManagerFactory emf; |
91 | - | 92 | + |
92 | private Map<String, EntityManager> cache; | 93 | private Map<String, EntityManager> cache; |
93 | - | 94 | + |
94 | private EntityManager em; | 95 | private EntityManager em; |
95 | 96 | ||
96 | @Before | 97 | @Before |
@@ -105,7 +106,7 @@ public class EntityManagerProducerTest { | @@ -105,7 +106,7 @@ public class EntityManagerProducerTest { | ||
105 | replay(emf, Persistence.class); | 106 | replay(emf, Persistence.class); |
106 | 107 | ||
107 | producer = new EntityManagerProducer(); | 108 | producer = new EntityManagerProducer(); |
108 | - bundle = new ResourceBundleProducer().create("demoiselle-jpa-bundle"); | 109 | + bundle = new ResourceBundleProducer().create("demoiselle-jpa-bundle", Locale.getDefault()); |
109 | logger = createMock(Logger.class); | 110 | logger = createMock(Logger.class); |
110 | 111 | ||
111 | setInternalState(producer, ResourceBundle.class, bundle); | 112 | setInternalState(producer, ResourceBundle.class, bundle); |
@@ -126,14 +127,14 @@ public class EntityManagerProducerTest { | @@ -126,14 +127,14 @@ public class EntityManagerProducerTest { | ||
126 | producer.close(); | 127 | producer.close(); |
127 | verify(em); | 128 | verify(em); |
128 | } | 129 | } |
129 | - | 130 | + |
130 | @Test | 131 | @Test |
131 | public void testGetCache() { | 132 | public void testGetCache() { |
132 | cache = Collections.synchronizedMap(new HashMap<String, EntityManager>()); | 133 | cache = Collections.synchronizedMap(new HashMap<String, EntityManager>()); |
133 | setInternalState(producer, Map.class, cache); | 134 | setInternalState(producer, Map.class, cache); |
134 | Assert.assertEquals(cache, producer.getCache()); | 135 | Assert.assertEquals(cache, producer.getCache()); |
135 | } | 136 | } |
136 | - | 137 | + |
137 | @After | 138 | @After |
138 | public void tearDown() { | 139 | public void tearDown() { |
139 | producer = null; | 140 | producer = null; |
@@ -166,16 +167,16 @@ public class EntityManagerProducerTest { | @@ -166,16 +167,16 @@ public class EntityManagerProducerTest { | ||
166 | 167 | ||
167 | @Test | 168 | @Test |
168 | public void testCreateWithPersistenceUnitNameFromPersistenceXML() { | 169 | public void testCreateWithPersistenceUnitNameFromPersistenceXML() { |
169 | - | 170 | + |
170 | Map<String, EntityManagerFactory> cache = Collections | 171 | Map<String, EntityManagerFactory> cache = Collections |
171 | - .synchronizedMap(new HashMap<String, EntityManagerFactory>()); | ||
172 | - | 172 | + .synchronizedMap(new HashMap<String, EntityManagerFactory>()); |
173 | + | ||
173 | cache.put("pu1", emf); | 174 | cache.put("pu1", emf); |
174 | - | 175 | + |
175 | EntityManagerFactoryProducer entityManagerFactoryProducer = createMock(EntityManagerFactoryProducer.class); | 176 | EntityManagerFactoryProducer entityManagerFactoryProducer = createMock(EntityManagerFactoryProducer.class); |
176 | - | 177 | + |
177 | expect(entityManagerFactoryProducer.getCache()).andReturn(cache); | 178 | expect(entityManagerFactoryProducer.getCache()).andReturn(cache); |
178 | - | 179 | + |
179 | expect(annotated.isAnnotationPresent(Name.class)).andReturn(false); | 180 | expect(annotated.isAnnotationPresent(Name.class)).andReturn(false); |
180 | expect(ip.getAnnotated()).andReturn(annotated).anyTimes(); | 181 | expect(ip.getAnnotated()).andReturn(annotated).anyTimes(); |
181 | expect(config.getPersistenceUnitName()).andReturn(null); | 182 | expect(config.getPersistenceUnitName()).andReturn(null); |
@@ -183,7 +184,7 @@ public class EntityManagerProducerTest { | @@ -183,7 +184,7 @@ public class EntityManagerProducerTest { | ||
183 | replay(annotated, ip, config, entityManagerFactoryProducer); | 184 | replay(annotated, ip, config, entityManagerFactoryProducer); |
184 | 185 | ||
185 | setInternalState(producer, EntityManagerFactoryProducer.class, entityManagerFactoryProducer); | 186 | setInternalState(producer, EntityManagerFactoryProducer.class, entityManagerFactoryProducer); |
186 | - | 187 | + |
187 | EntityManagerProxy entityManagerProxy = (EntityManagerProxy) producer.create(ip, config); | 188 | EntityManagerProxy entityManagerProxy = (EntityManagerProxy) producer.create(ip, config); |
188 | assertNotNull(entityManagerProxy); | 189 | assertNotNull(entityManagerProxy); |
189 | } | 190 | } |
impl/extension/jsf/src/test/java/br/gov/frameworkdemoiselle/template/AbstractEditPageBeanTest.java
@@ -47,6 +47,8 @@ import static org.powermock.api.easymock.PowerMock.replayAll; | @@ -47,6 +47,8 @@ import static org.powermock.api.easymock.PowerMock.replayAll; | ||
47 | import static org.powermock.api.easymock.PowerMock.verifyAll; | 47 | import static org.powermock.api.easymock.PowerMock.verifyAll; |
48 | import static org.powermock.reflect.Whitebox.setInternalState; | 48 | import static org.powermock.reflect.Whitebox.setInternalState; |
49 | 49 | ||
50 | +import java.util.Locale; | ||
51 | + | ||
50 | import javax.faces.component.UIViewRoot; | 52 | import javax.faces.component.UIViewRoot; |
51 | import javax.faces.context.FacesContext; | 53 | import javax.faces.context.FacesContext; |
52 | import javax.faces.convert.Converter; | 54 | import javax.faces.convert.Converter; |
@@ -70,7 +72,8 @@ import br.gov.frameworkdemoiselle.util.ResourceBundle; | @@ -70,7 +72,8 @@ import br.gov.frameworkdemoiselle.util.ResourceBundle; | ||
70 | import com.sun.faces.util.Util; | 72 | import com.sun.faces.util.Util; |
71 | 73 | ||
72 | @RunWith(PowerMockRunner.class) | 74 | @RunWith(PowerMockRunner.class) |
73 | -@PrepareForTest({ Parameter.class, Beans.class, Reflections.class, Converter.class, FacesContext.class, Util.class, Faces.class }) | 75 | +@PrepareForTest({ Parameter.class, Beans.class, Reflections.class, Converter.class, FacesContext.class, Util.class, |
76 | + Faces.class }) | ||
74 | public class AbstractEditPageBeanTest { | 77 | public class AbstractEditPageBeanTest { |
75 | 78 | ||
76 | private AbstractEditPageBean<Contact, Object> pageBean; | 79 | private AbstractEditPageBean<Contact, Object> pageBean; |
@@ -79,7 +82,7 @@ public class AbstractEditPageBeanTest { | @@ -79,7 +82,7 @@ public class AbstractEditPageBeanTest { | ||
79 | 82 | ||
80 | @Before | 83 | @Before |
81 | public void before() { | 84 | public void before() { |
82 | - bundle = new ResourceBundleProducer().create("demoiselle-jsf-bundle"); | 85 | + bundle = new ResourceBundleProducer().create("demoiselle-jsf-bundle", Locale.getDefault()); |
83 | 86 | ||
84 | pageBean = new AbstractEditPageBean<Contact, Object>() { | 87 | pageBean = new AbstractEditPageBean<Contact, Object>() { |
85 | 88 | ||
@@ -242,23 +245,23 @@ public class AbstractEditPageBeanTest { | @@ -242,23 +245,23 @@ public class AbstractEditPageBeanTest { | ||
242 | @SuppressWarnings("unchecked") | 245 | @SuppressWarnings("unchecked") |
243 | public void testGetLongId() { | 246 | public void testGetLongId() { |
244 | mockStatic(Faces.class); | 247 | mockStatic(Faces.class); |
245 | - | 248 | + |
246 | FacesContext facesContext = createMock(FacesContext.class); | 249 | FacesContext facesContext = createMock(FacesContext.class); |
247 | Converter converter = createMock(Converter.class); | 250 | Converter converter = createMock(Converter.class); |
248 | UIViewRoot viewRoot = createMock(UIViewRoot.class); | 251 | UIViewRoot viewRoot = createMock(UIViewRoot.class); |
249 | Parameter<String> parameter = createMock(Parameter.class); | 252 | Parameter<String> parameter = createMock(Parameter.class); |
250 | - | 253 | + |
251 | setInternalState(pageBean, "facesContext", facesContext); | 254 | setInternalState(pageBean, "facesContext", facesContext); |
252 | setInternalState(pageBean, "id", parameter); | 255 | setInternalState(pageBean, "id", parameter); |
253 | setInternalState(pageBean, "idClass", Long.class, AbstractEditPageBean.class); | 256 | setInternalState(pageBean, "idClass", Long.class, AbstractEditPageBean.class); |
254 | - | 257 | + |
255 | String value = "1"; | 258 | String value = "1"; |
256 | - | 259 | + |
257 | expect(parameter.getValue()).andReturn(value); | 260 | expect(parameter.getValue()).andReturn(value); |
258 | expect(facesContext.getViewRoot()).andReturn(viewRoot); | 261 | expect(facesContext.getViewRoot()).andReturn(viewRoot); |
259 | expect(Faces.getConverter(Long.class)).andReturn(converter); | 262 | expect(Faces.getConverter(Long.class)).andReturn(converter); |
260 | expect(converter.getAsObject(facesContext, viewRoot, value)).andReturn(Long.valueOf(value)); | 263 | expect(converter.getAsObject(facesContext, viewRoot, value)).andReturn(Long.valueOf(value)); |
261 | - | 264 | + |
262 | replayAll(); | 265 | replayAll(); |
263 | assertEquals(Long.valueOf(value), pageBean.getId()); | 266 | assertEquals(Long.valueOf(value), pageBean.getId()); |
264 | verifyAll(); | 267 | verifyAll(); |
@@ -276,7 +279,8 @@ public class AbstractEditPageBeanTest { | @@ -276,7 +279,8 @@ public class AbstractEditPageBeanTest { | ||
276 | try { | 279 | try { |
277 | pageBean.getId(); | 280 | pageBean.getId(); |
278 | } catch (DemoiselleException cause) { | 281 | } catch (DemoiselleException cause) { |
279 | - assertEquals(bundle.getString("id-converter-not-found", Contact.class.getCanonicalName()), cause.getMessage()); | 282 | + assertEquals(bundle.getString("id-converter-not-found", Contact.class.getCanonicalName()), |
283 | + cause.getMessage()); | ||
280 | } | 284 | } |
281 | 285 | ||
282 | verifyAll(); | 286 | verifyAll(); |