use of com.google.inject.CreationException in project guice by google.
the class OptionalBinderTest method testSourceLinesInException.
public void testSourceLinesInException() {
try {
Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
OptionalBinder.newOptionalBinder(binder(), Integer.class).setDefault();
}
});
fail();
} catch (CreationException expected) {
assertContains(expected.getMessage(), "No implementation for java.lang.Integer", "at " + getClass().getName());
}
}
use of com.google.inject.CreationException in project guice by google.
the class OptionalBinderTest method testDifferentBindingsFail_defaults.
public void testDifferentBindingsFail_defaults() {
Module module = new AbstractModule() {
@Override
protected void configure() {
OptionalBinder.newOptionalBinder(binder(), String.class).setDefault().toInstance("a");
OptionalBinder.newOptionalBinder(binder(), String.class).setDefault().toInstance("b");
}
};
try {
Guice.createInjector(module);
fail();
} catch (CreationException ce) {
assertEquals(ce.getMessage(), 1, ce.getErrorMessages().size());
assertContains(ce.getMessage(), "1) A binding to java.lang.String annotated with @" + RealOptionalBinder.Default.class.getName() + " was already configured at " + module.getClass().getName() + ".configure(", "at " + module.getClass().getName() + ".configure(");
}
}
use of com.google.inject.CreationException in project guice by google.
the class MapBinderTest method testMapBinderMapForbidsDuplicateKeys.
public void testMapBinderMapForbidsDuplicateKeys() {
Module module = new AbstractModule() {
@Override
protected void configure() {
MapBinder<String, String> multibinder = MapBinder.newMapBinder(binder(), String.class, String.class);
multibinder.addBinding("a").toInstance("A");
multibinder.addBinding("a").toInstance("B");
}
};
try {
Guice.createInjector(module);
fail();
} catch (CreationException expected) {
assertContains(expected.getMessage(), "Map injection failed due to duplicated key \"a\"");
}
assertMapVisitor(Key.get(mapOfString), stringType, stringType, setOf(module), MODULE, false, 0, instance("a", "A"), instance("a", "B"));
}
use of com.google.inject.CreationException in project guice by google.
the class MultibinderTest method testSourceLinesInMultibindings.
public void testSourceLinesInMultibindings() {
try {
Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
Multibinder.newSetBinder(binder(), Integer.class).addBinding();
}
});
fail();
} catch (CreationException expected) {
assertContains(expected.getMessage(), true, "No implementation for java.lang.Integer", "at " + getClass().getName());
}
}
use of com.google.inject.CreationException in project guice by google.
the class OptionalBinderTest method testDifferentBindingsFail_actual.
public void testDifferentBindingsFail_actual() {
Module module = new AbstractModule() {
@Override
protected void configure() {
OptionalBinder.newOptionalBinder(binder(), String.class).setBinding().toInstance("a");
OptionalBinder.newOptionalBinder(binder(), String.class).setBinding().toInstance("b");
}
};
try {
Guice.createInjector(module);
fail();
} catch (CreationException ce) {
assertEquals(ce.getMessage(), 1, ce.getErrorMessages().size());
assertContains(ce.getMessage(), "1) A binding to java.lang.String annotated with @" + RealOptionalBinder.Actual.class.getName() + " was already configured at " + module.getClass().getName() + ".configure(", "at " + module.getClass().getName() + ".configure(");
}
}
Aggregations