Reviewers: rjrjr,
http://gwt-code-reviews.appspot.com/1453803/diff/1/user/test/com/google/web/bindery/requestfactory/server/RequestFactoryInterfaceValidatorTest.java
File
user/test/com/google/web/bindery/requestfactory/server/RequestFactoryInterfaceValidatorTest.java
(right):
http://gwt-code-reviews.appspot.com/1453803/diff/1/user/test/com/google/web/bindery/requestfactory/server/RequestFactoryInterfaceValidatorTest.java#newcode281
user/test/com/google/web/bindery/requestfactory/server/RequestFactoryInterfaceValidatorTest.java:281:
interface SkipValidationContext extends RequestContext {
Re-sorted the file.
Description:
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
Please review this at http://gwt-code-reviews.appspot.com/1453803/
Affected files:
M
user/src/com/google/web/bindery/requestfactory/server/RequestFactoryInterfaceValidator.java
M
user/test/com/google/web/bindery/requestfactory/server/RequestFactoryInterfaceValidatorTest.java
Index:
user/src/com/google/web/bindery/requestfactory/server/RequestFactoryInterfaceValidator.java
===================================================================
---
user/src/com/google/web/bindery/requestfactory/server/RequestFactoryInterfaceValidator.java
(revision 10245)
+++
user/src/com/google/web/bindery/requestfactory/server/RequestFactoryInterfaceValidator.java
(working copy)
@@ -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));
Index:
user/test/com/google/web/bindery/requestfactory/server/RequestFactoryInterfaceValidatorTest.java
===================================================================
---
user/test/com/google/web/bindery/requestfactory/server/RequestFactoryInterfaceValidatorTest.java
(revision 10245)
+++
user/test/com/google/web/bindery/requestfactory/server/RequestFactoryInterfaceValidatorTest.java
(working copy)
@@ -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 {
}
@@ -246,21 +268,6 @@
@Service(Domain.class)
interface ServiceRequestMissingMethod extends RequestContext {
Request<Integer> doesNotExist(int a);
- }
-
- @Service(Domain.class)
- interface SkipValidationContext extends RequestContext {
- @SkipInterfaceValidation
- Request<Integer> doesNotExist(int a);
-
- @SkipInterfaceValidation
- Request<Long> foo(int a);
- }
-
- @Service(Domain.class)
- interface SkipValidationProxy extends ValueProxy {
- @SkipInterfaceValidation
- boolean doesNotExist();
}
@Service(Domain.class)
@@ -270,6 +277,21 @@
DomainProxyMissingAnnotation getDomainProxyMissingAnnotation();
}
+ @Service(Domain.class)
+ interface SkipValidationContext extends RequestContext {
+ @SkipInterfaceValidation
+ Request<Integer> doesNotExist(int a);
+
+ @SkipInterfaceValidation
+ Request<Long> foo(int a);
+ }
+
+ @Service(Domain.class)
+ interface SkipValidationProxy extends ValueProxy {
+ @SkipInterfaceValidation
+ boolean doesNotExist();
+ }
+
@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()));
}
}
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors