Search in sources :

Example 1 with BindingCreationException

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();
}
Also used : DependencyExplorerOutput(com.google.gwt.inject.rebind.resolution.DependencyExplorer.DependencyExplorerOutput) Dependency(com.google.gwt.inject.rebind.binding.Dependency) BindingCreationException(com.google.gwt.inject.rebind.resolution.ImplicitBindingCreator.BindingCreationException)

Example 2 with BindingCreationException

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.
}
Also used : BindingCreationException(com.google.gwt.inject.rebind.resolution.ImplicitBindingCreator.BindingCreationException)

Example 3 with BindingCreationException

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;
            }
        }
    }
}
Also used : Binding(com.google.gwt.inject.rebind.binding.Binding) ExposedChildBinding(com.google.gwt.inject.rebind.binding.ExposedChildBinding) GinjectorBindings(com.google.gwt.inject.rebind.GinjectorBindings) Dependency(com.google.gwt.inject.rebind.binding.Dependency) BindingCreationException(com.google.gwt.inject.rebind.resolution.ImplicitBindingCreator.BindingCreationException)

Example 4 with BindingCreationException

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()));
}
Also used : ExposedChildBinding(com.google.gwt.inject.rebind.binding.ExposedChildBinding) Binding(com.google.gwt.inject.rebind.binding.Binding) ParentBinding(com.google.gwt.inject.rebind.binding.ParentBinding) BindingCreationException(com.google.gwt.inject.rebind.resolution.ImplicitBindingCreator.BindingCreationException)

Example 5 with BindingCreationException

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()));
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) BindingCreationException(com.google.gwt.inject.rebind.resolution.ImplicitBindingCreator.BindingCreationException)

Aggregations

BindingCreationException (com.google.gwt.inject.rebind.resolution.ImplicitBindingCreator.BindingCreationException)7 Binding (com.google.gwt.inject.rebind.binding.Binding)3 ExposedChildBinding (com.google.gwt.inject.rebind.binding.ExposedChildBinding)3 Dependency (com.google.gwt.inject.rebind.binding.Dependency)2 ParentBinding (com.google.gwt.inject.rebind.binding.ParentBinding)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 GinjectorBindings (com.google.gwt.inject.rebind.GinjectorBindings)1 DependencyExplorerOutput (com.google.gwt.inject.rebind.resolution.DependencyExplorer.DependencyExplorerOutput)1