use of com.google.gwt.inject.rebind.resolution.ImplicitBindingCreator.BindingCreationException in project google-gin by gwtplus.
the class DependencyExplorerTest method testImplicitBindingFailed.
public void testImplicitBindingFailed() throws Exception {
expect(origin.getDependencies()).andStubReturn(TestUtils.dependencyList(new Dependency(Dependency.GINJECTOR, foo(), SOURCE)));
expect(origin.getParent()).andStubReturn(null);
expect(origin.isBound(foo())).andReturn(false).anyTimes();
expect(origin.isPinned(foo())).andReturn(false).anyTimes();
expect(bindingCreator.create(foo())).andThrow(new BindingCreationException("failed"));
control.replay();
DependencyExplorerOutput output = dependencyExplorer.explore(origin);
assertEquals(1, output.getBindingErrors().size());
assertEquals(foo(), output.getBindingErrors().iterator().next().getKey());
assertEquals("failed", output.getBindingErrors().iterator().next().getValue());
control.verify();
}
use of com.google.gwt.inject.rebind.resolution.ImplicitBindingCreator.BindingCreationException in project google-gin by gwtplus.
the class BindingResolverTest method testResolveOptionalKey_Fails.
public void testResolveOptionalKey_Fails() throws Exception {
StandardTree tree = createExampleTree();
expect(bindingCreator.create(foo())).andThrow(new BindingCreationException("Unable to create"));
replayAndResolve(tree.childLL, optional(Dependency.GINJECTOR, foo()));
// No error because foo() is optional.
}
use of com.google.gwt.inject.rebind.resolution.ImplicitBindingCreator.BindingCreationException in project google-gin by gwtplus.
the class DependencyExplorer method visit.
private void visit(Key<?> key, DependencyGraph.Builder builder, DependencyExplorerOutput output, GinjectorBindings origin) {
if (visited.add(key)) {
GinjectorBindings accessibleSource = locateHighestAccessibleSource(key, origin);
if (accessibleSource != null) {
PrettyPrinter.log(logger, TreeLogger.DEBUG, "Using binding of %s in %s.", key, accessibleSource);
output.preExistingBindings.put(key, accessibleSource);
} else {
try {
Binding binding = bindingCreator.create(key);
PrettyPrinter.log(logger, TreeLogger.DEBUG, "Implicitly bound %s in %s using %s.", key, origin, binding);
for (Dependency edge : binding.getDependencies()) {
PrettyPrinter.log(logger, TreeLogger.DEBUG, "Following %s", edge);
builder.addEdge(edge);
visit(edge.getTarget(), builder, output, origin);
}
// Do this *after* visiting all dependencies so that that the ordering is post-order
output.implicitBindings.put(key, binding);
} catch (BindingCreationException e) {
PrettyPrinter.log(logger, TreeLogger.DEBUG, "Implicit binding failed for %s: %s", key, e.getMessage());
output.bindingErrors.put(key, e.getMessage());
} catch (RuntimeException e) {
logger.log(Type.ERROR, "Exception while visiting " + key);
throw e;
}
}
}
}
use of com.google.gwt.inject.rebind.resolution.ImplicitBindingCreator.BindingCreationException in project google-gin by gwtplus.
the class BindingResolverTest method testResolveBindingWithOptionalDependencyThatFails.
// Tries to create Foo, which has an optional dependency on Bar, which requires Baz.
// Baz can't be created, so it should create Foo, without the Bar.
public void testResolveBindingWithOptionalDependencyThatFails() throws Exception {
StandardTree tree = createExampleTree();
Binding fooBinding = expectCreateBinding(foo(), optional(foo(), bar()));
expectCreateBinding(bar(), required(bar(), baz()));
expect(bindingCreator.create(baz())).andThrow(new BindingCreationException("Unable to create"));
tree.root.addBinding(foo(), fooBinding);
expectParentBinding(foo(), tree.root, tree.childLL);
replayAndResolve(tree.childLL, required(Dependency.GINJECTOR, foo()));
}
use of com.google.gwt.inject.rebind.resolution.ImplicitBindingCreator.BindingCreationException in project google-gin by gwtplus.
the class BindingResolverTest method testFailToCreateImplicitBinding.
public void testFailToCreateImplicitBinding() throws Exception {
StandardTree tree = createExampleTree();
expect(bindingCreator.create(foo())).andThrow(new BindingCreationException("Unable to create"));
errorManager.logError(isA(String.class), eq(foo()), isA(String.class), isA(List.class));
replayAndResolve(tree.childLL, required(Dependency.GINJECTOR, foo()));
}
Aggregations