use of com.google.inject.CreationException in project roboguice by roboguice.
the class ThrowingProviderTest method testBindingToSubSubInterface_Provides.
public void testBindingToSubSubInterface_Provides() throws RemoteException {
try {
Guice.createInjector(new AbstractModule() {
protected void configure() {
install(ThrowingProviderBinder.forModule(this));
}
@SuppressWarnings("unused")
@CheckedProvides(SubRemoteProvider.class)
String foo() {
return null;
}
});
fail();
} catch (CreationException expected) {
assertEquals(SubRemoteProvider.class.getName() + " must extend CheckedProvider (and only CheckedProvider)", Iterables.getOnlyElement(expected.getErrorMessages()).getMessage());
}
}
use of com.google.inject.CreationException in project roboguice by roboguice.
the class ThrowingProviderTest method testBindingToNonInterfaceType_Provides.
public void testBindingToNonInterfaceType_Provides() throws RemoteException {
try {
Guice.createInjector(new AbstractModule() {
protected void configure() {
install(ThrowingProviderBinder.forModule(this));
}
@SuppressWarnings("unused")
@CheckedProvides(MockRemoteProvider.class)
String foo() {
return null;
}
});
fail();
} catch (CreationException expected) {
assertEquals(MockRemoteProvider.class.getName() + " must be an interface", Iterables.getOnlyElement(expected.getErrorMessages()).getMessage());
}
}
use of com.google.inject.CreationException in project roboguice by roboguice.
the class CheckedProviderTest method testWrongThrowingProviderType.
public void testWrongThrowingProviderType() {
try {
Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
install(ThrowingProviderBinder.forModule(this));
}
@SuppressWarnings("unused")
@CheckedProvides(WrongThrowingProviderType.class)
String foo() {
return null;
}
});
fail();
} catch (CreationException ce) {
assertEquals(WrongThrowingProviderType.class.getName() + " does not properly extend CheckedProvider, the first type parameter of CheckedProvider " + "(java.lang.String) is not a generic type", Iterables.getOnlyElement(ce.getErrorMessages()).getMessage());
}
}
use of com.google.inject.CreationException in project roboguice by roboguice.
the class CheckedProviderTest method testProviderMethodWithSuperclassExceptionFails.
public void testProviderMethodWithSuperclassExceptionFails() {
try {
Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
install(ThrowingProviderBinder.forModule(this));
}
@SuppressWarnings("unused")
@CheckedProvides(RemoteProvider.class)
Foo foo() throws IOException {
return null;
}
});
fail();
} catch (CreationException ce) {
assertEquals(IOException.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 CheckedProviderTest method testBindingToInterfaceWithExtraMethod_Provides.
public void testBindingToInterfaceWithExtraMethod_Provides() throws Exception {
try {
Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
install(ThrowingProviderBinder.forModule(this));
}
@SuppressWarnings("unused")
@CheckedProvides(RemoteProviderWithExtraMethod.class)
Foo foo() {
return null;
}
});
fail();
} catch (CreationException expected) {
assertEquals(RemoteProviderWithExtraMethod.class.getName() + " may not declare any new methods, but declared " + RemoteProviderWithExtraMethod.class.getDeclaredMethods()[0].toGenericString(), Iterables.getOnlyElement(expected.getErrorMessages()).getMessage());
}
}
Aggregations