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();
}
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;
}
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();
}
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();
}
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();
}
Aggregations