Revision: 10258
Author:   [email protected]
Date:     Wed Jun  1 10:19:05 2011
Log: Add a test to RequestFactoryInterfaceValidator that the findFoo() domain
method is static.
http://code.google.com/p/google-web-toolkit/issues/detail?id=6428
Patch by: bobv
Review by: rjrjr
Reported by: zundel

Review at http://gwt-code-reviews.appspot.com/1453803

http://code.google.com/p/google-web-toolkit/source/detail?r=10258

Modified:
/trunk/user/src/com/google/web/bindery/requestfactory/server/RequestFactoryInterfaceValidator.java /trunk/user/test/com/google/web/bindery/requestfactory/server/RequestFactoryInterfaceValidatorTest.java

=======================================
--- /trunk/user/src/com/google/web/bindery/requestfactory/server/RequestFactoryInterfaceValidator.java Tue Apr 19 06:04:28 2011 +++ /trunk/user/src/com/google/web/bindery/requestfactory/server/RequestFactoryInterfaceValidator.java Wed Jun 1 10:19:05 2011
@@ -1077,6 +1077,9 @@
             + " cannot be used as the argument to %s(%s)", print(keyType),
             findMethod.getName(), print(findMethod.getArgumentTypes()[0]));
       }
+      if (!findMethod.isDeclaredStatic()) {
+        logger.poison("The %s method must be static", findMethodName);
+      }
     } else {
       logger.poison("There is no %s method in type %s that returns %2$s",
           findMethodName, print(domainType));
=======================================
--- /trunk/user/test/com/google/web/bindery/requestfactory/server/RequestFactoryInterfaceValidatorTest.java Tue Apr 19 06:04:28 2011 +++ /trunk/user/test/com/google/web/bindery/requestfactory/server/RequestFactoryInterfaceValidatorTest.java Wed Jun 1 10:19:05 2011
@@ -62,12 +62,10 @@
       return 0;
     }
   }
-
   @ProxyFor(ClinitEntity.class)
   interface ClinitEntityProxy extends EntityProxy {
     Object OBJECT = new Object();
   }
-
   @Service(ClinitEntity.class)
   interface ClinitRequestContext extends RequestContext {
     Object OBJECT = new Object();
@@ -127,6 +125,30 @@
   interface DomainWithSqlDateProxy extends EntityProxy {
     java.sql.Date getSqlDate();
   }
+
+  /**
+   * Tests that the validator reports non-static finder methods.
+   */
+  static class EntityWithInstanceFind {
+    public String getId() {
+      return null;
+    }
+
+    public int getVersion() {
+      return 0;
+    }
+
+    /**
+     * This method should be static.
+     */
+    EntityWithInstanceFind findEntityWithInstanceFind(String key) {
+      return null;
+    }
+  }
+
+  @ProxyFor(EntityWithInstanceFind.class)
+  interface EntityWithInstanceFindProxy extends EntityProxy {
+  }

   class Foo {
   }
@@ -247,6 +269,13 @@
   interface ServiceRequestMissingMethod extends RequestContext {
     Request<Integer> doesNotExist(int a);
   }
+
+  @Service(Domain.class)
+  interface SkipValidationChecksReferredProxies extends ValueProxy {
+    @SkipInterfaceValidation
+    // still validates other proxies
+    DomainProxyMissingAnnotation getDomainProxyMissingAnnotation();
+  }

   @Service(Domain.class)
   interface SkipValidationContext extends RequestContext {
@@ -262,13 +291,6 @@
     @SkipInterfaceValidation
     boolean doesNotExist();
   }
-
-  @Service(Domain.class)
-  interface SkipValidationChecksReferredProxies extends ValueProxy {
-    @SkipInterfaceValidation
-    // still validates other proxies
-    DomainProxyMissingAnnotation getDomainProxyMissingAnnotation();
-  }

   @ProxyFor(Domain.class)
   @ProxyForName("Domain")
@@ -294,8 +316,7 @@
   static class Value {
   }

-  static class VisibleErrorContext extends
-      RequestFactoryInterfaceValidator.ErrorContext {
+ static class VisibleErrorContext extends RequestFactoryInterfaceValidator.ErrorContext {
     final List<String> logs;

     public VisibleErrorContext(Logger logger) {
@@ -364,6 +385,12 @@
     v.validateEntityProxy(DomainWithSqlDateProxy.class.getName());
     assertTrue(v.isPoisoned());
   }
+
+  public void testFindMustBeStatic() {
+    v.validateEntityProxy(EntityWithInstanceFindProxy.class.getName());
+    assertTrue(v.isPoisoned());
+ assertTrue(errors.logs.contains("The findEntityWithInstanceFind method must be static"));
+  }

   /**
    * Test the {@link FindRequest} context used to implement find().
@@ -378,8 +405,7 @@
    */
   public void testFollowingTypeParameters() {
     v.validateEntityProxy(HasList.class.getName());
-    assertNotNull(v.getEntityProxyTypeName(HasListDomain.class.getName(),
-        HasList.class.getName()));
+ assertNotNull(v.getEntityProxyTypeName(HasListDomain.class.getName(), HasList.class.getName()));
     assertNotNull(v.getEntityProxyTypeName(Domain.class.getName(),
         ReachableOnlyThroughParamaterList.class.getName()));
     assertNotNull(v.getEntityProxyTypeName(Domain.class.getName(),
@@ -487,7 +513,8 @@
     Logger logger = Logger.getLogger("");
     logger.setLevel(DUMP_PAYLOAD ? Level.ALL : Level.OFF);
     errors = new VisibleErrorContext(logger);
-    v = new RequestFactoryInterfaceValidator(errors, new ClassLoaderLoader(
-        Thread.currentThread().getContextClassLoader()));
+    v =
+ new RequestFactoryInterfaceValidator(errors, new ClassLoaderLoader(Thread.currentThread()
+            .getContextClassLoader()));
   }
 }

--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to