use of com.google.inject.CreationException in project guice by google.
the class ThrowingProviderTest method testIncorrectPredefinedType_Provides.
public void testIncorrectPredefinedType_Provides() {
try {
Guice.createInjector(new AbstractModule() {
@Override
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 guice by google.
the class ThrowingProviderTest method testProviderMethodWithSuperclassFails.
public void testProviderMethodWithSuperclassFails() {
try {
Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
install(ThrowingProviderBinder.forModule(this));
}
@SuppressWarnings("unused")
@CheckedProvides(RemoteProvider.class)
String foo() throws IOException {
return null;
}
});
fail();
} catch (CreationException ce) {
assertEquals(IOException.class.getName() + " is not compatible with the exceptions ([" + RemoteException.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 testIncorrectPredefinedType_Bind.
public void testIncorrectPredefinedType_Bind() {
try {
Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
ThrowingProviderBinder.create(binder()).bind(StringRemoteProvider.class, Integer.class).to(new StringRemoteProvider() {
@Override
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 BinderTest method testDanglingConstantBinding.
public void testDanglingConstantBinding() {
try {
Guice.createInjector(new AbstractModule() {
@Override
public void configure() {
bindConstant();
}
});
fail();
} catch (CreationException expected) {
assertContains(expected.getMessage(), "1) Missing constant value. Please call to(...).", "at " + getClass().getName());
}
}
use of com.google.inject.CreationException in project roboguice by roboguice.
the class BinderTest method testBindingNullConstant.
public void testBindingNullConstant() {
try {
Guice.createInjector(new AbstractModule() {
@Override
public void configure() {
String none = null;
bindConstant().annotatedWith(Names.named("nullOne")).to(none);
bind(String.class).annotatedWith(Names.named("nullTwo")).toInstance(none);
}
});
fail();
} catch (CreationException expected) {
assertContains(expected.getMessage(), "1) Binding to null instances is not allowed. Use toProvider(Providers.of(null))", "2) Binding to null instances is not allowed. Use toProvider(Providers.of(null))");
}
}
Aggregations