Search in sources :

Example 26 with Dependency

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

the class BindingInstallerTest method testInheritDependencies.

public void testInheritDependencies() throws Exception {
    // Tests that when we install an implicit binding (for foo), we install bindings to "inherit"
    // the dependencies (bar and baz) from the appropriate injectors.  In this case, bar must be
    // inherited from the root, but we don't need to do anything with baz, since it is already
    // available.
    expect(positions.getInstallPosition(foo())).andStubReturn(child);
    expect(positions.getInstallPosition(bar())).andStubReturn(root);
    expect(positions.getInstallPosition(baz())).andStubReturn(child);
    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 Bar
    Binding bazBinding = control.createMock("bazBinding", Binding.class);
    expect(graph.getDependenciesOf(baz())).andReturn(TestUtils.dependencyList());
    implicitBindingMap.put(baz(), bazBinding);
    // Implicit binding for Foo
    Binding fooBinding = control.createMock("fooBinding", Binding.class);
    expect(graph.getDependenciesOf(foo())).andReturn(TestUtils.dependencyList(new Dependency(foo(), bar(), SOURCE), new Dependency(foo(), baz(), SOURCE)));
    implicitBindingMap.put(foo(), fooBinding);
    expect(output.getImplicitBindings()).andReturn(implicitBindingMap.entrySet());
    expect(child.getDependencies()).andReturn(TestUtils.dependencyList(new Dependency(Dependency.GINJECTOR, foo(), SOURCE)));
    child.addBinding(baz(), bazBinding);
    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 27 with Dependency

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

the class BindingResolverTest method expectCreateBinding.

private Binding expectCreateBinding(Key<?> key, Dependency... keys) throws Exception {
    Binding binding = control.createMock(Binding.class);
    expect(bindingCreator.create(key)).andReturn(binding);
    Set<Dependency> requiredKeys = new HashSet<Dependency>(keys.length);
    Collections.addAll(requiredKeys, keys);
    expect(binding.getDependencies()).andReturn(requiredKeys).atLeastOnce();
    bindings.add(binding);
    return binding;
}
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) Dependency(com.google.gwt.inject.rebind.binding.Dependency) HashSet(java.util.HashSet)

Example 28 with Dependency

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

the class DependencyExplorerTest method testUsesExposedBinding.

/**
 * Tests that we don't skip an exposed binding from a different injector.
 */
public void testUsesExposedBinding() throws Exception {
    GinjectorBindings parent = control.createMock("parent", GinjectorBindings.class);
    GinjectorBindings otherGinjector = control.createMock("other", GinjectorBindings.class);
    expect(origin.getDependencies()).andStubReturn(TestUtils.dependencyList(new Dependency(Dependency.GINJECTOR, foo(), SOURCE)));
    expect(origin.isBound(foo())).andReturn(false).anyTimes();
    expect(origin.isPinned(foo())).andReturn(false).anyTimes();
    expect(origin.getParent()).andReturn(parent).anyTimes();
    expect(parent.getParent()).andReturn(null);
    expect(parent.isBound(foo())).andReturn(true);
    control.replay();
    DependencyExplorerOutput output = dependencyExplorer.explore(origin);
    assertSame(parent, output.getPreExistingLocations().get(foo()));
    control.verify();
}
Also used : GinjectorBindings(com.google.gwt.inject.rebind.GinjectorBindings) DependencyExplorerOutput(com.google.gwt.inject.rebind.resolution.DependencyExplorer.DependencyExplorerOutput) Dependency(com.google.gwt.inject.rebind.binding.Dependency)

Example 29 with Dependency

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

the class DependencyExplorerTest method testWillBeBoundBoundInParent.

public void testWillBeBoundBoundInParent() throws Exception {
    GinjectorBindings parent = control.createMock("parent", GinjectorBindings.class);
    expect(origin.getDependencies()).andStubReturn(TestUtils.dependencyList(new Dependency(Dependency.GINJECTOR, foo(), SOURCE)));
    expect(origin.isPinned(foo())).andReturn(false).anyTimes();
    expect(origin.isBound(foo())).andReturn(false).anyTimes();
    expect(origin.getParent()).andReturn(parent).anyTimes();
    expect(parent.getParent()).andReturn(null);
    expect(parent.isBound(foo())).andReturn(false);
    expect(parent.isPinned(foo())).andReturn(true);
    control.replay();
    DependencyExplorerOutput output = dependencyExplorer.explore(origin);
    assertSame(parent, output.getPreExistingLocations().get(foo()));
    control.verify();
}
Also used : GinjectorBindings(com.google.gwt.inject.rebind.GinjectorBindings) DependencyExplorerOutput(com.google.gwt.inject.rebind.resolution.DependencyExplorer.DependencyExplorerOutput) Dependency(com.google.gwt.inject.rebind.binding.Dependency)

Example 30 with Dependency

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

the class DependencyExplorerTest method testSkipsExposedBindingFromOrigin.

/**
 * Tests that we don't try to use an exposed binding from the "origin" to satisfy a dependency
 * from the origin.
 */
public void testSkipsExposedBindingFromOrigin() throws Exception {
    GinjectorBindings parent = control.createMock("parent", GinjectorBindings.class);
    expect(origin.getDependencies()).andStubReturn(TestUtils.dependencyList(new Dependency(Dependency.GINJECTOR, foo(), SOURCE)));
    expect(origin.isBound(foo())).andReturn(false).anyTimes();
    expect(origin.isPinned(foo())).andReturn(true).anyTimes();
    expect(origin.getParent()).andReturn(parent).anyTimes();
    expect(bindingCreator.create(foo())).andReturn(binding);
    expect(binding.getDependencies()).andReturn(TestUtils.dependencyList());
    control.replay();
    DependencyExplorerOutput output = dependencyExplorer.explore(origin);
    assertTrue(output.getPreExistingLocations().isEmpty());
    assertTrue(output.getImplicitlyBoundKeys().contains(foo()));
    control.verify();
}
Also used : GinjectorBindings(com.google.gwt.inject.rebind.GinjectorBindings) DependencyExplorerOutput(com.google.gwt.inject.rebind.resolution.DependencyExplorer.DependencyExplorerOutput) Dependency(com.google.gwt.inject.rebind.binding.Dependency)

Aggregations

Dependency (com.google.gwt.inject.rebind.binding.Dependency)50 DependencyExplorerOutput (com.google.gwt.inject.rebind.resolution.DependencyExplorer.DependencyExplorerOutput)10 GinjectorBindings (com.google.gwt.inject.rebind.GinjectorBindings)8 Key (com.google.inject.Key)6 Binding (com.google.gwt.inject.rebind.binding.Binding)5 ParentBinding (com.google.gwt.inject.rebind.binding.ParentBinding)4 Method (java.lang.reflect.Method)4 LinkedHashSet (java.util.LinkedHashSet)4 ExposedChildBinding (com.google.gwt.inject.rebind.binding.ExposedChildBinding)3 HashMap (java.util.HashMap)3 Context (com.google.gwt.inject.rebind.binding.Context)2 BindingCreationException (com.google.gwt.inject.rebind.resolution.ImplicitBindingCreator.BindingCreationException)2 ArrayList (java.util.ArrayList)2 FieldLiteral (com.google.gwt.inject.rebind.reflect.FieldLiteral)1 InjectionPoint (com.google.inject.spi.InjectionPoint)1 Field (java.lang.reflect.Field)1 Member (java.lang.reflect.Member)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1