Search in sources :

Example 1 with Binding

use of com.google.gwt.inject.rebind.binding.Binding in project google-gin by gwtplus.

the class BindingInstallerTest method testInstallImplicitBindings.

public void testInstallImplicitBindings() throws Exception {
    // Tests that implicit bindings that are not already available in the origin are made accessible
    // foo and bar both had implicit bindings created (with no dependencies).  Foo is installed in
    // the child, and bar is installed in root.  We should add a binding to make bar accessible in
    // the child.
    expect(positions.getInstallPosition(foo())).andStubReturn(child);
    expect(positions.getInstallPosition(bar())).andStubReturn(root);
    Map<Key<?>, Binding> implicitBindingMap = new HashMap<Key<?>, Binding>();
    // Parent Binding to make bar available to child
    ParentBinding barBinding = control.createMock("barBinding", ParentBinding.class);
    expect(child.isBound(bar())).andReturn(false);
    expect(bindingFactory.getParentBinding(eq(bar()), eq(root), isA(Context.class))).andReturn(barBinding);
    // Implicit binding for Foo
    Binding fooBinding = control.createMock("fooBinding", Binding.class);
    expect(graph.getDependenciesOf(foo())).andReturn(TestUtils.dependencyList());
    implicitBindingMap.put(foo(), fooBinding);
    expect(output.getImplicitBindings()).andReturn(implicitBindingMap.entrySet());
    expect(child.getDependencies()).andReturn(TestUtils.dependencyList(new Dependency(Dependency.GINJECTOR, foo(), SOURCE), new Dependency(Dependency.GINJECTOR, bar(), SOURCE)));
    child.addBinding(bar(), barBinding);
    child.addBinding(foo(), fooBinding);
    control.replay();
    installer.installBindings(output);
    control.verify();
}
Also used : Binding(com.google.gwt.inject.rebind.binding.Binding) ParentBinding(com.google.gwt.inject.rebind.binding.ParentBinding) Context(com.google.gwt.inject.rebind.binding.Context) ParentBinding(com.google.gwt.inject.rebind.binding.ParentBinding) HashMap(java.util.HashMap) Dependency(com.google.gwt.inject.rebind.binding.Dependency) Key(com.google.inject.Key)

Example 2 with Binding

use of com.google.gwt.inject.rebind.binding.Binding in project google-gin by gwtplus.

the class BindingResolverTest method testDepHiddenInChildBlocksResolvingInRoot_NoErrorIfOptional.

public void testDepHiddenInChildBlocksResolvingInRoot_NoErrorIfOptional() throws Exception {
    GinjectorBindings root = createInjectorNode("root");
    GinjectorBindings child = createInjectorNode("child");
    setChildren(root, child);
    bind(baz(), root);
    bind(bar(), child);
    expect(root.isBoundLocallyInChild(bar())).andReturn(true).anyTimes();
    expect(root.getChildWhichBindsLocally(bar())).andReturn(child);
    Binding fooBinding = expectCreateBinding(foo(), required(foo(), baz()), optional(foo(), bar()));
    expectCreateBinding(bar());
    root.addBinding(foo(), fooBinding);
    replayAndResolve(root, 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) GinjectorBindings(com.google.gwt.inject.rebind.GinjectorBindings)

Example 3 with Binding

use of com.google.gwt.inject.rebind.binding.Binding in project google-gin by gwtplus.

the class BindingResolverTest method testResolveCycleThroughAsyncProvider.

public void testResolveCycleThroughAsyncProvider() throws Exception {
    // Foo -> AsyncProvider<Foo> -> Foo, cycle is OK because of AsyncProvider.
    // AsyncProvider<Foo> is in the "unpositioned pending Foo" set.  Identical to
    // testResolveCycleThroughProvider, but verifies that AsyncProvider is also acceptable.
    StandardTree tree = createExampleTree();
    Binding fooBinding = expectCreateBinding(foo(), required(foo(), asyncProviderFoo()));
    Binding providerFooBinding = expectCreateBinding(asyncProviderFoo(), requiredLazy(asyncProviderFoo(), foo()));
    tree.root.addBinding(foo(), fooBinding);
    tree.root.addBinding(asyncProviderFoo(), providerFooBinding);
    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)

Example 4 with Binding

use of com.google.gwt.inject.rebind.binding.Binding in project google-gin by gwtplus.

the class BindingResolverTest method testResolveCycleDepOfProviderBound.

public void testResolveCycleDepOfProviderBound() throws Exception {
    // Foo -> Provider<Bar> -> Bar -> {Foo, Baz}, Baz is bound at childL
    // This test makes sure that we at least ensure that Bar doesn't move higher than
    // *any* of it's dependencies, even after detecting a cycle.
    StandardTree tree = createExampleTree();
    Binding fooBinding = expectCreateBinding(foo(), required(foo(), providerBar()));
    Binding providerBarBinding = expectCreateBinding(providerBar(), requiredLazy(providerBar(), bar()));
    Binding barBinding = expectCreateBinding(bar(), required(bar(), foo()), required(bar(), baz()));
    bind(baz(), tree.childL);
    tree.childL.addBinding(foo(), fooBinding);
    tree.childL.addBinding(providerBar(), providerBarBinding);
    tree.childL.addBinding(bar(), barBinding);
    expectParentBinding(foo(), tree.childL, 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)

Example 5 with Binding

use of com.google.gwt.inject.rebind.binding.Binding in project google-gin by gwtplus.

the class BindingResolverTest method testResolveBindingWithOptionalThatDoesntBlockPosition.

public void testResolveBindingWithOptionalThatDoesntBlockPosition() throws Exception {
    StandardTree tree = createExampleTree();
    Binding fooBinding = expectCreateBinding(foo(), optional(foo(), bar()));
    expectCreateBinding(bar(), required(bar(), baz()));
    expectCreateBinding(baz());
    // Can't bar() because baz() is already bound in childLL.  Therefore, bar() should not constrain
    // the position of foo(), and we should place it in the root.
    bind(baz(), tree.childLL);
    expect(tree.childL.isBoundLocallyInChild(baz())).andReturn(true);
    expect(tree.childL.getChildWhichBindsLocally(baz())).andReturn(tree.childLL);
    tree.root.addBinding(foo(), fooBinding);
    expectParentBinding(foo(), tree.root, tree.childL);
    replayAndResolve(tree.childL, 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)

Aggregations

Binding (com.google.gwt.inject.rebind.binding.Binding)34 ParentBinding (com.google.gwt.inject.rebind.binding.ParentBinding)28 ExposedChildBinding (com.google.gwt.inject.rebind.binding.ExposedChildBinding)25 GinjectorBindings (com.google.gwt.inject.rebind.GinjectorBindings)10 Key (com.google.inject.Key)6 Dependency (com.google.gwt.inject.rebind.binding.Dependency)5 GinjectorNameGenerator (com.google.gwt.inject.rebind.GinjectorNameGenerator)4 NameGenerator (com.google.gwt.inject.rebind.util.NameGenerator)4 BindingCreationException (com.google.gwt.inject.rebind.resolution.ImplicitBindingCreator.BindingCreationException)3 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 Context (com.google.gwt.inject.rebind.binding.Context)2 HashMap (java.util.HashMap)2 UnableToCompleteException (com.google.gwt.core.ext.UnableToCompleteException)1 GinScope (com.google.gwt.inject.rebind.GinScope)1 GinjectorBinding (com.google.gwt.inject.rebind.binding.GinjectorBinding)1 RemoteServiceProxyBinding (com.google.gwt.inject.rebind.binding.RemoteServiceProxyBinding)1 InjectorMethod (com.google.gwt.inject.rebind.util.InjectorMethod)1 SourceWriteUtil (com.google.gwt.inject.rebind.util.SourceWriteUtil)1 Singleton (com.google.inject.Singleton)1