MCPcopy Create free account
hub / github.com/google/guice / JakartaTest

Class JakartaTest

core/test/com/googlecode/guice/JakartaTest.java:46–538  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

44import junit.framework.TestCase;
45
46public class JakartaTest extends TestCase {
47
48 private final B b = new B();
49 private final C c = new C();
50 private final D d = new D();
51 private final E e = new E();
52
53 @Override
54 protected void setUp() throws Exception {
55 J.nextInstanceId = 0;
56 K.nextInstanceId = 0;
57 }
58
59 public void testInject() {
60 Injector injector =
61 Guice.createInjector(
62 new AbstractModule() {
63 @Override
64 protected void configure() {
65 bind(B.class).toInstance(b);
66 bind(C.class).toInstance(c);
67 bind(D.class).toInstance(d);
68 bind(E.class).toInstance(e);
69 bind(A.class);
70 }
71 });
72
73 A a = injector.getInstance(A.class);
74 assertSame(b, a.b);
75 assertSame(c, a.c);
76 assertSame(d, a.d);
77 assertSame(e, a.e);
78 }
79
80 public void testQualifiedInject() {
81 Injector injector =
82 Guice.createInjector(
83 new AbstractModule() {
84 @Override
85 protected void configure() {
86 bind(B.class).annotatedWith(Names.named("jodie")).toInstance(b);
87 bind(C.class).annotatedWith(Red.class).toInstance(c);
88 bind(D.class).annotatedWith(RED).toInstance(d);
89 bind(E.class).annotatedWith(Names.named("jesse")).toInstance(e);
90 bind(F.class);
91 }
92 });
93
94 F f = injector.getInstance(F.class);
95 assertSame(b, f.b);
96 assertSame(c, f.c);
97 assertSame(d, f.d);
98 assertSame(e, f.e);
99 }
100
101 public void testProviderInject() {
102 Injector injector =
103 Guice.createInjector(

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected