(no commit message)
authorErik Brakkee <erik@brakkee.org>
Fri, 16 Jul 2010 10:36:22 +0000 (10:36 +0000)
committerErik Brakkee <erik@brakkee.org>
Fri, 16 Jul 2010 10:36:22 +0000 (10:36 +0000)
support/cdi/src/test/java/org/wamblee/cdi/BeanManagerLookupTest.java

index 8115ac49825c438bdefc021c649f1cd452f6a6bb..c1fd7cb18b1ce877779c03f11b6086a7ad261ac6 100644 (file)
@@ -23,6 +23,8 @@ import javax.naming.InitialContext;
 import org.junit.Test;
 import org.wamblee.support.jndi.StubInitialContextFactory;
 
+import static org.mockito.Mockito.*;
+
 public class BeanManagerLookupTest {
 
     @Test
@@ -33,12 +35,34 @@ public class BeanManagerLookupTest {
         InitialContext ctx = new InitialContext(); 
         ctx.bind(BeanManagerLookup.BEAN_MANAGER_JNDI, setup.getBeanManager());
         try {
-            ctx = new InitialContext(); 
-            BeanManager manager = (BeanManager) ctx.lookup(BeanManagerLookup.BEAN_MANAGER_JNDI);
-            assertSame(setup.getBeanManager(), manager);
+            assertSame(setup.getBeanManager(), BeanManagerLookup.lookup());
         } finally {
             setup.shutdown();
             StubInitialContextFactory.unregister();
         }
     }
+    
+    @Test
+    public void testWithJndiButWithOverride() throws Exception { 
+        BeanManagerSetup setup = new BeanManagerSetup();
+        setup.initialize();
+        StubInitialContextFactory.register();
+        InitialContext ctx = new InitialContext(); 
+        ctx.bind(BeanManagerLookup.BEAN_MANAGER_JNDI, setup.getBeanManager());
+        try {
+            BeanManager override = mock(BeanManager.class);
+            BeanManagerLookup.setBeanManager(override);
+            assertSame(override, BeanManagerLookup.lookup());
+        } finally {
+            setup.shutdown();
+            StubInitialContextFactory.unregister();
+        }
+    }
+    
+    @Test
+    public void testNoJndiButWithOverride() throws Exception { 
+        BeanManager override = mock(BeanManager.class);
+        BeanManagerLookup.setBeanManager(override);
+        assertSame(override, BeanManagerLookup.lookup());
+    }
 }