import org.junit.Test;
import org.wamblee.support.jndi.StubInitialContextFactory;
+import static org.mockito.Mockito.*;
+
public class BeanManagerLookupTest {
@Test
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());
+ }
}