use of com.google.inject.PrivateModule in project guice by google.
the class ModuleAnnotatedMethodScannerTest method privateModuleWithinPrivateModule_parentScannerInheritedIfInstalledAfter.
@Test
public void privateModuleWithinPrivateModule_parentScannerInheritedIfInstalledAfter() {
Injector injector = Guice.createInjector(new PrivateModule() {
@Override
protected void configure() {
expose(Key.get(String.class, named("foo-munged")));
install(new PrivateModule() {
@Override
protected void configure() {
}
@Exposed
@TestProvides
@Named("foo")
String foo() {
return "foo";
}
});
}
}, scannerModule(new NamedMunger()));
assertMungedBinding(injector, String.class, "foo", "foo");
}
use of com.google.inject.PrivateModule in project guice by google.
the class ModuleAnnotatedMethodScannerTest method privateModuleWithinPrivateModule.
@Test
public void privateModuleWithinPrivateModule() {
Injector injector = Guice.createInjector(scannerModule(new NamedMunger()), new PrivateModule() {
@Override
protected void configure() {
expose(Key.get(String.class, named("foo-munged")));
install(new PrivateModule() {
@Override
protected void configure() {
}
@Exposed
@TestProvides
@Named("foo")
String foo() {
return "foo";
}
});
}
});
assertMungedBinding(injector, String.class, "foo", "foo");
}
use of com.google.inject.PrivateModule in project guice by google.
the class ModuleAnnotatedMethodScannerTest method privateModuleInheritScanner_usingPrivateModule.
@Test
public void privateModuleInheritScanner_usingPrivateModule() {
Injector injector = Guice.createInjector(scannerModule(new NamedMunger()), new PrivateModule() {
@Override
protected void configure() {
}
@Exposed
@TestProvides
@Named("foo")
String foo() {
return "foo";
}
});
assertMungedBinding(injector, String.class, "foo", "foo");
}
use of com.google.inject.PrivateModule in project guice by google.
the class OverrideModuleTest method testOverrideDeepExpose.
public void testOverrideDeepExpose() {
final AtomicReference<Provider<Character>> charAProvider = new AtomicReference<Provider<Character>>();
Module exposes5 = new PrivateModule() {
@Override
protected void configure() {
install(new PrivateModule() {
@Override
protected void configure() {
bind(Integer.class).toInstance(5);
expose(Integer.class);
charAProvider.set(getProvider(Character.class));
bind(Character.class).toInstance('A');
}
});
expose(Integer.class);
}
};
Injector injector = Guice.createInjector(Modules.override(exposes5).with(EMPTY_MODULE));
assertEquals(5, injector.getInstance(Integer.class).intValue());
assertEquals('A', charAProvider.getAndSet(null).get().charValue());
injector = Guice.createInjector(Modules.override(EMPTY_MODULE).with(exposes5));
assertEquals(5, injector.getInstance(Integer.class).intValue());
assertEquals('A', charAProvider.getAndSet(null).get().charValue());
final AtomicReference<Provider<Character>> charBProvider = new AtomicReference<Provider<Character>>();
Module binds15 = new AbstractModule() {
@Override
protected void configure() {
bind(Integer.class).toInstance(15);
install(new PrivateModule() {
@Override
protected void configure() {
charBProvider.set(getProvider(Character.class));
bind(Character.class).toInstance('B');
}
});
}
};
injector = Guice.createInjector(Modules.override(binds15).with(exposes5));
assertEquals(5, injector.getInstance(Integer.class).intValue());
assertEquals('A', charAProvider.getAndSet(null).get().charValue());
assertEquals('B', charBProvider.getAndSet(null).get().charValue());
injector = Guice.createInjector(Modules.override(exposes5).with(binds15));
assertEquals(15, injector.getInstance(Integer.class).intValue());
assertEquals('A', charAProvider.getAndSet(null).get().charValue());
assertEquals('B', charBProvider.getAndSet(null).get().charValue());
}
Aggregations