use of com.google.inject.CreationException in project guice by google.
the class ProvidesIntoTest method testMapKeyMissingValueMethod.
public void testMapKeyMissingValueMethod() {
Module m = new AbstractModule() {
@Override
protected void configure() {
}
@ProvidesIntoMap
@MissingValueMethod
String provideFoo() {
return "foo";
}
};
try {
Guice.createInjector(MultibindingsScanner.asModule(), m);
fail();
} catch (CreationException ce) {
assertEquals(1, ce.getErrorMessages().size());
assertContains(ce.getMessage(), "No 'value' method in MapKey with unwrapValue=true: " + MissingValueMethod.class.getName());
}
}
use of com.google.inject.CreationException in project guice by google.
the class ProvidesIntoTest method testMoreThanOneMapKeyAnnotation.
public void testMoreThanOneMapKeyAnnotation() {
Module m = new AbstractModule() {
@Override
protected void configure() {
}
@ProvidesIntoMap
@TestEnumKey(TestEnum.A)
@TestEnumKey2(TestEnum.B)
String provideFoo() {
return "foo";
}
};
try {
Guice.createInjector(MultibindingsScanner.asModule(), m);
fail();
} catch (CreationException ce) {
assertEquals(1, ce.getErrorMessages().size());
assertContains(ce.getMessage(), "Found more than one MapKey annotations on " + m.getClass().getName() + ".provideFoo");
}
}
use of com.google.inject.CreationException in project roboguice by roboguice.
the class FactoryModuleBuilderTest method testImplicitForwardingAssistedBindingFailsWithAbstractClass.
public void testImplicitForwardingAssistedBindingFailsWithAbstractClass() {
try {
Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(AbstractCar.class).to(ArtCar.class);
install(new FactoryModuleBuilder().build(ColoredAbstractCarFactory.class));
}
});
fail();
} catch (CreationException ce) {
assertContains(ce.getMessage(), "1) " + AbstractCar.class.getName() + " is abstract, not a concrete class.", "Unable to create AssistedInject factory.", "while locating " + AbstractCar.class.getName(), "at " + ColoredAbstractCarFactory.class.getName() + ".create(");
assertEquals(1, ce.getErrorMessages().size());
}
}
use of com.google.inject.CreationException in project roboguice by roboguice.
the class FactoryModuleBuilderTest method testExplicitForwardingAssistedBindingFailsWithAbstractClass.
public void testExplicitForwardingAssistedBindingFailsWithAbstractClass() {
try {
Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(AbstractCar.class).to(ArtCar.class);
install(new FactoryModuleBuilder().implement(Car.class, AbstractCar.class).build(ColoredCarFactory.class));
}
});
fail();
} catch (CreationException ce) {
assertContains(ce.getMessage(), "1) " + AbstractCar.class.getName() + " is abstract, not a concrete class.", "Unable to create AssistedInject factory.", "while locating " + AbstractCar.class.getName(), "while locating " + Car.class.getName(), "at " + ColoredCarFactory.class.getName() + ".create(");
assertEquals(1, ce.getErrorMessages().size());
}
}
use of com.google.inject.CreationException in project roboguice by roboguice.
the class Jsr330Test method testInjectingFinalFieldsIsForbidden.
public void testInjectingFinalFieldsIsForbidden() {
try {
Guice.createInjector(new AbstractModule() {
protected void configure() {
bind(L.class);
}
});
fail();
} catch (CreationException expected) {
assertContains(expected.getMessage(), "1) Injected field " + L.class.getName() + ".b cannot be final.");
}
}
Aggregations