Author: limpbizkit
Date: Wed Apr  1 09:04:48 2009
New Revision: 923

Modified:
    trunk/test/com/google/inject/InjectableTypeListenerTest.java

Log:
A couple of test changes:
  - to ensure that lookups are valid by the time InjectionListener.hear() is  
called
  - to ensure that classes with no @Inject-annotated members still fire the  
injectable type listener. This test is currently failing.

Modified: trunk/test/com/google/inject/InjectableTypeListenerTest.java
==============================================================================
--- trunk/test/com/google/inject/InjectableTypeListenerTest.java        
(original)
+++ trunk/test/com/google/inject/InjectableTypeListenerTest.java        Wed Apr 
 1  
09:04:48 2009
@@ -350,6 +350,16 @@
      final AtomicReference<MembersInjector<A>> aMembersInjectorReference
          = new AtomicReference<MembersInjector<A>>();

+    final InjectionListener<Object> lookupsTester = new  
InjectionListener<Object>() {
+      public void afterInjection(Object injectee) {
+        assertNotNull(bProviderReference.get().get());
+
+        A a = new A();
+        aMembersInjectorReference.get().injectMembers(a);
+        assertNotNull(a.injector);
+      }
+    };
+
      Guice.createInjector(new AbstractModule() {
        protected void configure() {
          bindListener(only(TypeLiteral.get(C.class)), new  
InjectableType.Listener() {
@@ -374,18 +384,17 @@
                    expected.getMessage());
              }
              aMembersInjectorReference.set(aMembersInjector);
+
+            encounter.register(lookupsTester);
            }
          });

-        bind(C.class);
+        // this ensures the type listener fires, and also the  
afterInjection() listener
+        bind(C.class).asEagerSingleton();
        }
      });

-    assertNotNull(bProviderReference.get().get());
-
-    A a = new A();
-    aMembersInjectorReference.get().injectMembers(a);
-    assertNotNull(a.injector);
+    lookupsTester.afterInjection(null);
    }

    public void testLookupsPostCreate() {
@@ -404,6 +413,29 @@
      });

      injector.getInstance(C.class);
+  }
+
+  /**
+   * We had a bug where we weren't notifying of types encountered for  
member injection when those
+   * types had no members to be injected. Constructed types are always  
injected because they always
+   * have at least one injection point: the class constructor.
+   */
+  public void testTypesWithNoInjectableMembersAreNotified() {
+    final AtomicInteger notificationCount = new AtomicInteger();
+
+    Guice.createInjector(new AbstractModule() {
+      protected void configure() {
+        bindListener(any(), new InjectableType.Listener() {
+          public <I> void hear(InjectableType<I> injectableType,  
Encounter<I> encounter) {
+            notificationCount.incrementAndGet();
+          }
+        });
+
+        bind(C.class).toInstance(new C());
+      }
+    });
+
+    assertEquals(1, notificationCount.get());
    }

    // TODO: recursively accessing a lookup should fail

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to