use of com.google.inject.CreationException in project roboguice by roboguice.
the class CheckedProviderTest method testEarlyBindingError.
public void testEarlyBindingError() {
try {
Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
ThrowingProviderBinder.create(binder()).bind(StringRemoteProvider.class, String.class).to(FailingProvider.class);
}
});
fail();
} catch (CreationException ce) {
assertEquals("Could not find a suitable constructor in " + FailingProvider.class.getName() + ". Classes must have either one (and only one) constructor annotated with @Inject" + " or a zero-argument constructor that is not private.", Iterables.getOnlyElement(ce.getErrorMessages()).getMessage());
}
}
use of com.google.inject.CreationException in project roboguice by roboguice.
the class CheckedProviderTest method testCxtorWithWrongException.
public void testCxtorWithWrongException() {
try {
Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
ThrowingProviderBinder.create(binder()).bind(RemoteProvider.class, Foo.class).providing(WrongExceptionFoo.class);
}
});
fail();
} catch (CreationException ce) {
assertEquals(InterruptedException.class.getName() + " is not compatible with the exceptions ([" + RemoteException.class + ", " + BindException.class + "]) declared in the CheckedProvider interface (" + RemoteProvider.class.getName() + ")", Iterables.getOnlyElement(ce.getErrorMessages()).getMessage());
}
}
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 guice by google.
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 guice by google.
the class MapBinderTest method testMapBinderMapForbidsNullKeys.
public void testMapBinderMapForbidsNullKeys() {
try {
Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
MapBinder.newMapBinder(binder(), String.class, String.class).addBinding(null);
}
});
fail();
} catch (CreationException expected) {
}
}
Aggregations