(no commit message)
[utils] / support / cdi / src / test / java / org / wamblee / cdi / CdiInjectorTest.java
1 /*
2  * Copyright 2005-2010 the original author or authors.
3  * 
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
7  * 
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  * 
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.
15  */
16 package org.wamblee.cdi;
17
18 import static junit.framework.Assert.*;
19
20 import org.junit.After;
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.wamblee.inject.InjectorBuilder;
24
25 public class CdiInjectorTest extends BaseTestFixture {
26
27     private BeanManagerSetup manager;
28
29     @Before
30     public void setUp() throws Exception {
31         super.setUp();
32         manager = new BeanManagerSetup();
33         manager.initialize();
34     }
35
36     @After
37     public void tearDown() throws Exception {
38         manager.shutdown();
39         super.tearDown();
40     }
41
42     @Test
43     public void testInject() {
44         CdiInjector injector = new CdiInjector(manager.getBeanManager(),
45             MyPojo.class);
46         MyPojo pojo = new MyPojo();
47         injector.inject(pojo);
48         assertNotNull(pojo.getSingleton());
49     }
50
51     @Test(expected = IllegalArgumentException.class)
52     public void testWrongType() {
53         CdiInjector injector = new CdiInjector(manager.getBeanManager(),
54             String.class);
55         MyPojo pojo = new MyPojo();
56         injector.inject(pojo);
57     }
58
59     @Test
60     public void testNullObject() {
61         CdiInjector injector = new CdiInjector(manager.getBeanManager(),
62             MyPojo.class);
63         injector.inject(null);
64
65         // ok should simply ignore.
66     }
67 }