Commit ce4798f42f201dca5bf908d2f7c6cb3f6044b981
1 parent
01a1cb2a
Exists in
master
Refatoração dos testes unitários
Showing
2 changed files
with
46 additions
and
33 deletions
Show diff stats
impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/producer/LoggerProducerTest.java
| ... | ... | @@ -35,6 +35,7 @@ |
| 35 | 35 | * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. |
| 36 | 36 | */ |
| 37 | 37 | package br.gov.frameworkdemoiselle.internal.producer; |
| 38 | + | |
| 38 | 39 | import org.junit.Ignore; |
| 39 | 40 | import static org.easymock.EasyMock.createMock; |
| 40 | 41 | import static org.easymock.EasyMock.expect; |
| ... | ... | @@ -47,7 +48,7 @@ import javax.enterprise.inject.spi.InjectionPoint; |
| 47 | 48 | |
| 48 | 49 | import org.junit.Test; |
| 49 | 50 | import org.slf4j.Logger; |
| 50 | -@Ignore | |
| 51 | + | |
| 51 | 52 | public class LoggerProducerTest { |
| 52 | 53 | |
| 53 | 54 | private Logger logger; | ... | ... |
impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/producer/ResourceBundleProducerTest.java
| ... | ... | @@ -35,20 +35,35 @@ |
| 35 | 35 | * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. |
| 36 | 36 | */ |
| 37 | 37 | package br.gov.frameworkdemoiselle.internal.producer; |
| 38 | -import org.junit.Ignore; | |
| 38 | + | |
| 39 | +import static org.easymock.EasyMock.expect; | |
| 39 | 40 | import static org.junit.Assert.assertTrue; |
| 41 | +import static org.powermock.api.easymock.PowerMock.mockStatic; | |
| 42 | +import static org.powermock.api.easymock.PowerMock.replay; | |
| 40 | 43 | |
| 41 | 44 | import java.util.Locale; |
| 42 | 45 | |
| 46 | +import javax.enterprise.inject.spi.Annotated; | |
| 47 | +import javax.enterprise.inject.spi.InjectionPoint; | |
| 48 | + | |
| 49 | +import org.easymock.EasyMock; | |
| 43 | 50 | import org.junit.After; |
| 44 | 51 | import org.junit.AfterClass; |
| 45 | 52 | import org.junit.Assert; |
| 46 | 53 | import org.junit.Before; |
| 47 | 54 | import org.junit.BeforeClass; |
| 48 | 55 | import org.junit.Test; |
| 56 | +import org.junit.runner.RunWith; | |
| 57 | +import org.powermock.core.classloader.annotations.PrepareForTest; | |
| 58 | +import org.powermock.modules.junit4.PowerMockRunner; | |
| 49 | 59 | |
| 50 | 60 | import br.gov.frameworkdemoiselle.DemoiselleException; |
| 51 | -@Ignore | |
| 61 | +import br.gov.frameworkdemoiselle.annotation.Name; | |
| 62 | +import br.gov.frameworkdemoiselle.util.Beans; | |
| 63 | +import br.gov.frameworkdemoiselle.util.ResourceBundle; | |
| 64 | + | |
| 65 | +@RunWith(PowerMockRunner.class) | |
| 66 | +@PrepareForTest(Beans.class) | |
| 52 | 67 | public class ResourceBundleProducerTest { |
| 53 | 68 | |
| 54 | 69 | @BeforeClass |
| ... | ... | @@ -61,6 +76,11 @@ public class ResourceBundleProducerTest { |
| 61 | 76 | |
| 62 | 77 | @Before |
| 63 | 78 | public void setUp() throws Exception { |
| 79 | + mockStatic(Beans.class); | |
| 80 | + | |
| 81 | + expect(Beans.getReference(Locale.class)).andReturn(Locale.getDefault()); | |
| 82 | + | |
| 83 | + replay(Beans.class); | |
| 64 | 84 | } |
| 65 | 85 | |
| 66 | 86 | @After |
| ... | ... | @@ -73,39 +93,31 @@ public class ResourceBundleProducerTest { |
| 73 | 93 | Assert.assertNotNull(factory); |
| 74 | 94 | } |
| 75 | 95 | |
| 96 | + @Test | |
| 97 | + public void testCreateNullInjectionPoint() { | |
| 98 | + ResourceBundleProducer factory = new ResourceBundleProducer(); | |
| 99 | + ResourceBundle resourceBundle = factory.create((InjectionPoint) null); | |
| 100 | + Assert.assertNotNull(resourceBundle); | |
| 101 | + } | |
| 102 | + | |
| 76 | 103 | @Test |
| 77 | - public void testCreateWithNonExistentFile() { | |
| 78 | - try { | |
| 79 | - ResourceBundleProducer.create("arquivo_inexistente", Locale.getDefault()); | |
| 80 | - } catch (Exception e) { | |
| 81 | - assertTrue(e instanceof DemoiselleException); | |
| 82 | - } | |
| 83 | - } | |
| 104 | + public void testCreateInjectionPointNameAnnoted() { | |
| 105 | + Name name = EasyMock.createMock(Name.class); | |
| 106 | + expect(name.value()).andReturn("demoiselle-core-bundle"); | |
| 107 | + replay(name); | |
| 84 | 108 | |
| 85 | - // @Test | |
| 86 | - // public void testCreateNullInjectionPoint() { | |
| 87 | - // ResourceBundleProducer factory = new ResourceBundleProducer(); | |
| 88 | - // Assert.assertNotNull(factory.create((InjectionPoint) null, Locale.getDefault())); | |
| 89 | - // } | |
| 109 | + Annotated annotated = EasyMock.createMock(Annotated.class); | |
| 110 | + expect(annotated.getAnnotation(Name.class)).andReturn(name).anyTimes(); | |
| 111 | + expect(annotated.isAnnotationPresent(Name.class)).andReturn(true).anyTimes(); | |
| 112 | + replay(annotated); | |
| 90 | 113 | |
| 91 | - // @Test | |
| 92 | - // public void testCreateInjectionPointNameAnnoted() { | |
| 93 | - // Name name = EasyMock.createMock(Name.class); | |
| 94 | - // expect(name.value()).andReturn("demoiselle-core-bundle"); | |
| 95 | - // replay(name); | |
| 96 | - // | |
| 97 | - // Annotated annotated = EasyMock.createMock(Annotated.class); | |
| 98 | - // expect(annotated.getAnnotation(Name.class)).andReturn(name).anyTimes(); | |
| 99 | - // expect(annotated.isAnnotationPresent(Name.class)).andReturn(true).anyTimes(); | |
| 100 | - // replay(annotated); | |
| 101 | - // | |
| 102 | - // InjectionPoint ip = EasyMock.createMock(InjectionPoint.class); | |
| 103 | - // expect(ip.getAnnotated()).andReturn(annotated).anyTimes(); | |
| 104 | - // replay(ip); | |
| 105 | - // | |
| 106 | - // ResourceBundleProducer factory = new ResourceBundleProducer(); | |
| 107 | - // Assert.assertNotNull(factory.create(ip, Locale.getDefault())); | |
| 108 | - // } | |
| 114 | + InjectionPoint ip = EasyMock.createMock(InjectionPoint.class); | |
| 115 | + expect(ip.getAnnotated()).andReturn(annotated).anyTimes(); | |
| 116 | + replay(ip); | |
| 117 | + | |
| 118 | + ResourceBundleProducer factory = new ResourceBundleProducer(); | |
| 119 | + Assert.assertNotNull(factory.create(ip)); | |
| 120 | + } | |
| 109 | 121 | |
| 110 | 122 | // @Test |
| 111 | 123 | // public void testCreateInjectionPointNameUnannoted() { | ... | ... |