From: Erik Brakkee Date: Fri, 16 Jul 2010 10:36:22 +0000 (+0000) Subject: (no commit message) X-Git-Tag: wamblee-utils-0.7~308 X-Git-Url: http://wamblee.org/gitweb/?a=commitdiff_plain;h=f72c6154065a85e59e1b494927a355f869faf8c6;p=utils --- 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 8115ac49..c1fd7cb1 100644 --- a/support/cdi/src/test/java/org/wamblee/cdi/BeanManagerLookupTest.java +++ b/support/cdi/src/test/java/org/wamblee/cdi/BeanManagerLookupTest.java @@ -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()); + } }