(no commit message)
[utils] / support / cdi / src / test / java / org / wamblee / cdi / SimpleInjectorTest.java
index 829f5ceb531cd192d6be8e7ecec2920660b16a87..7c61b2ffa6d70500325d658fdc69cd122e69a8ba 100644 (file)
@@ -18,6 +18,8 @@ package org.wamblee.cdi;
 import static junit.framework.Assert.*;
 import static org.mockito.Mockito.*;
 
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
 import javax.naming.InitialContext;
 
 import org.junit.After;
@@ -25,15 +27,18 @@ import org.junit.Before;
 import org.junit.Test;
 import org.wamblee.inject.Injector;
 import org.wamblee.inject.InjectorFactory;
+import org.wamblee.inject.InjectorBuilder;
 import org.wamblee.inject.SimpleInjector;
-import org.wamblee.support.jndi.StubInitialContextFactory;
+import org.wamblee.test.cdi.BeanManagerSetup;
+import org.wamblee.test.jndi.StubInitialContextFactory;
 
-public class SimpleInjectorTest {
+public class SimpleInjectorTest extends BaseTestFixture {
 
     private BeanManagerSetup setup;
 
     @Before
     public void setUp() throws Exception {
+        super.setUp();
         setup = new BeanManagerSetup();
         setup.initialize();
         StubInitialContextFactory.register();
@@ -43,15 +48,17 @@ public class SimpleInjectorTest {
     }
 
     @After
-    public void tearDown() {
+    public void tearDown() throws Exception {
         StubInitialContextFactory.unregister();
         setup.shutdown();
+        super.tearDown();
     }
 
     @Test
     public void testGetSingleton() {
         MyPojo pojo = new MyPojo();
-        SimpleInjector injector = new SimpleInjector(new CdiInjectorFactory());
+        SimpleInjector injector = new SimpleInjector(new CdiInjectorFactory(
+            BeanManagerLookup.lookup()));
         injector.inject(pojo);
 
         MySingleton obj = pojo.getSingleton();
@@ -77,12 +84,38 @@ public class SimpleInjectorTest {
             @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 X {
+        @Inject
+        private Y y;
+
+    }
+
+    @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();
+        InjectorBuilder.setInjectorFactory(null);
+        InjectorBuilder.getInjector().inject(x);
+    }
+
 }