@@ -0,0 +1,3250 @@
+package org.grouplens.grapht;%0A%0Aimport org.grouplens.grapht.annotation.DefaultImplementation;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0A%0Aimport javax.annotation.Nullable;%0Aimport javax.inject.Inject;%0A%0Aimport static org.hamcrest.CoreMatchers.instanceOf;%0Aimport static org.hamcrest.CoreMatchers.notNullValue;%0Aimport static org.hamcrest.CoreMatchers.nullValue;%0Aimport static org.junit.Assert.assertThat;%0A%0A/**%0A * Test using multiple context bindings to separate components.%0A *%0A * @author Michael Ekstrand%0A */%0Apublic class ContextOverrideTest %7B%0A    private InjectorBuilder build;%0A%0A    @Before%0A    public void setup() %7B%0A        build = new InjectorBuilder();%0A    %7D%0A%0A    /**%0A     * Test bindings with a null, and a deeper context using a binding. To make things%0A     * interesting, the thing tweaked is a concrete class.%0A     */%0A    @Test%0A    public void testDeeperOverride() %7B%0A        build.in(Outer.class)%0A             .bind(IPlug.class)%0A             .to(PlugH.class);%0A        build.in(Inner.class)%0A             .bind(IPlug.class)%0A             .to(PlugA.class);%0A        Injector inj = build.build();%0A%0A        Inner in = inj.getInstance(Inner.class);%0A        assertThat(in, notNullValue());%0A        assertThat(in.plug, instanceOf(PlugA.class));%0A%0A        Outer out = inj.getInstance(Outer.class);%0A        assertThat(out, notNullValue());%0A        assertThat(out.plug, instanceOf(PlugH.class));%0A        assertThat(out.inner, notNullValue());%0A        assertThat(out.inner.plug, instanceOf(PlugA.class));%0A    %7D%0A%0A    /**%0A     * Test bindings with a null, and a deeper context using a binding.%0A     */%0A    @Test%0A    public void testNullDeepConcrete() %7B%0A        build.in(COuter.class)%0A             .bind(Plug.class)%0A             .toNull();%0A        build.in(CInner.class)%0A             .bind(Plug.class)%0A             .to(Plug.class);%0A        Injector inj = build.build();%0A%0A        CInner in = inj.getInstance(CInner.class);%0A        assertThat(in, notNullValue());%0A        assertThat(in.plug, notNullValue());%0A%0A        COuter out = inj.getInstance(COuter.class);%0A        assertThat(out, notNullValue());%0A        assertThat(out.plug, nullValue());%0A        assertThat(out.inner, notNullValue());%0A        assertThat(out.inner.plug, notNullValue());%0A        assertThat(out.inner.plug, instanceOf(Plug.class));%0A    %7D%0A%0A    @DefaultImplementation(PlugA.class)%0A    public static interface IPlug %7B%7D%0A    public static class PlugA implements IPlug %7B%7D%0A    public static class PlugH implements IPlug %7B%7D%0A%0A    public static class Inner %7B%0A        final IPlug plug;%0A%0A        @Inject%0A        public Inner(IPlug p) %7B%0A            plug = p;%0A        %7D%0A    %7D%0A%0A    public static class Outer %7B%0A        final IPlug plug;%0A        final Inner inner;%0A%0A        @Inject%0A        public Outer(Inner in, @Nullable IPlug p) %7B%0A            plug = p;%0A            inner = in;%0A        %7D%0A    %7D%0A%0A    public static class Plug %7B%7D%0A%0A    public static class CInner %7B%0A        final Plug plug;%0A%0A        @Inject%0A        public CInner(@Nullable Plug p) %7B%0A            plug = p;%0A        %7D%0A    %7D%0A%0A    public static class COuter %7B%0A        final Plug plug;%0A        final CInner inner;%0A%0A        @Inject%0A        public COuter(CInner in, @Nullable Plug p) %7B%0A            plug = p;%0A            inner = in;%0A        %7D%0A    %7D%0A%7D%0A

Add more tests for context-sensitive bindings