Author: limpbizkit
Date: Mon Jul 13 17:45:10 2009
New Revision: 1044
Modified:
trunk/test/com/google/inject/CircularDependencyTest.java
Log:
New failing test: circularly dependent providers aren't properly
singletons! And they aren't detected either.
See issue 391, reported by mcculls.
Modified: trunk/test/com/google/inject/CircularDependencyTest.java
==============================================================================
--- trunk/test/com/google/inject/CircularDependencyTest.java (original)
+++ trunk/test/com/google/inject/CircularDependencyTest.java Mon Jul 13
17:45:10 2009
@@ -23,6 +23,12 @@
*/
public class CircularDependencyTest extends TestCase {
+ @Override protected void setUp() throws Exception {
+ super.setUp();
+ Chicken.nextInstanceId = 0;
+ Egg.nextInstanceId = 0;
+ }
+
public void testCircularlyDependentConstructors()
throws CreationException {
Injector injector = Guice.createInjector(new AbstractModule() {
@@ -110,5 +116,37 @@
public A getA() {
return this;
}
+ }
+
+ static class Chicken {
+ static int nextInstanceId;
+ final int instanceId = nextInstanceId++;
+ @Inject Egg source;
+ }
+
+ static class Egg {
+ static int nextInstanceId;
+ final int instanceId = nextInstanceId++;
+ @Inject Chicken source;
+ }
+
+ public void testCircularlyDependentSingletonsWithProviders() {
+ Injector injector = Guice.createInjector(new AbstractModule() {
+ protected void configure() {
+ bind(Chicken.class).in(Singleton.class);
+ }
+
+ @Provides @Singleton Egg provideEgg(Chicken chicken) {
+ Egg egg = new Egg();
+ egg.source = chicken;
+ return egg;
+ }
+ });
+
+ injector.getInstance(Egg.class);
+ injector.getInstance(Chicken.class);
+
+ assertEquals(1, Chicken.nextInstanceId);
+ assertEquals(1, Egg.nextInstanceId);
}
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"google-guice-dev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/google-guice-dev?hl=en
-~----------~----~----~----~------~----~------~--~---