use of com.google.gwt.inject.rebind.GinjectorBindings 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.GinjectorBindings 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.GinjectorBindings 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();
}
use of com.google.gwt.inject.rebind.GinjectorBindings in project google-gin by gwtplus.
the class DependencyExplorerTest method testAlreadyBoundInParent.
public void testAlreadyBoundInParent() 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(true);
control.replay();
DependencyExplorerOutput output = dependencyExplorer.explore(origin);
assertSame(parent, output.getPreExistingLocations().get(foo()));
control.verify();
}
use of com.google.gwt.inject.rebind.GinjectorBindings in project google-gin by gwtplus.
the class BindingPositioner method computeInitialPosition.
/**
* Returns the highest injector that we could possibly position the key at without causing a
* double binding.
*/
private GinjectorBindings computeInitialPosition(Key<?> key) {
GinjectorBindings initialPosition = output.getGraph().getOrigin();
boolean pinned = initialPosition.isPinned(key);
// to install the binding in the origin.
if (pinned) {
PrettyPrinter.log(logger, TreeLogger.DEBUG, PrettyPrinter.format("Forcing %s to be installed in %s due to a pin.", key, initialPosition));
installOverrides.put(key, initialPosition);
}
while (canExposeKeyFrom(key, initialPosition, pinned)) {
PrettyPrinter.log(logger, TreeLogger.SPAM, "Moving the highest visible position of %s from %s to %s.", key, initialPosition, initialPosition.getParent());
initialPosition = initialPosition.getParent();
}
return initialPosition;
}
Aggregations