use of com.google.inject.CreationException in project roboguice by roboguice.
the class ThrowingProviderTest method testIncorrectPredefinedType_Bind.
public void testIncorrectPredefinedType_Bind() {
try {
Guice.createInjector(new AbstractModule() {
protected void configure() {
ThrowingProviderBinder.create(binder()).bind(StringRemoteProvider.class, Integer.class).to(new StringRemoteProvider() {
public String get() throws RemoteException {
return "A";
}
});
}
});
fail();
} catch (CreationException ce) {
assertEquals(StringRemoteProvider.class.getName() + " expects the value type to be java.lang.String, but it was java.lang.Integer", Iterables.getOnlyElement(ce.getErrorMessages()).getMessage());
}
}
use of com.google.inject.CreationException in project roboguice by roboguice.
the class ThrowingProviderTest method testOneMethodThatIsntGet.
public void testOneMethodThatIsntGet() {
try {
Guice.createInjector(new AbstractModule() {
protected void configure() {
install(ThrowingProviderBinder.forModule(this));
}
@SuppressWarnings("unused")
@CheckedProvides(OneNoneGetMethod.class)
String foo() {
return null;
}
});
fail();
} catch (CreationException ce) {
assertEquals(OneNoneGetMethod.class.getName() + " may not declare any new methods, but declared " + Classes.toString(OneNoneGetMethod.class.getDeclaredMethods()[0]), Iterables.getOnlyElement(ce.getErrorMessages()).getMessage());
}
}
use of com.google.inject.CreationException in project roboguice by roboguice.
the class ThrowingProviderTest method testProviderMethodWithManyExceptions.
public void testProviderMethodWithManyExceptions() {
try {
Guice.createInjector(new AbstractModule() {
protected void configure() {
install(ThrowingProviderBinder.forModule(this));
}
@SuppressWarnings("unused")
@CheckedProvides(RemoteProvider.class)
String foo() throws InterruptedException, RuntimeException, RemoteException, AccessException, TooManyListenersException {
return null;
}
});
fail();
} catch (CreationException ce) {
// The only two that should fail are Interrupted & TooManyListeners.. the rest are OK.
List<Message> errors = ImmutableList.copyOf(ce.getErrorMessages());
assertEquals(InterruptedException.class.getName() + " is not compatible with the exceptions ([" + RemoteException.class + "]) declared in the CheckedProvider interface (" + RemoteProvider.class.getName() + ")", errors.get(0).getMessage());
assertEquals(TooManyListenersException.class.getName() + " is not compatible with the exceptions ([" + RemoteException.class + "]) declared in the CheckedProvider interface (" + RemoteProvider.class.getName() + ")", errors.get(1).getMessage());
assertEquals(2, errors.size());
}
}
use of com.google.inject.CreationException in project roboguice by roboguice.
the class ThrowingProviderTest method testIncorrectPredefinedType_Provides.
public void testIncorrectPredefinedType_Provides() {
try {
Guice.createInjector(new AbstractModule() {
protected void configure() {
install(ThrowingProviderBinder.forModule(this));
}
@SuppressWarnings("unused")
@CheckedProvides(StringRemoteProvider.class)
Integer foo() {
return null;
}
});
fail();
} catch (CreationException ce) {
assertEquals(StringRemoteProvider.class.getName() + " expects the value type to be java.lang.String, but it was java.lang.Integer", Iterables.getOnlyElement(ce.getErrorMessages()).getMessage());
}
}
use of com.google.inject.CreationException in project roboguice by roboguice.
the class ThrowingProviderTest method testManyMethods.
public void testManyMethods() {
try {
Guice.createInjector(new AbstractModule() {
protected void configure() {
install(ThrowingProviderBinder.forModule(this));
}
@SuppressWarnings("unused")
@CheckedProvides(ManyMethods.class)
String foo() {
return null;
}
});
fail();
} catch (CreationException ce) {
assertEquals(ManyMethods.class.getName() + " may not declare any new methods, but declared " + Arrays.asList(ManyMethods.class.getDeclaredMethods()), Iterables.getOnlyElement(ce.getErrorMessages()).getMessage());
}
}
Aggregations