use of com.google.gwt.inject.rebind.GinjectorBindings in project google-gin by gwtplus.
the class BindingResolverTest method testCircularDependency.
public void testCircularDependency() throws Exception {
GinjectorBindings root = createInjectorNode("root");
expectCreateBinding(bar(), required(bar(), baz()));
expectCreateBinding(baz(), required(baz(), bar()));
Capture<String> errorMessage = new Capture<String>();
errorManager.logError(isA(String.class), isA(Object.class), isA(Object.class));
// Intentionally use a different key, so that == won't work
replayAndResolve(root, required(Dependency.GINJECTOR, bar()));
}
use of com.google.gwt.inject.rebind.GinjectorBindings in project google-gin by gwtplus.
the class BindingResolverTest method testDependencyInOtherChild.
public void testDependencyInOtherChild() throws Exception {
// Test one of the "weird" behaviors in Guice. Foo depends on Bar and Baz. Because
// Bar is bound in a sibling, we can't create Bar in the parent. Therefore,
// we create Bar (and Foo) in the origin
GinjectorBindings root = createInjectorNode("root");
GinjectorBindings childL = createInjectorNode("childL");
GinjectorBindings childR = createInjectorNode("childR");
setChildren(root, childL, childR);
bind(baz(), root);
bind(bar(), childL);
expect(root.isBoundLocallyInChild(bar())).andReturn(true).anyTimes();
Binding fooBinding = expectCreateBinding(foo(), required(foo(), bar()), required(foo(), baz()));
Binding barBinding = expectCreateBinding(bar());
childR.addBinding(bar(), barBinding);
expectParentBinding(baz(), root, childR);
childR.addBinding(foo(), fooBinding);
replayAndResolve(childR, required(Dependency.GINJECTOR, foo()));
}
use of com.google.gwt.inject.rebind.GinjectorBindings in project google-gin by gwtplus.
the class DependencyExplorerTest method testSourcePositioned_Exposed.
/**
* Tests that when we have a dependency that installs multiple steps (eg, GINJECTOR -> foo -> bar)
* we will use the highest foo available.
*/
public void testSourcePositioned_Exposed() throws Exception {
GinjectorBindings parent = control.createMock("parent", GinjectorBindings.class);
expect(origin.getDependencies()).andStubReturn(TestUtils.dependencyList(new Dependency(Dependency.GINJECTOR, foo(), SOURCE), new Dependency(foo(), bar(), SOURCE)));
expect(origin.isBound(foo())).andReturn(true).anyTimes();
expect(origin.isBound(bar())).andReturn(false).anyTimes();
expect(origin.isPinned(foo())).andReturn(true).anyTimes();
expect(origin.isPinned(bar())).andReturn(false).anyTimes();
expect(origin.getParent()).andReturn(parent).anyTimes();
expect(parent.getParent()).andReturn(null).times(2);
expect(parent.isBound(foo())).andReturn(true);
expect(parent.isBound(bar())).andReturn(true);
control.replay();
DependencyExplorerOutput output = dependencyExplorer.explore(origin);
assertSame(parent, output.getPreExistingLocations().get(foo()));
assertSame(parent, output.getPreExistingLocations().get(bar()));
control.verify();
}
use of com.google.gwt.inject.rebind.GinjectorBindings in project google-gin by gwtplus.
the class GinjectorBindingsOutputterTest method testOutputStaticInjections.
// Verify that outputting static injections creates and dispatches to the
// correct fragment classes.
public void testOutputStaticInjections() throws Exception {
PrintWriter printWriter = new PrintWriter(new ByteArrayOutputStream());
GeneratorContext ctx = createMock(GeneratorContext.class, "ctx");
expect(ctx.tryCreate((TreeLogger) anyObject(), (String) anyObject(), (String) anyObject())).andStubReturn(printWriter);
Capture<FieldLiteral<SuperClass>> fieldCapture = new Capture<FieldLiteral<SuperClass>>();
Capture<MethodLiteral<SuperClass, Method>> methodCapture = new Capture<MethodLiteral<SuperClass, Method>>();
NameGenerator nameGenerator = createMock(NameGenerator.class, "nameGenerator");
expect(nameGenerator.convertToValidMemberName("injectStatic_com.google.gwt.inject.rebind.output." + "GinjectorBindingsOutputterTest$SubClass")).andStubReturn("test_injectSubClass");
expect(nameGenerator.convertToValidMemberName("injectStatic_com.google.gwt.inject.rebind.output.subpackage." + "SubPackageClass")).andStubReturn("test_injectSubPackageClass");
SourceWriteUtil sourceWriteUtil = createMock(SourceWriteUtil.class, "sourceWriteUtil");
expect(sourceWriteUtil.createFieldInjection(capture(fieldCapture), (String) anyObject(), (NameGenerator) anyObject(), (List<InjectorMethod>) anyObject())).andReturn(SourceSnippets.forText(""));
MethodCallUtil methodCallUtil = createMock(MethodCallUtil.class, "methodCallUtil");
expect(methodCallUtil.createMethodCallWithInjection(capture(methodCapture), (String) anyObject(), (NameGenerator) anyObject(), (List<InjectorMethod>) anyObject())).andReturn(SourceSnippets.forText(""));
GinjectorBindings bindings = createMock(GinjectorBindings.class, "bindings");
expect(bindings.getNameGenerator()).andStubReturn(nameGenerator);
expect(bindings.getStaticInjectionRequests()).andStubReturn(Arrays.<Class<?>>asList(SubClass.class, SubPackageClass.class));
String ginjectorPackageName = "com.google.gwt.inject.rebind.output";
String ginjectorClassName = "GinjectorFragmentOutputterTest$FakeGinjector";
GinjectorFragmentOutputter.Factory fragmentOutputterFactory = createMock(GinjectorFragmentOutputter.Factory.class, "fragmentOutputterFactory");
GinjectorFragmentOutputter fragmentOutputter = createMock(GinjectorFragmentOutputter.class, "fragmentOutputter");
GinjectorFragmentOutputter fragmentOutputterSubpackage = createMock(GinjectorFragmentOutputter.class, "fragmentOutputterSubpackage");
expect(fragmentOutputterFactory.create(bindings, new FragmentPackageName(null, "com.google.gwt.inject.rebind.output"), ginjectorPackageName, ginjectorClassName)).andStubReturn(fragmentOutputter);
expect(fragmentOutputterFactory.create(bindings, new FragmentPackageName(null, "com.google.gwt.inject.rebind.output.subpackage"), ginjectorPackageName, ginjectorClassName)).andStubReturn(fragmentOutputterSubpackage);
fragmentOutputter.outputMethod((InjectorMethod) anyObject());
fragmentOutputterSubpackage.outputMethod((InjectorMethod) anyObject());
fragmentOutputter.invokeInInitializeStaticInjections("test_injectSubClass");
fragmentOutputterSubpackage.invokeInInitializeStaticInjections("test_injectSubPackageClass");
replay();
GinjectorBindingsOutputter outputter = new GinjectorBindingsOutputter(ctx, null, fragmentOutputterFactory, new TestFragmentPackageNameFactory(), null, TreeLogger.NULL, methodCallUtil, null, null);
GinjectorBindingsOutputter.FragmentMap fragments = new GinjectorBindingsOutputter.FragmentMap(bindings, ginjectorPackageName, ginjectorClassName, fragmentOutputterFactory);
outputter.outputStaticInjections(bindings, fragments, sourceWriteUtil);
verify();
TypeLiteral<SuperClass> superClass = TypeLiteral.get(SuperClass.class);
assertEquals(superClass, methodCapture.getValue().getDeclaringType());
assertEquals(superClass, fieldCapture.getValue().getDeclaringType());
}
use of com.google.gwt.inject.rebind.GinjectorBindings in project google-gin by gwtplus.
the class BindingPositioner method computeInitialPositions.
/**
* Place an initial guess in the position map that places each implicit binding as high as
* possible in the injector tree without causing double binding.
*/
private void computeInitialPositions() {
positions.putAll(output.getPreExistingLocations());
for (Key<?> key : output.getImplicitlyBoundKeys()) {
GinjectorBindings initialPosition = computeInitialPosition(key);
PrettyPrinter.log(logger, TreeLogger.DEBUG, PrettyPrinter.format("Initial highest visible position of %s is %s", key, initialPosition));
positions.put(key, initialPosition);
}
}
Aggregations