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