From ac4ab368640a790834b3b794424bc511c9701c0a Mon Sep 17 00:00:00 2001 From: erik Date: Fri, 16 Jul 2010 10:36:22 +0000 Subject: [PATCH] --- .../wamblee/cdi/BeanManagerLookupTest.java | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) 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()); + } } -- 2.31.1