X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=support%2Fcdi%2Fsrc%2Ftest%2Fjava%2Forg%2Fwamblee%2Fcdi%2FWeldTest.java;h=c6f378e81188f62870b49e959851bd1649d52402;hb=9b768a517d7fffa74b978431ee7a5947ec078798;hp=57fa4ad247ddccf41bdff9b3fcdc48a554289e43;hpb=efe818bf40c144c19d25c4df283996667de84cf4;p=utils diff --git a/support/cdi/src/test/java/org/wamblee/cdi/WeldTest.java b/support/cdi/src/test/java/org/wamblee/cdi/WeldTest.java index 57fa4ad2..c6f378e8 100644 --- a/support/cdi/src/test/java/org/wamblee/cdi/WeldTest.java +++ b/support/cdi/src/test/java/org/wamblee/cdi/WeldTest.java @@ -9,43 +9,53 @@ import javax.enterprise.inject.spi.InjectionTarget; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.wamblee.test.cdi.BeanManagerSetup; public class WeldTest { - - private BeanManagerSetup setup; - + + private BeanManagerSetup setup; + @Before public void setUp() { - setup = new BeanManagerSetup(); - setup.initialize(); + setup = new BeanManagerSetup(); + setup.initialize(); MySingleton.reset(); } - + @After - public void tearDown() { + public void tearDown() { setup.shutdown(); } - + @Test - public void testGetSingleton() { - AnnotatedType type = setup.getBeanManager().createAnnotatedType(MyPojo.class); - InjectionTarget target = setup.getBeanManager().createInjectionTarget(type); - CreationalContext ctx = setup.getBeanManager().createCreationalContext(null); - - MyPojo pojo = new MyPojo(); - - target.inject(pojo, ctx); - - MySingleton obj = pojo.getSingleton(); - + public void testGetSingleton() { + AnnotatedType type = setup.getBeanManager() + .createAnnotatedType(MyPojo.class); + InjectionTarget target = setup.getBeanManager() + .createInjectionTarget(type); + CreationalContext ctx = setup.getBeanManager() + .createCreationalContext(null); + + MyPojo pojo = new MyPojo(); + + target.inject(pojo, ctx); + + MySingleton obj = pojo.getSingleton(); + assertNotNull(obj); - - MyPojo pojo2 = new MyPojo(); - target.inject(pojo2, ctx); - - // Objects will not be the same as they are contextual references to the same object. + + MyPojo pojo2 = new MyPojo(); + target.inject(pojo2, ctx); + + // Objects will not be the same as they are contextual references to the + // same object. // assertSame(pojo2, pojo); assertEquals(1, MySingleton.getInstances()); } + + @Test + public void testAgain() { + testGetSingleton(); + } }