Permalink
Browse files

only auto-add @Test annotation to methods that return void

  • Loading branch information...
graemerocher committed Feb 20, 2013
1 parent f424310 commit efe91129a0b210a6ede24509ff9b0471cc55cd9f
@@ -93,6 +93,7 @@
public static final AnnotationNode TEST_ANNOTATION = new AnnotationNode(new ClassNode(Test.class));
public static final ClassNode GROOVY_TEST_CASE_CLASS = new ClassNode(GroovyTestCase.class);
+ public static final String VOID_TYPE = "void";
private ResourceLocator resourceLocator;
@@ -216,7 +217,9 @@ public void testFor(ClassNode classNode, ClassExpression ce) {
List<AnnotationNode> existingTestAnnotations = methodNode.getAnnotations(testAnnotationClassNode);
if (isCandidateMethod(methodNode) && (methodNode.getName().startsWith("test") || existingTestAnnotations.size()>0)) {
if (existingTestAnnotations.size()==0) {
- methodNode.addAnnotation(TEST_ANNOTATION);
+ ClassNode returnType = methodNode.getReturnType();
+ if(returnType.getName().equals(VOID_TYPE))
+ methodNode.addAnnotation(TEST_ANNOTATION);
}
hasTestMethods = true;
}
@@ -0,0 +1,18 @@
+package grails.test.mixin
+
+import grails.test.mixin.web.GroovyPageUnitTestMixin
+import org.junit.Test
+
+/**
+ * @author Graeme Rocher
+ */
+@TestMixin(GroovyPageUnitTestMixin)
+@TestFor(MyController)
+class ControllerAndGroovyPageMixinTests {
+
+ // verifies the above 2 mixins can operator together without error
+ @Test
+ void testController() {
+ controller != null
+ }
+}

0 comments on commit efe9112

Please sign in to comment.