Revision: 1326
Author: sberlin
Date: Thu Oct 28 20:01:12 2010
Log: Update test to make sure custom @Nullable annotations work, in addition to c.g.i.i.util.Nullable.
http://code.google.com/p/google-guice/source/detail?r=1326

Modified:
 /trunk/core/test/com/google/inject/NullableInjectionPointTest.java

=======================================
--- /trunk/core/test/com/google/inject/NullableInjectionPointTest.java Tue Oct 26 19:03:52 2010 +++ /trunk/core/test/com/google/inject/NullableInjectionPointTest.java Thu Oct 28 20:01:12 2010
@@ -2,6 +2,13 @@

 import static com.google.inject.Asserts.assertContains;

+import java.lang.annotation.Annotation;
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
 import com.google.inject.internal.util.Nullable;

 import junit.framework.TestCase;
@@ -72,6 +79,24 @@
         = createInjector().getInstance(NullableFooField.class);
     assertNull(nff.foo);
   }
+
+  public void testInjectNullIntoCustomNullableConstructor() {
+    CustomNullableFooConstructor nfc
+        = createInjector().getInstance(CustomNullableFooConstructor.class);
+    assertNull(nfc.foo);
+  }
+
+  public void testInjectNullIntoCustomNullableMethod() {
+    CustomNullableFooMethod nfm
+        = createInjector().getInstance(CustomNullableFooMethod.class);
+    assertNull(nfm.foo);
+  }
+
+  public void testInjectNullIntoCustomNullableField() {
+    CustomNullableFooField nff
+        = createInjector().getInstance(CustomNullableFooField.class);
+    assertNull(nff.foo);
+  }

   private Injector createInjector() {
     return Guice.createInjector(
@@ -115,6 +140,7 @@
       }
     });
     assertNull(injector.getInstance(NullableFooField.class).foo);
+    assertNull(injector.getInstance(CustomNullableFooField.class).foo);

     try {
       injector.getInstance(FooField.class);
@@ -135,6 +161,7 @@
       }
     });
     assertNull(injector.getInstance(NullableFooField.class).foo);
+    assertNull(injector.getInstance(CustomNullableFooField.class).foo);

     try {
       injector.getInstance(FooField.class);
@@ -155,6 +182,7 @@
       }
     });
     assertNull(injector.getInstance(NullableFooField.class).foo);
+    assertNull(injector.getInstance(CustomNullableFooField.class).foo);

     try {
       injector.getInstance(FooField.class);
@@ -193,4 +221,28 @@
       this.foo = foo;
     }
   }
-}
+
+  static class CustomNullableFooConstructor {
+    Foo foo;
+    @Inject CustomNullableFooConstructor(@Namespace.Nullable Foo foo) {
+      this.foo = foo;
+    }
+  }
+
+  static class CustomNullableFooField {
+    @Inject @Namespace.Nullable Foo foo;
+  }
+  static class CustomNullableFooMethod {
+    Foo foo;
+    @Inject void setFoo(@Namespace.Nullable Foo foo) {
+      this.foo = foo;
+    }
+  }
+
+  static interface Namespace {
+    @Documented
+    @Retention(RetentionPolicy.RUNTIME)
+    @Target({ElementType.PARAMETER, ElementType.FIELD})
+    @interface Nullable { }
+  }
+}

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