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

Method testMissingBindings

core/test/com/google/inject/BinderTest.java:99–150  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

97 static class Foo {}
98
99 public void testMissingBindings() {
100 try {
101 Guice.createInjector(
102 // We put each binding in a separate module so the order of the error messages doesn't
103 // depend on line numbers
104 new AbstractModule() {
105 @Override
106 public void configure() {
107 getProvider(Runnable.class);
108 }
109 },
110 new AbstractModule() {
111 @Override
112 public void configure() {
113 bind(Comparator.class);
114 }
115 },
116 new AbstractModule() {
117 @Override
118 public void configure() {
119 requireBinding(Key.get(new TypeLiteral<Callable<String>>() {}));
120 }
121 },
122 new AbstractModule() {
123 @Override
124 public void configure() {
125 bind(Date.class).annotatedWith(Names.named("date"));
126 }
127 });
128 fail("Expected CreationException");
129 } catch (CreationException e) {
130 assertEquals(4, e.getErrorMessages().size());
131 String segment1 = "No implementation for Runnable was bound.";
132 String segment2 = "No implementation for Comparator was bound.";
133 String segment3 = "No implementation for Callable<String> was bound.";
134 String segment4 =
135 String.format(
136 "No implementation for Date annotated with @Named(%s) was bound.",
137 Annotations.memberValueString("value", "date"));
138 String sourceFileName = getDeclaringSourcePart(getClass());
139 assertContains(
140 e.getMessage(),
141 segment1,
142 sourceFileName,
143 segment2,
144 sourceFileName,
145 segment3,
146 sourceFileName,
147 segment4,
148 sourceFileName);
149 }
150 }
151
152 public void testMissingDependency() {
153 try {

Callers

nothing calls this directly

Calls 9

createInjectorMethod · 0.95
memberValueStringMethod · 0.95
assertContainsMethod · 0.80
failMethod · 0.45
sizeMethod · 0.45
getErrorMessagesMethod · 0.45
formatMethod · 0.45
getMessageMethod · 0.45

Tested by

no test coverage detected