use of com.google.inject.CreationException in project roboguice by roboguice.
the class BoundFieldModuleTest method testRawProviderCannotBeBound.
public void testRawProviderCannotBeBound() {
final Integer testValue = 1024;
Object instance = new Object() {
@Bind
private Provider anIntProvider = new Provider() {
@Override
public Object get() {
return testValue;
}
};
};
BoundFieldModule module = BoundFieldModule.of(instance);
try {
Guice.createInjector(module);
fail();
} catch (CreationException e) {
assertContains(e.getMessage(), "Non parameterized Provider fields must have an " + "explicit binding class via @Bind(to = Foo.class)");
}
}
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.");
}
}
use of com.google.inject.CreationException in project roboguice by roboguice.
the class Jsr330Test method testInjectingMethodsWithTypeParametersIsForbidden.
public void testInjectingMethodsWithTypeParametersIsForbidden() {
try {
Guice.createInjector(new AbstractModule() {
protected void configure() {
bind(N.class);
}
});
fail();
} catch (CreationException expected) {
assertContains(expected.getMessage(), "1) Injected method " + N.class.getName() + ".setB() cannot declare type parameters of its own.");
}
}
Aggregations