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


git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@10258 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/web/bindery/requestfactory/server/RequestFactoryInterfaceValidator.java b/user/src/com/google/web/bindery/requestfactory/server/RequestFactoryInterfaceValidator.java
index 5e3dfe3..645c199 100644
--- a/user/src/com/google/web/bindery/requestfactory/server/RequestFactoryInterfaceValidator.java
+++ b/user/src/com/google/web/bindery/requestfactory/server/RequestFactoryInterfaceValidator.java
@@ -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));
diff --git a/user/test/com/google/web/bindery/requestfactory/server/RequestFactoryInterfaceValidatorTest.java b/user/test/com/google/web/bindery/requestfactory/server/RequestFactoryInterfaceValidatorTest.java
index 698b2b4..e2da733 100644
--- a/user/test/com/google/web/bindery/requestfactory/server/RequestFactoryInterfaceValidatorTest.java
+++ b/user/test/com/google/web/bindery/requestfactory/server/RequestFactoryInterfaceValidatorTest.java
@@ -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();
@@ -128,6 +126,30 @@
     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 {
   }
 
@@ -249,6 +271,13 @@
   }
 
   @Service(Domain.class)
+  interface SkipValidationChecksReferredProxies extends ValueProxy {
+    @SkipInterfaceValidation
+    // still validates other proxies
+    DomainProxyMissingAnnotation getDomainProxyMissingAnnotation();
+  }
+
+  @Service(Domain.class)
   interface SkipValidationContext extends RequestContext {
     @SkipInterfaceValidation
     Request<Integer> doesNotExist(int a);
@@ -263,13 +292,6 @@
     boolean doesNotExist();
   }
 
-  @Service(Domain.class)
-  interface SkipValidationChecksReferredProxies extends ValueProxy {
-    @SkipInterfaceValidation
-    // still validates other proxies
-    DomainProxyMissingAnnotation getDomainProxyMissingAnnotation();
-  }
-
   @ProxyFor(Domain.class)
   @ProxyForName("Domain")
   @Service(Domain.class)
@@ -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) {
@@ -365,6 +386,12 @@
     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()));
   }
 }