use of com.google.inject.CreationException in project roboguice by roboguice.
the class MapBinderTest method testSourceLinesInMapBindings.
public void testSourceLinesInMapBindings() {
try {
Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
MapBinder.newMapBinder(binder(), String.class, Integer.class).addBinding("one");
}
});
fail();
} catch (CreationException expected) {
assertContains(expected.getMessage(), "1) No implementation for java.lang.Integer", "at " + getClass().getName());
}
}
use of com.google.inject.CreationException in project roboguice by roboguice.
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 @" + Actual.class.getName() + " was already configured at " + module.getClass().getName() + ".configure(", "at " + module.getClass().getName() + ".configure(");
}
}
use of com.google.inject.CreationException in project roboguice by roboguice.
the class OptionalBinderTest method testDifferentBindingsFail_both.
public void testDifferentBindingsFail_both() {
Module module = new AbstractModule() {
@Override
protected void configure() {
OptionalBinder.newOptionalBinder(binder(), String.class).setDefault().toInstance("a");
OptionalBinder.newOptionalBinder(binder(), String.class).setDefault().toInstance("b");
OptionalBinder.newOptionalBinder(binder(), String.class).setBinding().toInstance("b");
OptionalBinder.newOptionalBinder(binder(), String.class).setBinding().toInstance("c");
}
};
try {
Guice.createInjector(module);
fail();
} catch (CreationException ce) {
assertEquals(ce.getMessage(), 2, ce.getErrorMessages().size());
assertContains(ce.getMessage(), "1) A binding to java.lang.String annotated with @" + Default.class.getName() + " was already configured at " + module.getClass().getName() + ".configure(", "at " + module.getClass().getName() + ".configure(", "2) A binding to java.lang.String annotated with @" + Actual.class.getName() + " was already configured at " + module.getClass().getName() + ".configure(", "at " + module.getClass().getName() + ".configure(");
}
}
use of com.google.inject.CreationException in project roboguice by roboguice.
the class FactoryProviderTest method testFactoryFailsWithMissingBinding.
public void testFactoryFailsWithMissingBinding() {
try {
Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(ColoredCarFactory.class).toProvider(FactoryProvider.newFactory(ColoredCarFactory.class, Mustang.class));
}
});
fail();
} catch (CreationException expected) {
assertContains(expected.getMessage(), "1) Parameter of type 'double' is not injectable or annotated with @Assisted");
}
}
use of com.google.inject.CreationException in project roboguice by roboguice.
the class ManyConstructorsTest method testTooManyMatchingConstructors.
public void testTooManyMatchingConstructors() {
try {
Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
install(new FactoryModuleBuilder().implement(Foo.class, TooManyMatches.class).build(SimpleFactory2.class));
}
});
fail("should have failed");
} catch (CreationException expected) {
Asserts.assertContains(expected.getMessage(), "1) " + TooManyMatches.class.getName() + " has more than one constructor annotated with @AssistedInject that " + "matches the parameters in method " + SimpleFactory2.class.getName());
}
}
Aggregations