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

Class RequestInjectionTest

core/test/com/google/inject/RequestInjectionTest.java:32–355  ·  view source on GitHub ↗

@author crazybob@google.com (Bob Lee)

Source from the content-addressed store, hash-verified

30 * @author crazybob@google.com (Bob Lee)
31 */
32public class RequestInjectionTest extends TestCase {
33
34 @Retention(RUNTIME)
35 @BindingAnnotation
36 @interface ForField {}
37
38 @Retention(RUNTIME)
39 @BindingAnnotation
40 @interface ForMethod {}
41
42 @Override
43 protected void setUp() throws Exception {
44 super.setUp();
45 HasInjections.staticField = 0;
46 HasInjections.staticMethod = null;
47 NeedsThing.injectedCount = 0;
48 }
49
50 public void testInjectMembers() {
51 final HasInjections hi = new HasInjections();
52
53 Guice.createInjector(
54 new AbstractModule() {
55 @Override
56 protected void configure() {
57 bindConstant().annotatedWith(ForMethod.class).to("test");
58 bindConstant().annotatedWith(ForField.class).to(5);
59 requestInjection(hi);
60 }
61 });
62
63 assertEquals("test", hi.instanceMethod);
64 assertEquals(5, hi.instanceField);
65 assertNull(HasInjections.staticMethod);
66 assertEquals(0, HasInjections.staticField);
67 }
68
69 public void testInjectStatics() throws CreationException {
70 Guice.createInjector(
71 new AbstractModule() {
72 @Override
73 protected void configure() {
74 bindConstant().annotatedWith(ForMethod.class).to("test");
75 bindConstant().annotatedWith(ForField.class).to(5);
76 requestStaticInjection(HasInjections.class);
77 }
78 });
79
80 assertEquals("test", HasInjections.staticMethod);
81 assertEquals(5, HasInjections.staticField);
82 }
83
84 public void testInjectMembersAndStatics() {
85 final HasInjections hi = new HasInjections();
86
87 Guice.createInjector(
88 new AbstractModule() {
89 @Override

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected