Author: limpbizkit
Date: Sat Jun 20 11:01:04 2009
New Revision: 1023

Modified:
    trunk/src/com/google/inject/spi/InjectionPoint.java
    trunk/test/com/google/inject/BindingTest.java

Log:
More tests, redefining InjectionPoint equality to consider the generic type  
of the injected type

Modified: trunk/src/com/google/inject/spi/InjectionPoint.java
==============================================================================
--- trunk/src/com/google/inject/spi/InjectionPoint.java (original)
+++ trunk/src/com/google/inject/spi/InjectionPoint.java Sat Jun 20 11:01:04  
2009
@@ -164,11 +164,12 @@

    @Override public boolean equals(Object o) {
      return o instanceof InjectionPoint
-        && member.equals(((InjectionPoint) o).member);
+        && member.equals(((InjectionPoint) o).member)
+        && declaringType.equals(((InjectionPoint) o).declaringType);
    }

    @Override public int hashCode() {
-    return member.hashCode();
+    return member.hashCode() ^ declaringType.hashCode();
    }

    @Override public String toString() {

Modified: trunk/test/com/google/inject/BindingTest.java
==============================================================================
--- trunk/test/com/google/inject/BindingTest.java       (original)
+++ trunk/test/com/google/inject/BindingTest.java       Sat Jun 20 11:01:04 2009
@@ -209,28 +209,57 @@
    }

    public void testToConstructorBindings() throws NoSuchMethodException {
-    final Constructor<C> constructor = C.class.getConstructor(Stage.class);
+    final Constructor constructor = C.class.getConstructor(Stage.class,  
Object.class);

      Injector injector = Guice.createInjector(new AbstractModule() {
        protected void configure() {
-        bind(C.class).toConstructor(constructor);
+        bind(new TypeLiteral<C<Stage>>() {}).toConstructor(constructor);
+        bind(new TypeLiteral<C<Injector>>() {}).toConstructor(constructor);
        }
      });
-
-    assertEquals(Stage.DEVELOPMENT, injector.getInstance(C.class).stage);
+
+    C<Stage> one = injector.getInstance(new Key<C<Stage>>() {});
+    assertEquals(Stage.DEVELOPMENT, one.stage);
+    assertEquals(Stage.DEVELOPMENT, one.t);
+    assertEquals(Stage.DEVELOPMENT, one.anotherT);
+
+    C<Injector> two = injector.getInstance(new Key<C<Injector>>() {});
+    assertEquals(Stage.DEVELOPMENT, two.stage);
+    assertEquals(injector, two.t);
+    assertEquals(injector, two.anotherT);
    }

-  public static class C {
-    private final Stage stage;
+  public static class C<T> {
+    private Stage stage;
+    private T t;
+    @Inject T anotherT;

-    public C(Stage stage) {
+    public C(Stage stage, T t) {
        this.stage = stage;
+      this.t = t;
      }

-    @Inject C() {
-      this.stage = null;
-    }
+    @Inject C() {}
    }


+  public void testToConstructorBinding() throws NoSuchMethodException {
+    final Constructor<D> constructor = D.class.getConstructor(Stage.class);
+
+    Injector injector = Guice.createInjector(new AbstractModule() {
+      protected void configure() {
+        bind(Object.class).toConstructor(constructor);
+      }
+    });
+
+    D d = (D) injector.getInstance(Object.class);
+    assertEquals(Stage.DEVELOPMENT, d.stage);
+  }
+
+  public static class D {
+    Stage stage;
+    public D(Stage stage) {
+      this.stage = stage;
+    }
+  }
  }

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