Search in sources :

Example 21 with Binding

use of com.google.gwt.inject.rebind.binding.Binding 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 22 with Binding

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

the class BindingResolverTest method testResolveDependenciesInRoot_InheritedByChild.

public void testResolveDependenciesInRoot_InheritedByChild() throws Exception {
    StandardTree tree = createExampleTree();
    // Bar already in root, inherited in childL.  Baz already in root.  Foo can still be in root.
    Binding fooBinding = expectCreateBinding(foo(), required(foo(), bar()), required(foo(), baz()));
    bind(bar(), tree.root);
    bindParent(bar(), tree.root, tree.childL);
    bind(baz(), tree.root);
    tree.root.addBinding(foo(), fooBinding);
    expectParentBinding(foo(), tree.root, tree.childLL);
    replayAndResolve(tree.childLL, required(Dependency.GINJECTOR, foo()));
}
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)

Example 23 with Binding

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

the class BindingResolverTest method testResolveCycleDepBeforeProviderBound.

public void testResolveCycleDepBeforeProviderBound() throws Exception {
    // Foo -> {Baz, Provider<Bar>}; Provider<Bar> -> Bar -> Foo. Baz is bound at childL
    // Similar to the last one, although this time the already bound dependency comes before
    // earlier in the cycle (Before the provider).  We should still make sure that Foo is
    // in the correct position.
    StandardTree tree = createExampleTree();
    Binding fooBinding = expectCreateBinding(foo(), required(foo(), baz()), required(foo(), providerBar()));
    Binding providerBarBinding = expectCreateBinding(providerBar(), requiredLazy(providerBar(), bar()));
    Binding barBinding = expectCreateBinding(bar(), required(bar(), foo()));
    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()));
}
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)

Example 24 with Binding

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

the class BindingResolverTest method testResolveBindingWithOptionalDependency_DepFails.

public void testResolveBindingWithOptionalDependency_DepFails() throws Exception {
    StandardTree tree = createExampleTree();
    // Baz is optional and fails to resolve
    Binding fooBinding = expectCreateBinding(foo(), required(foo(), bar()), optional(foo(), baz()));
    expect(bindingCreator.create(baz())).andThrow(new BindingCreationException("Unable to create"));
    bind(bar(), tree.root);
    tree.root.addBinding(foo(), fooBinding);
    // childLL gets foo from childL
    expectParentBinding(foo(), tree.root, tree.childLL);
    replayAndResolve(tree.childLL, required(Dependency.GINJECTOR, foo()));
}
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) BindingCreationException(com.google.gwt.inject.rebind.resolution.ImplicitBindingCreator.BindingCreationException)

Example 25 with Binding

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

the class BindingResolverTest method testResolveDependenciesInOriginExposedToParent.

public void testResolveDependenciesInOriginExposedToParent() throws Exception {
    StandardTree tree = createExampleTree();
    // Bar is bound in the child, but exposed to the root.  Foo should still be in root
    bind(bar(), tree.childR);
    bindChild(bar(), tree.root, tree.childR);
    bind(baz(), tree.root);
    Binding fooBinding = expectCreateBinding(foo(), required(foo(), bar()), required(foo(), baz()));
    tree.root.addBinding(foo(), fooBinding);
    expectParentBinding(foo(), tree.root, tree.childR);
    replayAndResolve(tree.childR, required(Dependency.GINJECTOR, foo()));
}
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)

Aggregations

Binding (com.google.gwt.inject.rebind.binding.Binding)34 ParentBinding (com.google.gwt.inject.rebind.binding.ParentBinding)28 ExposedChildBinding (com.google.gwt.inject.rebind.binding.ExposedChildBinding)25 GinjectorBindings (com.google.gwt.inject.rebind.GinjectorBindings)10 Key (com.google.inject.Key)6 Dependency (com.google.gwt.inject.rebind.binding.Dependency)5 GinjectorNameGenerator (com.google.gwt.inject.rebind.GinjectorNameGenerator)4 NameGenerator (com.google.gwt.inject.rebind.util.NameGenerator)4 BindingCreationException (com.google.gwt.inject.rebind.resolution.ImplicitBindingCreator.BindingCreationException)3 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 Context (com.google.gwt.inject.rebind.binding.Context)2 HashMap (java.util.HashMap)2 UnableToCompleteException (com.google.gwt.core.ext.UnableToCompleteException)1 GinScope (com.google.gwt.inject.rebind.GinScope)1 GinjectorBinding (com.google.gwt.inject.rebind.binding.GinjectorBinding)1 RemoteServiceProxyBinding (com.google.gwt.inject.rebind.binding.RemoteServiceProxyBinding)1 InjectorMethod (com.google.gwt.inject.rebind.util.InjectorMethod)1 SourceWriteUtil (com.google.gwt.inject.rebind.util.SourceWriteUtil)1 Singleton (com.google.inject.Singleton)1