diff --git a/core/test/com/google/inject/PrivateModuleTest.java b/core/test/com/google/inject/PrivateModuleTest.java index 4d89df2a2a..fe09b983f9 100644 --- a/core/test/com/google/inject/PrivateModuleTest.java +++ b/core/test/com/google/inject/PrivateModuleTest.java @@ -646,19 +646,30 @@ private static class ManyPrivateModules extends AbstractModule { @Override protected void configure() { // make sure duplicate sources are collapsed - install(new FailingPrivateModule()); - install(new FailingPrivateModule()); + install(new FailingPrivateModule("a")); + install(new FailingPrivateModule("b")); // but additional sources are listed - install(new SecondFailingPrivateModule()); + install(new SecondFailingPrivateModule("c")); } } private static class FailingPrivateModule extends PrivateModule { + private final String exposeAs; + + FailingPrivateModule(String exposeAs) { + this.exposeAs = exposeAs; + } + @Override protected void configure() { Key> key = new Key>() {}; bind(key).toInstance(new ArrayList()); + // Expose _something_ so that the child/private injector doesn't immediately get GC'd. + Key exposedKey = new Key(Names.named(exposeAs)) {}; + bind(exposedKey).toInstance("exposed"); + expose(exposedKey); + // Add the Provider binding, created just-in-time, // to make sure our linked JIT bindings have the correct source. getProvider(key); @@ -672,11 +683,22 @@ protected void configure() { /** A second class, so we can see another name in the source list. */ private static class SecondFailingPrivateModule extends PrivateModule { + private final String exposeAs; + + SecondFailingPrivateModule(String exposeAs) { + this.exposeAs = exposeAs; + } + @Override protected void configure() { Key> key = new Key>() {}; bind(key).toInstance(new ArrayList()); + // Expose _something_ so that the child/private injector doesn't immediately get GC'd. + Key exposedKey = new Key(Names.named(exposeAs)) {}; + bind(exposedKey).toInstance("exposed"); + expose(exposedKey); + // Add the Provider binding, created just-in-time, // to make sure our linked JIT bindings have the correct source. getProvider(key); diff --git a/core/test/com/google/inject/errors/ChildBindingAlreadySetErrorTest.java b/core/test/com/google/inject/errors/ChildBindingAlreadySetErrorTest.java index f5c0b72098..14ab16b8e2 100644 --- a/core/test/com/google/inject/errors/ChildBindingAlreadySetErrorTest.java +++ b/core/test/com/google/inject/errors/ChildBindingAlreadySetErrorTest.java @@ -7,6 +7,7 @@ import com.google.inject.AbstractModule; import com.google.inject.ConfigurationException; import com.google.inject.CreationException; +import com.google.inject.Exposed; import com.google.inject.Guice; import com.google.inject.Injector; import com.google.inject.PrivateModule; @@ -14,6 +15,7 @@ import com.google.inject.internal.InternalFlags; import com.google.inject.internal.InternalFlags.IncludeStackTraceOption; import javax.inject.Inject; +import javax.inject.Named; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -42,6 +44,14 @@ static class ChildModule extends PrivateModule { protected void configure() { bind(Foo.class).to(SubFoo.class); } + + // Expose _something_ so that the child/private injector doesn't immediately get GC'd. + @Provides + @Named("ChildModule") + @Exposed + String provideExposed() { + return "a"; + } } @Test @@ -61,6 +71,14 @@ protected void configure() {} Foo provideFoo() { return new Foo(); } + + // Expose _something_ so that the child/private injector doesn't immediately get GC'd. + @Provides + @Named("Child2Module") + @Exposed + String provideExposed() { + return "a"; + } } static class DependsOnFoo { @@ -106,6 +124,14 @@ protected void configure() { // Trigger a JIT binding for DependsOnFoo in this PrivateModule. getProvider(DependsOnFoo.class); } + + // Expose _something_ so that the child/private injector doesn't immediately get GC'd. + @Provides + @Named("Child3Module") + @Exposed + String provideExposed() { + return "a"; + } } static class ChildModule4 extends PrivateModule { @@ -113,6 +139,14 @@ static class ChildModule4 extends PrivateModule { protected void configure() { bind(DependsOnFoo.class).toInstance(new DependsOnFoo(new Foo())); } + + // Expose _something_ so that the child/private injector doesn't immediately get GC'd. + @Provides + @Named("Child4Module") + @Exposed + String provideExposed() { + return "a"; + } } @Test