1 package org.wamblee.cdi;
3 import javax.enterprise.context.spi.CreationalContext;
4 import javax.enterprise.inject.spi.AnnotatedType;
5 import javax.enterprise.inject.spi.BeanManager;
6 import javax.enterprise.inject.spi.InjectionTarget;
8 import org.jboss.weld.environment.se.Weld;
9 import org.jboss.weld.environment.se.WeldContainer;
10 import org.junit.After;
11 import org.junit.Before;
12 import org.junit.Test;
13 import static junit.framework.TestCase.*;
15 public class WeldTest {
18 private WeldContainer container;
19 private BeanManager beanManager;
24 container = weld.initialize();
25 beanManager = container.getBeanManager();
29 public void tearDown() {
34 public void testGetSingleton() {
35 AnnotatedType<MyPojo> type = beanManager.createAnnotatedType(MyPojo.class);
36 InjectionTarget<MyPojo> target = beanManager.createInjectionTarget(type);
37 CreationalContext<MyPojo> ctx = beanManager.createCreationalContext(null);
39 MyPojo pojo = new MyPojo();
41 target.inject(pojo, ctx);
43 MySingleton obj = pojo.getSingleton();
47 MyPojo pojo2 = new MyPojo();
48 target.inject(pojo2, ctx);
50 // Objects will not be the same as they are contextual references to the same object.
51 // assertSame(pojo2, pojo);
53 assertEquals(1, MySingleton.getInstances());