Skip to content

Commit efe9112

Browse files
committed
only auto-add @test annotation to methods that return void
1 parent f424310 commit efe9112

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

grails-plugin-testing/src/main/groovy/org/codehaus/groovy/grails/compiler/injection/test/TestForTransformation.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public class TestForTransformation extends TestMixinTransformation {
9393

9494
public static final AnnotationNode TEST_ANNOTATION = new AnnotationNode(new ClassNode(Test.class));
9595
public static final ClassNode GROOVY_TEST_CASE_CLASS = new ClassNode(GroovyTestCase.class);
96+
public static final String VOID_TYPE = "void";
9697

9798
private ResourceLocator resourceLocator;
9899

@@ -216,7 +217,9 @@ public void testFor(ClassNode classNode, ClassExpression ce) {
216217
List<AnnotationNode> existingTestAnnotations = methodNode.getAnnotations(testAnnotationClassNode);
217218
if (isCandidateMethod(methodNode) && (methodNode.getName().startsWith("test") || existingTestAnnotations.size()>0)) {
218219
if (existingTestAnnotations.size()==0) {
219-
methodNode.addAnnotation(TEST_ANNOTATION);
220+
ClassNode returnType = methodNode.getReturnType();
221+
if(returnType.getName().equals(VOID_TYPE))
222+
methodNode.addAnnotation(TEST_ANNOTATION);
220223
}
221224
hasTestMethods = true;
222225
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package grails.test.mixin
2+
3+
import grails.test.mixin.web.GroovyPageUnitTestMixin
4+
import org.junit.Test
5+
6+
/**
7+
* @author Graeme Rocher
8+
*/
9+
@TestMixin(GroovyPageUnitTestMixin)
10+
@TestFor(MyController)
11+
class ControllerAndGroovyPageMixinTests {
12+
13+
// verifies the above 2 mixins can operator together without error
14+
@Test
15+
void testController() {
16+
controller != null
17+
}
18+
}

0 commit comments

Comments
 (0)