use of com.google.inject.CreationException in project roboguice by roboguice.
the class FactoryProvider2Test method testAssistedJavaxProviderIsDisallowed.
public void testAssistedJavaxProviderIsDisallowed() {
try {
Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(JavaxProviderBasedColoredCarFactory.class).toProvider(FactoryProvider.newFactory(JavaxProviderBasedColoredCarFactory.class, Subaru.class));
}
});
fail();
} catch (CreationException expected) {
assertEquals(expected.getMessage(), 4, expected.getErrorMessages().size());
assertContains(expected.getMessage(), ") A Provider may not be a type in a factory method of an AssistedInject." + "\n Offending instance is parameter [1] with key" + " [com.google.inject.Provider<" + Color.class.getName() + ">] on method [" + JavaxProviderBasedColoredCarFactory.class.getName() + ".createCar()]");
assertContains(expected.getMessage(), ") A Provider may not be a type in a factory method of an AssistedInject." + "\n Offending instance is parameter [2] with key" + " [com.google.inject.Provider<java.lang.String>] on method [" + JavaxProviderBasedColoredCarFactory.class.getName() + ".createCar()]");
assertContains(expected.getMessage(), ") A Provider may not be a type in a factory method of an AssistedInject." + "\n Offending instance is parameter [1] with key" + " [com.google.inject.Provider<" + Color.class.getName() + ">" + " annotated with @com.google.inject.assistedinject.Assisted(value=color)]" + " on method [" + JavaxProviderBasedColoredCarFactory.class.getName() + ".createMustang()]");
assertContains(expected.getMessage(), ") No implementation for com.google.inject.assistedinject." + "FactoryProvider2Test$JavaxProviderBasedColoredCarFactory was bound.");
}
}
use of com.google.inject.CreationException in project roboguice by roboguice.
the class FactoryProvider2Test method testFactoryFailsWithMissingBinding.
public void testFactoryFailsWithMissingBinding() {
try {
Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(ColoredCarFactory.class).toProvider(FactoryProvider.newFactory(ColoredCarFactory.class, Mustang.class));
}
});
fail();
} catch (CreationException expected) {
assertContains(expected.getMessage(), "Could not find a suitable constructor in java.lang.Double.", "at " + ColoredCarFactory.class.getName() + ".create(FactoryProvider2Test.java");
}
}
use of com.google.inject.CreationException in project roboguice by roboguice.
the class FactoryProvider2Test method testAssistedProviderIsDisallowed.
public void testAssistedProviderIsDisallowed() {
try {
Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(ProviderBasedColoredCarFactory.class).toProvider(FactoryProvider.newFactory(ProviderBasedColoredCarFactory.class, Subaru.class));
}
});
fail();
} catch (CreationException expected) {
assertEquals(expected.getMessage(), 4, expected.getErrorMessages().size());
// Assert each method individually, because JDK7 doesn't guarantee method ordering.
assertContains(expected.getMessage(), ") A Provider may not be a type in a factory method of an AssistedInject." + "\n Offending instance is parameter [1] with key" + " [com.google.inject.Provider<" + Color.class.getName() + ">] on method [" + ProviderBasedColoredCarFactory.class.getName() + ".createCar()]");
assertContains(expected.getMessage(), ") A Provider may not be a type in a factory method of an AssistedInject." + "\n Offending instance is parameter [2] with key" + " [com.google.inject.Provider<java.lang.String>] on method [" + ProviderBasedColoredCarFactory.class.getName() + ".createCar()]");
assertContains(expected.getMessage(), ") A Provider may not be a type in a factory method of an AssistedInject." + "\n Offending instance is parameter [1] with key" + " [com.google.inject.Provider<" + Color.class.getName() + ">" + " annotated with @com.google.inject.assistedinject.Assisted(value=color)]" + " on method [" + ProviderBasedColoredCarFactory.class.getName() + ".createMustang()]");
assertContains(expected.getMessage(), ") No implementation for com.google.inject.assistedinject." + "FactoryProvider2Test$ProviderBasedColoredCarFactory was bound.");
}
}
use of com.google.inject.CreationException in project roboguice by roboguice.
the class OverrideModuleTest method testFailsIfOverridenScopeInstanceHasBeenUsed.
public void testFailsIfOverridenScopeInstanceHasBeenUsed() {
final Scope scope = new Scope() {
public <T> Provider<T> scope(Key<T> key, Provider<T> unscoped) {
return unscoped;
}
@Override
public String toString() {
return "ORIGINAL SCOPE";
}
};
final Module original = new AbstractModule() {
@Override
protected void configure() {
bindScope(TestScopeAnnotation.class, scope);
bind(Date.class).in(scope);
bind(String.class).in(scope);
}
};
Module originalWrapper = new AbstractModule() {
@Override
protected void configure() {
install(original);
}
};
Module replacements = new AbstractModule() {
@Override
protected void configure() {
bindScope(TestScopeAnnotation.class, new SingleUseScope());
}
};
try {
createInjector(Modules.override(originalWrapper).with(replacements));
fail("Exception expected");
} catch (CreationException e) {
assertContains(e.getMessage(), "1) The scope for @TestScopeAnnotation is bound directly and cannot be overridden.", "original binding at " + original.getClass().getName() + ".configure(", asModuleChain(originalWrapper.getClass(), original.getClass()), "bound directly at " + original.getClass().getName() + ".configure(", asModuleChain(originalWrapper.getClass(), original.getClass()), "bound directly at " + original.getClass().getName() + ".configure(", asModuleChain(originalWrapper.getClass(), original.getClass()), "at ", replacements.getClass().getName() + ".configure(", asModuleChain(Modules.OverrideModule.class, replacements.getClass()));
}
}
use of com.google.inject.CreationException in project roboguice by roboguice.
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