use of com.google.inject.Injector in project guice by google.
the class ModuleAnnotatedMethodScannerTest method testWithSource.
public void testWithSource() throws Exception {
Module module = new AbstractModule() {
@Override
protected void configure() {
binder().withSource("source").install(new AbstractModule() {
@Override
protected void configure() {
}
@TestProvides
@Named("foo")
String foo() {
return "foo";
}
});
}
};
Injector injector = Guice.createInjector(module, NamedMunger.module());
assertMungedBinding(injector, String.class, "foo", "foo");
}
use of com.google.inject.Injector in project guice by google.
the class ModuleAnnotatedMethodScannerTest method testPrivateModule_skipSourcesForPrivateModule.
public void testPrivateModule_skipSourcesForPrivateModule() {
Injector injector = Guice.createInjector(NamedMunger.module(), new AbstractModule() {
@Override
protected void configure() {
binder().skipSources(getClass()).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.Injector in project guice by google.
the class ModuleAnnotatedMethodScannerTest method testScanning.
public void testScanning() throws Exception {
Module module = new AbstractModule() {
@Override
protected void configure() {
}
@TestProvides
@Named("foo")
String foo() {
return "foo";
}
@TestProvides
@Named("foo2")
String foo2() {
return "foo2";
}
};
Injector injector = Guice.createInjector(module, NamedMunger.module());
// assert no bindings named "foo" or "foo2" exist -- they were munged.
assertMungedBinding(injector, String.class, "foo", "foo");
assertMungedBinding(injector, String.class, "foo2", "foo2");
Binding<String> fooBinding = injector.getBinding(Key.get(String.class, named("foo-munged")));
Binding<String> foo2Binding = injector.getBinding(Key.get(String.class, named("foo2-munged")));
// Validate the provider has a sane toString
assertEquals(methodName(TestProvides.class, "foo", module), fooBinding.getProvider().toString());
assertEquals(methodName(TestProvides.class, "foo2", module), foo2Binding.getProvider().toString());
}
use of com.google.inject.Injector in project guice by google.
the class ModuleAnnotatedMethodScannerTest method testPrivateModule_skipSourcesWithinPrivateModule.
public void testPrivateModule_skipSourcesWithinPrivateModule() {
Injector injector = Guice.createInjector(NamedMunger.module(), new PrivateModule() {
@Override
protected void configure() {
binder().skipSources(getClass()).install(new AbstractModule() {
@Override
protected void configure() {
}
@Exposed
@TestProvides
@Named("foo")
String foo() {
return "foo";
}
});
}
});
assertMungedBinding(injector, String.class, "foo", "foo");
}
use of com.google.inject.Injector in project guice by google.
the class ModuleAnnotatedMethodScannerTest method testPrivateModuleInheritScanner_usingPrivateModule.
public void testPrivateModuleInheritScanner_usingPrivateModule() {
Injector injector = Guice.createInjector(NamedMunger.module(), new PrivateModule() {
@Override
protected void configure() {
}
@Exposed
@TestProvides
@Named("foo")
String foo() {
return "foo";
}
});
assertMungedBinding(injector, String.class, "foo", "foo");
}
Aggregations