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.");
}
}
use of com.google.inject.CreationException in project roboguice by roboguice.
the class ToolStageInjectorTest method testToolStageWarnsOfMissingObjectGraph.
public void testToolStageWarnsOfMissingObjectGraph() {
final Bar bar = new Bar();
try {
Guice.createInjector(Stage.TOOL, new AbstractModule() {
@Override
protected void configure() {
requestStaticInjection(Bar.class);
requestInjection(bar);
}
});
fail("expected exception");
} catch (CreationException expected) {
Asserts.assertContains(expected.toString(), "No implementation for java.util.Collection was bound.", "No implementation for java.util.Map was bound.", "No implementation for java.util.List was bound.", "No implementation for java.util.Set was bound.");
}
}
use of com.google.inject.CreationException in project roboguice by roboguice.
the class FactoryModuleBuilderTest method testSingletonScopeOnAssistedClassIsIgnored.
public void testSingletonScopeOnAssistedClassIsIgnored() {
try {
Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
install(new FactoryModuleBuilder().build(SingletonFactory.class));
}
});
fail();
} catch (CreationException ce) {
assertEquals(1, ce.getErrorMessages().size());
assertEquals("Found scope annotation [" + Singleton.class.getName() + "]" + " on implementation class [" + AssistedSingleton.class.getName() + "]" + " of AssistedInject factory [" + SingletonFactory.class.getName() + "]." + "\nThis is not allowed, please remove the scope annotation.", Iterables.getOnlyElement(ce.getErrorMessages()).getMessage());
}
}
use of com.google.inject.CreationException in project roboguice by roboguice.
the class FactoryProviderTest method testAssistedInjectConstructorAndAssistedFactoryParameterMustNotMix.
public void testAssistedInjectConstructorAndAssistedFactoryParameterMustNotMix() {
try {
Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(Double.class).toInstance(5.0d);
bind(AssistedParamsFactory.class).toProvider(FactoryProvider.newFactory(AssistedParamsFactory.class, Mustang.class));
}
});
fail();
} catch (CreationException expected) {
assertContains(expected.getMessage(), "Factory method " + AssistedParamsFactory.class.getName() + ".create() has an @Assisted parameter, which " + "is incompatible with the deprecated @AssistedInject annotation.");
}
}
use of com.google.inject.CreationException in project roboguice by roboguice.
the class ProviderMethodsTest method testVoidProviderMethods.
public void testVoidProviderMethods() {
try {
Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
}
@Provides
void provideFoo() {
}
});
fail();
} catch (CreationException expected) {
assertContains(expected.getMessage(), "1) Provider methods must return a value. Do not return void.", getClass().getName(), ".provideFoo(ProviderMethodsTest.java:");
}
}
Aggregations