From: Erik Brakkee Date: Sat, 31 Jul 2010 17:32:41 +0000 (+0000) Subject: (no commit message) X-Git-Tag: wamblee-utils-0.7~122 X-Git-Url: http://wamblee.org/gitweb/?a=commitdiff_plain;h=d76c1c5b113e82739f8e0ae92288ba120d747111;p=utils --- diff --git a/support/cdi/.project b/support/cdi/.project deleted file mode 100644 index b0870aa2..00000000 --- a/support/cdi/.project +++ /dev/null @@ -1,23 +0,0 @@ - - - wamblee-support-cdi - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.maven.ide.eclipse.maven2Builder - - - - - - org.eclipse.jdt.core.javanature - org.maven.ide.eclipse.maven2Nature - - diff --git a/support/cdi/src/main/java/org/wamblee/cdi/BeanManagerLookup.java b/support/cdi/src/main/java/org/wamblee/cdi/BeanManagerLookup.java index 8d9ab46d..8c9f2cb0 100644 --- a/support/cdi/src/main/java/org/wamblee/cdi/BeanManagerLookup.java +++ b/support/cdi/src/main/java/org/wamblee/cdi/BeanManagerLookup.java @@ -28,9 +28,9 @@ import javax.naming.NamingException; * In case no bean manager is found the beanmanager is set to null and the * problem is logged. * - * This class does caching of the obtained reference to the bean manager. - * As a result, it is necessary to call {@link #setBeanManager(BeanManager)} - * in the setup phase of unit tests to make sure that the lookup is done again. + * This class does caching of the obtained reference to the bean manager. As a + * result, it is necessary to call {@link #setBeanManager(BeanManager)} in the + * setup phase of unit tests to make sure that the lookup is done again. * * @author Erik Brakkee */ diff --git a/support/cdi/src/main/java/org/wamblee/cdi/package-info.java b/support/cdi/src/main/java/org/wamblee/cdi/package-info.java index 65bdfebc..ceb1c7a0 100644 --- a/support/cdi/src/main/java/org/wamblee/cdi/package-info.java +++ b/support/cdi/src/main/java/org/wamblee/cdi/package-info.java @@ -25,4 +25,3 @@ */ package org.wamblee.cdi; - diff --git a/support/cdi/src/test/java/org/wamblee/cdi/BaseTestFixture.java b/support/cdi/src/test/java/org/wamblee/cdi/BaseTestFixture.java index dd3abc40..a8275e0d 100644 --- a/support/cdi/src/test/java/org/wamblee/cdi/BaseTestFixture.java +++ b/support/cdi/src/test/java/org/wamblee/cdi/BaseTestFixture.java @@ -21,14 +21,13 @@ import org.junit.Before; public class BaseTestFixture { @Before - public void setUp() throws Exception { + public void setUp() throws Exception { BeanManagerLookup.setBeanManager(null); } - @After - public void tearDown() throws Exception { + public void tearDown() throws Exception { BeanManagerLookup.setBeanManager(null); } - + } diff --git a/support/cdi/src/test/java/org/wamblee/cdi/BeanManagerLookupTest.java b/support/cdi/src/test/java/org/wamblee/cdi/BeanManagerLookupTest.java index 5b7f51d4..2889a2fa 100644 --- a/support/cdi/src/test/java/org/wamblee/cdi/BeanManagerLookupTest.java +++ b/support/cdi/src/test/java/org/wamblee/cdi/BeanManagerLookupTest.java @@ -25,13 +25,13 @@ import org.junit.Test; import org.wamblee.test.jndi.StubInitialContextFactory; public class BeanManagerLookupTest extends BaseTestFixture { - + @Test public void testLookupInJndi() throws Exception { BeanManagerSetup setup = new BeanManagerSetup(); setup.initialize(); StubInitialContextFactory.register(); - InitialContext ctx = new InitialContext(); + InitialContext ctx = new InitialContext(); ctx.bind(BeanManagerLookup.BEAN_MANAGER_JNDI, setup.getBeanManager()); try { assertSame(setup.getBeanManager(), BeanManagerLookup.lookup()); @@ -40,13 +40,13 @@ public class BeanManagerLookupTest extends BaseTestFixture { StubInitialContextFactory.unregister(); } } - + @Test - public void testWithJndiButWithOverride() throws Exception { + public void testWithJndiButWithOverride() throws Exception { BeanManagerSetup setup = new BeanManagerSetup(); setup.initialize(); StubInitialContextFactory.register(); - InitialContext ctx = new InitialContext(); + InitialContext ctx = new InitialContext(); ctx.bind(BeanManagerLookup.BEAN_MANAGER_JNDI, setup.getBeanManager()); try { BeanManager override = mock(BeanManager.class); @@ -57,9 +57,9 @@ public class BeanManagerLookupTest extends BaseTestFixture { StubInitialContextFactory.unregister(); } } - + @Test - public void testNoJndiButWithOverride() throws Exception { + public void testNoJndiButWithOverride() throws Exception { BeanManager override = mock(BeanManager.class); BeanManagerLookup.setBeanManager(override); assertSame(override, BeanManagerLookup.lookup()); diff --git a/support/cdi/src/test/java/org/wamblee/cdi/BeanManagerSetup.java b/support/cdi/src/test/java/org/wamblee/cdi/BeanManagerSetup.java index cbf85bcf..80650311 100644 --- a/support/cdi/src/test/java/org/wamblee/cdi/BeanManagerSetup.java +++ b/support/cdi/src/test/java/org/wamblee/cdi/BeanManagerSetup.java @@ -35,7 +35,7 @@ public class BeanManagerSetup { container = weld.initialize(); beanManager = container.getBeanManager(); } - + public BeanManager getBeanManager() { return beanManager; } @@ -43,7 +43,7 @@ public class BeanManagerSetup { public void shutdown() { weld.shutdown(); weld = null; - container = null; - beanManager = null; + container = null; + beanManager = null; } } diff --git a/support/cdi/src/test/java/org/wamblee/cdi/CdiInjectorFactoryTest.java b/support/cdi/src/test/java/org/wamblee/cdi/CdiInjectorFactoryTest.java index 5461d5c0..861e8809 100644 --- a/support/cdi/src/test/java/org/wamblee/cdi/CdiInjectorFactoryTest.java +++ b/support/cdi/src/test/java/org/wamblee/cdi/CdiInjectorFactoryTest.java @@ -42,7 +42,8 @@ public class CdiInjectorFactoryTest extends BaseTestFixture { @Test public void testGetInjector() { - InjectorFactory factory = new CdiInjectorFactory(manager.getBeanManager()); + InjectorFactory factory = new CdiInjectorFactory(manager + .getBeanManager()); Injector injector = factory.create(MyPojo.class); MyPojo pojo = new MyPojo(); injector.inject(pojo); diff --git a/support/cdi/src/test/java/org/wamblee/cdi/InjectorBuilderTest.java b/support/cdi/src/test/java/org/wamblee/cdi/InjectorBuilderTest.java index 36440cf4..daffe9b1 100644 --- a/support/cdi/src/test/java/org/wamblee/cdi/InjectorBuilderTest.java +++ b/support/cdi/src/test/java/org/wamblee/cdi/InjectorBuilderTest.java @@ -29,14 +29,13 @@ import org.wamblee.inject.InjectorBuilder; import org.wamblee.test.jndi.StubInitialContextFactory; public class InjectorBuilderTest extends BaseTestFixture { - @Test - public void testCdiInjectorFactoryIsFound() throws Exception { + public void testCdiInjectorFactoryIsFound() throws Exception { BeanManagerSetup setup = new BeanManagerSetup(); setup.initialize(); StubInitialContextFactory.register(); - InitialContext ctx = new InitialContext(); + InitialContext ctx = new InitialContext(); ctx.bind(BeanManagerLookup.BEAN_MANAGER_JNDI, setup.getBeanManager()); try { InjectorFactory factory = InjectorBuilder.getInjectorFactory(); @@ -46,7 +45,7 @@ public class InjectorBuilderTest extends BaseTestFixture { StubInitialContextFactory.unregister(); } } - + @Test public void testInjectManyTimes() { int n = 1000; diff --git a/support/cdi/src/test/java/org/wamblee/cdi/MyPojo.java b/support/cdi/src/test/java/org/wamblee/cdi/MyPojo.java index 0504deb8..573a7f25 100644 --- a/support/cdi/src/test/java/org/wamblee/cdi/MyPojo.java +++ b/support/cdi/src/test/java/org/wamblee/cdi/MyPojo.java @@ -20,16 +20,16 @@ import javax.inject.Inject; public class MyPojo { @Inject - private MySingleton singleton; - - public MyPojo() { + private MySingleton singleton; + + public MyPojo() { // Empty. } - + public MySingleton getSingleton() { return singleton; } - + public void setSingleton(MySingleton aSingleton) { singleton = aSingleton; } diff --git a/support/cdi/src/test/java/org/wamblee/cdi/MySingleton.java b/support/cdi/src/test/java/org/wamblee/cdi/MySingleton.java index 8af870ea..60c0c06f 100644 --- a/support/cdi/src/test/java/org/wamblee/cdi/MySingleton.java +++ b/support/cdi/src/test/java/org/wamblee/cdi/MySingleton.java @@ -17,22 +17,21 @@ package org.wamblee.cdi; import javax.enterprise.context.ApplicationScoped; - @ApplicationScoped public class MySingleton { - - private static int instances = 0; - public MySingleton() { - instances++; + private static int INSTANCES = 0; + + public MySingleton() { + INSTANCES++; } - - public static void reset() { - instances = 0; + + public static void reset() { + INSTANCES = 0; } - + public static int getInstances() { - return instances; + return INSTANCES; } - + } diff --git a/support/cdi/src/test/java/org/wamblee/cdi/SimpleInjectorTest.java b/support/cdi/src/test/java/org/wamblee/cdi/SimpleInjectorTest.java index 93f260e2..7c4bd112 100644 --- a/support/cdi/src/test/java/org/wamblee/cdi/SimpleInjectorTest.java +++ b/support/cdi/src/test/java/org/wamblee/cdi/SimpleInjectorTest.java @@ -43,7 +43,7 @@ public class SimpleInjectorTest extends BaseTestFixture { StubInitialContextFactory.register(); InitialContext ctx = new InitialContext(); ctx.bind(BeanManagerLookup.BEAN_MANAGER_JNDI, setup.getBeanManager()); - MySingleton.reset(); + MySingleton.reset(); } @After @@ -56,7 +56,8 @@ public class SimpleInjectorTest extends BaseTestFixture { @Test public void testGetSingleton() { MyPojo pojo = new MyPojo(); - SimpleInjector injector = new SimpleInjector(new CdiInjectorFactory(BeanManagerLookup.lookup())); + SimpleInjector injector = new SimpleInjector(new CdiInjectorFactory( + BeanManagerLookup.lookup())); injector.inject(pojo); MySingleton obj = pojo.getSingleton(); @@ -82,37 +83,38 @@ public class SimpleInjectorTest extends BaseTestFixture { @Override public void inject(Object aComponent) { MyPojo pojo2 = (MyPojo) aComponent; - pojo2.setSingleton(singleton); + pojo2.setSingleton(singleton); } }); - + injector.inject(pojo); - // verify the custom injector was called. + // verify the custom injector was called. assertSame(singleton, pojo.getSingleton()); } - + @RequestScoped - public static class Y { - + public static class Y { + } - public static class X { + + public static class X { @Inject - private Y y; - + private Y y; + } - - @Test - public void testInjectStorage() throws Exception { - X x = new X(); + + @Test + public void testInjectStorage() throws Exception { + X x = new X(); InjectorBuilder.setInjectorFactory(null); InjectorBuilder.getInjector().inject(x); } - - @Test - public void testInjectStorage2() { - X x = new X(); + + @Test + public void testInjectStorage2() { + X x = new X(); InjectorBuilder.setInjectorFactory(null); InjectorBuilder.getInjector().inject(x); } - + } 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 64060837..d2aa8a55 100644 --- a/support/cdi/src/test/java/org/wamblee/cdi/WeldTest.java +++ b/support/cdi/src/test/java/org/wamblee/cdi/WeldTest.java @@ -11,46 +11,50 @@ import org.junit.Before; import org.junit.Test; 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() { + public void testAgain() { testGetSingleton(); } }