use of com.google.inject.ConfigurationException in project guice by google.
the class MapBinderTest method testMapBinderMultimapWithAnotation.
public void testMapBinderMultimapWithAnotation() {
AbstractModule ab1 = new AbstractModule() {
@Override
protected void configure() {
MapBinder<String, String> multibinder = MapBinder.newMapBinder(binder(), String.class, String.class, Abc.class);
multibinder.addBinding("a").toInstance("A");
multibinder.addBinding("b").toInstance("B1");
}
};
AbstractModule b2c = new AbstractModule() {
@Override
protected void configure() {
MapBinder<String, String> multibinder = MapBinder.newMapBinder(binder(), String.class, String.class, Abc.class);
multibinder.addBinding("b").toInstance("B2");
multibinder.addBinding("c").toInstance("C");
multibinder.permitDuplicates();
}
};
Injector injector = Guice.createInjector(ab1, b2c);
assertEquals(mapOf("a", setOf("A"), "b", setOf("B1", "B2"), "c", setOf("C")), injector.getInstance(Key.get(mapOfSetOfString, Abc.class)));
try {
injector.getInstance(Key.get(mapOfSetOfString));
fail();
} catch (ConfigurationException expected) {
}
assertMapVisitor(Key.get(mapOfString, Abc.class), stringType, stringType, setOf(ab1, b2c), BOTH, true, 0, instance("a", "A"), instance("b", "B1"), instance("b", "B2"), instance("c", "C"));
}
use of com.google.inject.ConfigurationException in project guice by google.
the class ChildBindingAlreadySetErrorTest method childBindingAlreadySetError.
@Test
public void childBindingAlreadySetError() throws Exception {
Injector injector = Guice.createInjector(new ChildModule());
ConfigurationException exception = assertThrows(ConfigurationException.class, () -> injector.getInstance(Foo.class));
assertGuiceErrorEqualsIgnoreLineNumber(exception.getMessage(), "child_binding_already_set_error.txt");
}
use of com.google.inject.ConfigurationException in project guice by google.
the class ChildBindingAlreadySetErrorTest method childBindingAlreadySetMultipleTimesError.
@Test
public void childBindingAlreadySetMultipleTimesError() throws Exception {
Injector injector = Guice.createInjector(new ChildModule(), new ChildModule2());
ConfigurationException exception = assertThrows(ConfigurationException.class, () -> injector.getInstance(DependsOnFoo.class));
assertGuiceErrorEqualsIgnoreLineNumber(exception.getMessage(), "child_binding_already_set_multiple_times_error.txt");
}
use of com.google.inject.ConfigurationException in project guice by google.
the class ChildBindingAlreadySetErrorTest method childBindingAlreadySetByJustInTimeBinding.
@Test
public void childBindingAlreadySetByJustInTimeBinding() throws Exception {
Injector injector = Guice.createInjector(new ChildModule3(), new ChildModule4());
ConfigurationException exception = assertThrows(ConfigurationException.class, () -> injector.getInstance(DependsOnFoo.class));
assertGuiceErrorEqualsIgnoreLineNumber(exception.getMessage(), "child_binding_already_set_by_just_in_time_binding.txt");
}
use of com.google.inject.ConfigurationException in project guice by google.
the class InjectionPointTest method testTooManyConstructors.
public void testTooManyConstructors() {
ConfigurationException exception = assertThrows(ConfigurationException.class, () -> InjectionPoint.forConstructorOf(TypeLiteral.get(TooManyConstructors.class)));
assertThat(exception).hasMessageThat().contains("has more than one constructor annotated with @Inject.");
}
Aggregations