use of com.google.inject.CreationException in project guice by google.
the class CheckedProviderTest method testNoThrowingInject.
public void testNoThrowingInject() {
try {
Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
ThrowingProviderBinder.create(binder()).bind(RemoteProvider.class, Foo.class).providing(NormalInjectableFoo.class);
}
});
fail();
} catch (CreationException ce) {
assertEquals("Could not find a suitable constructor in " + NormalInjectableFoo.class.getName() + ". Classes must have either one (and only one) constructor annotated with " + "@ThrowingInject.", Iterables.getOnlyElement(ce.getErrorMessages()).getMessage());
}
}
use of com.google.inject.CreationException in project guice by google.
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 guice by google.
the class ThrowingProviderTest 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 guice by google.
the class ThrowingProviderTest method testMoreTypeParameters.
public void testMoreTypeParameters() {
try {
Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
install(ThrowingProviderBinder.forModule(this));
}
@SuppressWarnings("unused")
@CheckedProvides(TooManyTypeParameters.class)
String foo() {
return null;
}
});
fail();
} catch (CreationException ce) {
assertEquals(TooManyTypeParameters.class.getName() + " has more than one generic type parameter: [T, P]", Iterables.getOnlyElement(ce.getErrorMessages()).getMessage());
}
}
use of com.google.inject.CreationException in project guice by google.
the class ThrowingProviderTest method testOneMethodThatIsntGet.
public void testOneMethodThatIsntGet() {
try {
Guice.createInjector(new AbstractModule() {
@Override
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());
}
}
Aggregations