blob: 0a6f84de58f7422417e717d0a321472fb1455fa0 [file] [log] [blame]
limpbizkit47151c22008-10-15 05:18:48 +00001/**
2 * Copyright (C) 2008 Google Inc.
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
limpbizkitfcbdf992008-11-26 02:37:35 +000017package com.google.inject;
limpbizkit47151c22008-10-15 05:18:48 +000018
limpbizkit86cb3bb2008-10-15 21:25:50 +000019import static com.google.inject.Asserts.assertContains;
sberlin45ca7f62011-02-20 00:05:28 +000020
21import java.util.ArrayList;
22import java.util.Collection;
23import java.util.List;
24
sberlind9c913a2011-06-26 21:02:54 +000025import com.google.common.collect.ImmutableSet;
limpbizkit47151c22008-10-15 05:18:48 +000026import com.google.inject.name.Named;
limpbizkitc3f92842008-12-30 19:43:47 +000027import com.google.inject.name.Names;
limpbizkit47151c22008-10-15 05:18:48 +000028import static com.google.inject.name.Names.named;
limpbizkitc3f92842008-12-30 19:43:47 +000029import com.google.inject.spi.Dependency;
30import com.google.inject.spi.ExposedBinding;
31import com.google.inject.spi.PrivateElements;
sberlincc17f142011-02-27 00:02:03 +000032import com.google.inject.util.Types;
33
limpbizkit47151c22008-10-15 05:18:48 +000034import junit.framework.TestCase;
35
36/**
37 * @author jessewilson@google.com (Jesse Wilson)
38 */
39public class PrivateModuleTest extends TestCase {
40
41 public void testBasicUsage() {
42 Injector injector = Guice.createInjector(new AbstractModule() {
43 protected void configure() {
44 bind(String.class).annotatedWith(named("a")).toInstance("public");
45
46 install(new PrivateModule() {
crazyboblee91193702009-02-05 22:18:55 +000047 public void configure() {
limpbizkit47151c22008-10-15 05:18:48 +000048 bind(String.class).annotatedWith(named("b")).toInstance("i");
49
50 bind(AB.class).annotatedWith(named("one")).to(AB.class);
51 expose(AB.class).annotatedWith(named("one"));
52 }
53 });
54
55 install(new PrivateModule() {
crazyboblee91193702009-02-05 22:18:55 +000056 public void configure() {
limpbizkit47151c22008-10-15 05:18:48 +000057 bind(String.class).annotatedWith(named("b")).toInstance("ii");
58
59 bind(AB.class).annotatedWith(named("two")).to(AB.class);
60 expose(AB.class).annotatedWith(named("two"));
61 }
62 });
63 }
64 });
65
66 AB ab1 = injector.getInstance(Key.get(AB.class, named("one")));
67 assertEquals("public", ab1.a);
68 assertEquals("i", ab1.b);
69
70 AB ab2 = injector.getInstance(Key.get(AB.class, named("two")));
71 assertEquals("public", ab2.a);
72 assertEquals("ii", ab2.b);
73 }
limpbizkitfcbdf992008-11-26 02:37:35 +000074
75 public void testWithoutPrivateModules() {
76 Injector injector = Guice.createInjector(new AbstractModule() {
77 protected void configure() {
78 PrivateBinder bindA = binder().newPrivateBinder();
79 bindA.bind(String.class).annotatedWith(named("a")).toInstance("i");
80 bindA.expose(String.class).annotatedWith(named("a"));
81 bindA.bind(String.class).annotatedWith(named("c")).toInstance("private to A");
82
83 PrivateBinder bindB = binder().newPrivateBinder();
84 bindB.bind(String.class).annotatedWith(named("b")).toInstance("ii");
85 bindB.expose(String.class).annotatedWith(named("b"));
86 bindB.bind(String.class).annotatedWith(named("c")).toInstance("private to B");
87 }
88 });
89
90 assertEquals("i", injector.getInstance(Key.get(String.class, named("a"))));
91 assertEquals("ii", injector.getInstance(Key.get(String.class, named("b"))));
92 }
limpbizkit47151c22008-10-15 05:18:48 +000093
limpbizkitb1f42f52008-11-26 07:44:53 +000094 public void testMisplacedExposedAnnotation() {
95 try {
96 Guice.createInjector(new AbstractModule() {
97 protected void configure() {}
98
99 @Provides @Exposed
100 String provideString() {
101 return "i";
102 }
103 });
104 fail();
105 } catch (CreationException expected) {
106 assertContains(expected.getMessage(), "Cannot expose java.lang.String on a standard binder. ",
107 "Exposed bindings are only applicable to private binders.",
108 " at " + PrivateModuleTest.class.getName(), "provideString(PrivateModuleTest.java:");
109 }
110 }
111
112 public void testMisplacedExposeStatement() {
113 try {
114 Guice.createInjector(new AbstractModule() {
115 protected void configure() {
116 ((PrivateBinder) binder()).expose(String.class).annotatedWith(named("a"));
117 }
118 });
119 fail();
120 } catch (CreationException expected) {
121 assertContains(expected.getMessage(), "Cannot expose java.lang.String on a standard binder. ",
122 "Exposed bindings are only applicable to private binders.",
123 " at " + PrivateModuleTest.class.getName(), "configure(PrivateModuleTest.java:");
124 }
125 }
126
limpbizkit86cb3bb2008-10-15 21:25:50 +0000127 public void testPrivateModulesAndProvidesMethods() {
128 Injector injector = Guice.createInjector(new AbstractModule() {
129 protected void configure() {
130 install(new PrivateModule() {
crazyboblee91193702009-02-05 22:18:55 +0000131 public void configure() {
limpbizkit86cb3bb2008-10-15 21:25:50 +0000132 expose(String.class).annotatedWith(named("a"));
133 }
134
135 @Provides @Named("a") String providePublicA() {
136 return "i";
137 }
138
139 @Provides @Named("b") String providePrivateB() {
140 return "private";
141 }
142 });
143
144 install(new PrivateModule() {
crazyboblee91193702009-02-05 22:18:55 +0000145 public void configure() {}
limpbizkit86cb3bb2008-10-15 21:25:50 +0000146
limpbizkitfcbdf992008-11-26 02:37:35 +0000147 @Provides @Named("c") String providePrivateC() {
limpbizkit86cb3bb2008-10-15 21:25:50 +0000148 return "private";
149 }
150
limpbizkitfcbdf992008-11-26 02:37:35 +0000151 @Provides @Exposed @Named("d") String providePublicD() {
limpbizkit86cb3bb2008-10-15 21:25:50 +0000152 return "ii";
153 }
154 });
155 }
156 });
157
158 assertEquals("i", injector.getInstance(Key.get(String.class, named("a"))));
limpbizkit0551b642008-11-26 22:25:05 +0000159
160 try {
limpbizkit8dfd5cc2008-11-29 22:21:52 +0000161 injector.getInstance(Key.get(String.class, named("b")));
limpbizkit0551b642008-11-26 22:25:05 +0000162 fail();
163 } catch(ConfigurationException expected) {
164 }
165
166 try {
limpbizkit8dfd5cc2008-11-29 22:21:52 +0000167 injector.getInstance(Key.get(String.class, named("c")));
limpbizkit0551b642008-11-26 22:25:05 +0000168 fail();
169 } catch(ConfigurationException expected) {
170 }
171
limpbizkitfcbdf992008-11-26 02:37:35 +0000172 assertEquals("ii", injector.getInstance(Key.get(String.class, named("d"))));
limpbizkit86cb3bb2008-10-15 21:25:50 +0000173 }
174
175 public void testCannotBindAKeyExportedByASibling() {
176 try {
177 Guice.createInjector(new AbstractModule() {
178 protected void configure() {
179 install(new PrivateModule() {
crazyboblee91193702009-02-05 22:18:55 +0000180 public void configure() {
limpbizkit86cb3bb2008-10-15 21:25:50 +0000181 bind(String.class).toInstance("public");
182 expose(String.class);
183 }
184 });
185
186 install(new PrivateModule() {
crazyboblee91193702009-02-05 22:18:55 +0000187 public void configure() {
limpbizkit86cb3bb2008-10-15 21:25:50 +0000188 bind(String.class).toInstance("private");
189 }
190 });
191 }
192 });
limpbizkitfcbdf992008-11-26 02:37:35 +0000193 fail();
limpbizkit86cb3bb2008-10-15 21:25:50 +0000194 } catch (CreationException expected) {
limpbizkitfcbdf992008-11-26 02:37:35 +0000195 assertContains(expected.getMessage(),
196 "A binding to java.lang.String was already configured at ",
crazyboblee91193702009-02-05 22:18:55 +0000197 getClass().getName(), ".configure(PrivateModuleTest.java:",
198 " at " + getClass().getName(), ".configure(PrivateModuleTest.java:");
limpbizkit86cb3bb2008-10-15 21:25:50 +0000199 }
200 }
201
202 public void testExposeButNoBind() {
203 try {
204 Guice.createInjector(new AbstractModule() {
205 protected void configure() {
206 bind(String.class).annotatedWith(named("a")).toInstance("a");
207 bind(String.class).annotatedWith(named("b")).toInstance("b");
208
209 install(new PrivateModule() {
crazyboblee91193702009-02-05 22:18:55 +0000210 public void configure() {
limpbizkit86cb3bb2008-10-15 21:25:50 +0000211 expose(AB.class);
212 }
213 });
214 }
215 });
216 fail("AB was exposed but not bound");
217 } catch (CreationException expected) {
limpbizkitfcbdf992008-11-26 02:37:35 +0000218 assertContains(expected.getMessage(),
219 "Could not expose() " + AB.class.getName() + ", it must be explicitly bound",
crazyboblee91193702009-02-05 22:18:55 +0000220 ".configure(PrivateModuleTest.java:");
limpbizkit86cb3bb2008-10-15 21:25:50 +0000221 }
222 }
223
limpbizkit72d11dd2008-11-02 07:59:13 +0000224 /**
225 * Ensure that when we've got errors in different private modules, Guice presents all errors
226 * in a unified message.
227 */
228 public void testMessagesFromPrivateModulesAreNicelyIntegrated() {
229 try {
230 Guice.createInjector(
231 new PrivateModule() {
crazyboblee91193702009-02-05 22:18:55 +0000232 public void configure() {
limpbizkit72d11dd2008-11-02 07:59:13 +0000233 bind(C.class);
234 }
235 },
236 new PrivateModule() {
crazyboblee91193702009-02-05 22:18:55 +0000237 public void configure() {
limpbizkit72d11dd2008-11-02 07:59:13 +0000238 bind(AB.class);
239 }
240 }
241 );
242 fail();
243 } catch (CreationException expected) {
244 assertContains(expected.getMessage(),
245 "1) No implementation for " + C.class.getName() + " was bound.",
crazyboblee91193702009-02-05 22:18:55 +0000246 "at " + getClass().getName(), ".configure(PrivateModuleTest.java:",
limpbizkit72d11dd2008-11-02 07:59:13 +0000247 "2) No implementation for " + String.class.getName(), "Named(value=a) was bound.",
248 "for field at " + AB.class.getName() + ".a(PrivateModuleTest.java:",
249 "3) No implementation for " + String.class.getName(), "Named(value=b) was bound.",
250 "for field at " + AB.class.getName() + ".b(PrivateModuleTest.java:",
251 "3 errors");
252 }
253 }
254
limpbizkit86cb3bb2008-10-15 21:25:50 +0000255 public void testNestedPrivateInjectors() {
256 Injector injector = Guice.createInjector(new PrivateModule() {
crazyboblee91193702009-02-05 22:18:55 +0000257 public void configure() {
limpbizkit86cb3bb2008-10-15 21:25:50 +0000258 expose(String.class);
259
260 install(new PrivateModule() {
crazyboblee91193702009-02-05 22:18:55 +0000261 public void configure() {
limpbizkit86cb3bb2008-10-15 21:25:50 +0000262 bind(String.class).toInstance("nested");
263 expose(String.class);
264 }
265 });
266 }
267 });
268
269 assertEquals("nested", injector.getInstance(String.class));
270 }
271
272 public void testInstallingRegularModulesFromPrivateModules() {
273 Injector injector = Guice.createInjector(new PrivateModule() {
crazyboblee91193702009-02-05 22:18:55 +0000274 public void configure() {
limpbizkit86cb3bb2008-10-15 21:25:50 +0000275 expose(String.class);
276
277 install(new AbstractModule() {
278 protected void configure() {
279 bind(String.class).toInstance("nested");
280 }
281 });
282 }
283 });
284
285 assertEquals("nested", injector.getInstance(String.class));
286 }
287
limpbizkita26a41e2008-10-17 17:49:49 +0000288 public void testNestedPrivateModulesWithSomeKeysUnexposed() {
289 Injector injector = Guice.createInjector(new PrivateModule() {
crazyboblee91193702009-02-05 22:18:55 +0000290 public void configure() {
limpbizkita26a41e2008-10-17 17:49:49 +0000291 bind(String.class).annotatedWith(named("bound outer, exposed outer")).toInstance("boeo");
292 expose(String.class).annotatedWith(named("bound outer, exposed outer"));
293 bind(String.class).annotatedWith(named("bound outer, exposed none")).toInstance("boen");
294 expose(String.class).annotatedWith(named("bound inner, exposed both"));
295
296 install(new PrivateModule() {
crazyboblee91193702009-02-05 22:18:55 +0000297 public void configure() {
limpbizkita26a41e2008-10-17 17:49:49 +0000298 bind(String.class).annotatedWith(named("bound inner, exposed both")).toInstance("bieb");
299 expose(String.class).annotatedWith(named("bound inner, exposed both"));
300 bind(String.class).annotatedWith(named("bound inner, exposed none")).toInstance("bien");
301 }
302 });
303 }
304 });
305
limpbizkitfcbdf992008-11-26 02:37:35 +0000306 assertEquals("boeo",
307 injector.getInstance(Key.get(String.class, named("bound outer, exposed outer"))));
308 assertEquals("bieb",
309 injector.getInstance(Key.get(String.class, named("bound inner, exposed both"))));
limpbizkita26a41e2008-10-17 17:49:49 +0000310
311 try {
312 injector.getInstance(Key.get(String.class, named("bound outer, exposed none")));
313 fail();
limpbizkitfcbdf992008-11-26 02:37:35 +0000314 } catch (ConfigurationException expected) {
limpbizkita26a41e2008-10-17 17:49:49 +0000315 }
316
317 try {
318 injector.getInstance(Key.get(String.class, named("bound inner, exposed none")));
319 fail();
limpbizkitfcbdf992008-11-26 02:37:35 +0000320 } catch (ConfigurationException expected) {
limpbizkita26a41e2008-10-17 17:49:49 +0000321 }
322 }
323
limpbizkite2db8592008-10-15 23:49:00 +0000324 public void testDependenciesBetweenPrivateAndPublic() {
325 Injector injector = Guice.createInjector(
326 new PrivateModule() {
crazyboblee91193702009-02-05 22:18:55 +0000327 protected void configure() {}
limpbizkite2db8592008-10-15 23:49:00 +0000328
329 @Provides @Exposed @Named("a") String provideA() {
330 return "A";
331 }
332
limpbizkit2f51f2c2008-10-16 00:21:29 +0000333 @Provides @Exposed @Named("abc") String provideAbc(@Named("ab") String ab) {
limpbizkite2db8592008-10-15 23:49:00 +0000334 return ab + "C";
335 }
336 },
337 new AbstractModule() {
338 protected void configure() {}
339
limpbizkit2f51f2c2008-10-16 00:21:29 +0000340 @Provides @Named("ab") String provideAb(@Named("a") String a) {
limpbizkite2db8592008-10-15 23:49:00 +0000341 return a + "B";
342 }
343
limpbizkit2f51f2c2008-10-16 00:21:29 +0000344 @Provides @Named("abcd") String provideAbcd(@Named("abc") String abc) {
limpbizkite2db8592008-10-15 23:49:00 +0000345 return abc + "D";
346 }
347 }
348 );
349
350 assertEquals("ABCD", injector.getInstance(Key.get(String.class, named("abcd"))));
351 }
352
353 public void testDependenciesBetweenPrivateAndPublicWithPublicEagerSingleton() {
354 Injector injector = Guice.createInjector(
355 new PrivateModule() {
crazyboblee91193702009-02-05 22:18:55 +0000356 protected void configure() {}
limpbizkite2db8592008-10-15 23:49:00 +0000357
358 @Provides @Exposed @Named("a") String provideA() {
359 return "A";
360 }
361
limpbizkit2f51f2c2008-10-16 00:21:29 +0000362 @Provides @Exposed @Named("abc") String provideAbc(@Named("ab") String ab) {
limpbizkite2db8592008-10-15 23:49:00 +0000363 return ab + "C";
364 }
365 },
366 new AbstractModule() {
367 protected void configure() {
368 bind(String.class).annotatedWith(named("abcde")).toProvider(new Provider<String>() {
369 @Inject @Named("abcd") String abcd;
370
371 public String get() {
372 return abcd + "E";
373 }
374 }).asEagerSingleton();
375 }
376
limpbizkit2f51f2c2008-10-16 00:21:29 +0000377 @Provides @Named("ab") String provideAb(@Named("a") String a) {
limpbizkite2db8592008-10-15 23:49:00 +0000378 return a + "B";
379 }
380
limpbizkit2f51f2c2008-10-16 00:21:29 +0000381 @Provides @Named("abcd") String provideAbcd(@Named("abc") String abc) {
limpbizkite2db8592008-10-15 23:49:00 +0000382 return abc + "D";
383 }
384 }
385 );
386
387 assertEquals("ABCDE", injector.getInstance(Key.get(String.class, named("abcde"))));
388 }
389
390 public void testDependenciesBetweenPrivateAndPublicWithPrivateEagerSingleton() {
391 Injector injector = Guice.createInjector(
392 new AbstractModule() {
393 protected void configure() {}
394
limpbizkit2f51f2c2008-10-16 00:21:29 +0000395 @Provides @Named("ab") String provideAb(@Named("a") String a) {
limpbizkite2db8592008-10-15 23:49:00 +0000396 return a + "B";
397 }
398
limpbizkit2f51f2c2008-10-16 00:21:29 +0000399 @Provides @Named("abcd") String provideAbcd(@Named("abc") String abc) {
limpbizkite2db8592008-10-15 23:49:00 +0000400 return abc + "D";
401 }
402 },
403 new PrivateModule() {
crazyboblee91193702009-02-05 22:18:55 +0000404 protected void configure() {
limpbizkite2db8592008-10-15 23:49:00 +0000405 bind(String.class).annotatedWith(named("abcde")).toProvider(new Provider<String>() {
406 @Inject @Named("abcd") String abcd;
407
408 public String get() {
409 return abcd + "E";
410 }
411 }).asEagerSingleton();
412 expose(String.class).annotatedWith(named("abcde"));
413 }
414
415 @Provides @Exposed @Named("a") String provideA() {
416 return "A";
417 }
418
limpbizkit2f51f2c2008-10-16 00:21:29 +0000419 @Provides @Exposed @Named("abc") String provideAbc(@Named("ab") String ab) {
limpbizkite2db8592008-10-15 23:49:00 +0000420 return ab + "C";
421 }
422 }
423 );
424
425 assertEquals("ABCDE", injector.getInstance(Key.get(String.class, named("abcde"))));
426 }
427
limpbizkit47151c22008-10-15 05:18:48 +0000428 static class AB {
429 @Inject @Named("a") String a;
430 @Inject @Named("b") String b;
431 }
limpbizkite2db8592008-10-15 23:49:00 +0000432
433 interface C {}
limpbizkitc3f92842008-12-30 19:43:47 +0000434
435 public void testSpiAccess() {
436 Injector injector = Guice.createInjector(new PrivateModule() {
crazyboblee91193702009-02-05 22:18:55 +0000437 public void configure() {
limpbizkitc3f92842008-12-30 19:43:47 +0000438 bind(String.class).annotatedWith(named("a")).toInstance("private");
439 bind(String.class).annotatedWith(named("b")).toInstance("exposed");
440 expose(String.class).annotatedWith(named("b"));
441 }
442 });
443
444 ExposedBinding<?> binding
445 = (ExposedBinding<?>) injector.getBinding(Key.get(String.class, Names.named("b")));
446 assertEquals(ImmutableSet.<Dependency<?>>of(Dependency.get(Key.get(Injector.class))),
447 binding.getDependencies());
448 PrivateElements privateElements = binding.getPrivateElements();
449 assertEquals(ImmutableSet.<Key<?>>of(Key.get(String.class, named("b"))),
450 privateElements.getExposedKeys());
limpbizkitaa07ab02009-05-15 07:10:43 +0000451 assertContains(privateElements.getExposedSource(Key.get(String.class, named("b"))).toString(),
452 PrivateModuleTest.class.getName(), ".configure(PrivateModuleTest.java:");
limpbizkitc3f92842008-12-30 19:43:47 +0000453 Injector privateInjector = privateElements.getInjector();
454 assertEquals("private", privateInjector.getInstance(Key.get(String.class, Names.named("a"))));
455 }
sberlin45ca7f62011-02-20 00:05:28 +0000456
457 public void testParentBindsSomethingInPrivate() {
458 try {
459 Guice.createInjector(new FailingModule());
460 fail();
461 } catch(CreationException expected) {
462 assertEquals(1, expected.getErrorMessages().size());
463 assertContains(expected.toString(),
sberlincc17f142011-02-27 00:02:03 +0000464 "Unable to create binding for java.util.List.",
465 "It was already configured on one or more child injectors or private modules",
466 "bound at " + FailingPrivateModule.class.getName() + ".configure(",
467 "bound at " + SecondFailingPrivateModule.class.getName() + ".configure(",
468 "If it was in a PrivateModule, did you forget to expose the binding?",
sberlin45ca7f62011-02-20 00:05:28 +0000469 "at " + FailingModule.class.getName() + ".configure(");
470 }
471 }
472
sberlincc17f142011-02-27 00:02:03 +0000473 public void testParentBindingToPrivateLinkedJitBinding() {
474 Injector injector = Guice.createInjector(new ManyPrivateModules());
475 try {
476 injector.getBinding(Key.get(Types.providerOf(List.class)));
477 fail();
478 } catch(ConfigurationException expected) {
479 assertEquals(1, expected.getErrorMessages().size());
480 assertContains(expected.toString(),
481 "Unable to create binding for com.google.inject.Provider<java.util.List>.",
482 "It was already configured on one or more child injectors or private modules",
483 "bound at " + FailingPrivateModule.class.getName() + ".configure(",
484 "bound at " + SecondFailingPrivateModule.class.getName() + ".configure(",
485 "If it was in a PrivateModule, did you forget to expose the binding?",
486 "while locating com.google.inject.Provider<java.util.List>");
487 }
488 }
489
490 public void testParentBindingToPrivateJitBinding() {
491 Injector injector = Guice.createInjector(new ManyPrivateModules());
492 try {
493 injector.getBinding(PrivateFoo.class);
494 fail();
495 } catch(ConfigurationException expected) {
496 assertEquals(1, expected.getErrorMessages().size());
497 assertContains(expected.toString(),
498 "Unable to create binding for " + PrivateFoo.class.getName(),
499 "It was already configured on one or more child injectors or private modules",
500 "(bound by a just-in-time binding)",
501 "If it was in a PrivateModule, did you forget to expose the binding?",
502 "while locating " + PrivateFoo.class.getName());
503 }
504 }
505
sberlin45ca7f62011-02-20 00:05:28 +0000506 private static class FailingModule extends AbstractModule {
507 @Override
508 protected void configure() {
509 bind(Collection.class).to(List.class);
sberlincc17f142011-02-27 00:02:03 +0000510 install(new ManyPrivateModules());
sberlin45ca7f62011-02-20 00:05:28 +0000511 }
512 }
sberlincc17f142011-02-27 00:02:03 +0000513
514 private static class ManyPrivateModules extends AbstractModule {
515 @Override
516 protected void configure() {
517 // make sure duplicate sources are collapsed
518 install(new FailingPrivateModule());
519 install(new FailingPrivateModule());
520 // but additional sources are listed
521 install(new SecondFailingPrivateModule());
522 }
523 }
524
sberlin45ca7f62011-02-20 00:05:28 +0000525 private static class FailingPrivateModule extends PrivateModule {
526 @Override
527 protected void configure() {
528 bind(List.class).toInstance(new ArrayList());
sberlincc17f142011-02-27 00:02:03 +0000529
530 // Add the Provider<List> binding, created just-in-time,
531 // to make sure our linked JIT bindings have the correct source.
532 getProvider(Key.get(Types.providerOf(List.class)));
533
534 // Request a JIT binding for PrivateFoo, which can only
535 // be created in the private module because it depends
536 // on List.
537 getProvider(PrivateFoo.class);
sberlin45ca7f62011-02-20 00:05:28 +0000538 }
539 }
sberlincc17f142011-02-27 00:02:03 +0000540
541 /** A second class, so we can see another name in the source list. */
542 private static class SecondFailingPrivateModule extends PrivateModule {
543 @Override
544 protected void configure() {
545 bind(List.class).toInstance(new ArrayList());
546
547 // Add the Provider<List> binding, created just-in-time,
548 // to make sure our linked JIT bindings have the correct source.
549 getProvider(Key.get(Types.providerOf(List.class)));
550
551 // Request a JIT binding for PrivateFoo, which can only
552 // be created in the private module because it depends
553 // on List.
554 getProvider(PrivateFoo.class);
555 }
556 }
557
558 private static class PrivateFoo {
559 @Inject List list;
560 }
limpbizkit47151c22008-10-15 05:18:48 +0000561}