2 * Copyright 2005-2010 the original author or authors.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.wamblee.cdi;
18 import static junit.framework.Assert.*;
19 import static org.mockito.Mockito.*;
21 import javax.enterprise.inject.spi.BeanManager;
22 import javax.naming.InitialContext;
24 import org.junit.Test;
25 import org.wamblee.support.jndi.StubInitialContextFactory;
27 public class BeanManagerLookupTest extends BaseTestFixture {
30 public void testLookupInJndi() throws Exception {
31 BeanManagerSetup setup = new BeanManagerSetup();
33 StubInitialContextFactory.register();
34 InitialContext ctx = new InitialContext();
35 ctx.bind(BeanManagerLookup.BEAN_MANAGER_JNDI, setup.getBeanManager());
37 assertSame(setup.getBeanManager(), BeanManagerLookup.lookup());
40 StubInitialContextFactory.unregister();
45 public void testWithJndiButWithOverride() throws Exception {
46 BeanManagerSetup setup = new BeanManagerSetup();
48 StubInitialContextFactory.register();
49 InitialContext ctx = new InitialContext();
50 ctx.bind(BeanManagerLookup.BEAN_MANAGER_JNDI, setup.getBeanManager());
52 BeanManager override = mock(BeanManager.class);
53 BeanManagerLookup.setBeanManager(override);
54 assertSame(override, BeanManagerLookup.lookup());
57 StubInitialContextFactory.unregister();
62 public void testNoJndiButWithOverride() throws Exception {
63 BeanManager override = mock(BeanManager.class);
64 BeanManagerLookup.setBeanManager(override);
65 assertSame(override, BeanManagerLookup.lookup());