|
46 | 46 | import org.codehaus.groovy.grails.plugins.web.filters.FiltersConfigArtefactHandler; |
47 | 47 | import org.codehaus.groovy.syntax.Token; |
48 | 48 | import org.codehaus.groovy.transform.GroovyASTTransformation; |
| 49 | +import org.junit.After; |
49 | 50 | import org.junit.Before; |
50 | 51 | import org.junit.Test; |
51 | 52 | import org.springframework.core.io.FileSystemResource; |
@@ -86,6 +87,10 @@ public class TestForTransformation extends TestMixinTransformation { |
86 | 87 | public static final ClassNode BEFORE_CLASS_NODE = new ClassNode(Before.class); |
87 | 88 | public static final AnnotationNode BEFORE_ANNOTATION = new AnnotationNode(BEFORE_CLASS_NODE); |
88 | 89 |
|
| 90 | + public static final ClassNode AFTER_CLASS_NODE = new ClassNode(After.class); |
| 91 | + public static final AnnotationNode AFTER_ANNOTATION = new AnnotationNode(AFTER_CLASS_NODE); |
| 92 | + |
| 93 | + |
89 | 94 | public static final AnnotationNode TEST_ANNOTATION = new AnnotationNode(new ClassNode(Test.class)); |
90 | 95 | public static final ClassNode GROOVY_TEST_CASE_CLASS = new ClassNode(GroovyTestCase.class); |
91 | 96 |
|
@@ -187,6 +192,8 @@ else if (isSpock) { |
187 | 192 | * @param ce The class expression that represents the class to test |
188 | 193 | */ |
189 | 194 | public void testFor(ClassNode classNode, ClassExpression ce) { |
| 195 | + |
| 196 | + autoAnnotateSetupTeardown(classNode); |
190 | 197 | boolean junit3Test = isJunit3Test(classNode); |
191 | 198 |
|
192 | 199 | // make sure the 'log' property is not the one from GroovyTestCase |
@@ -215,6 +222,19 @@ public void testFor(ClassNode classNode, ClassExpression ce) { |
215 | 222 | } |
216 | 223 | } |
217 | 224 |
|
| 225 | + private void autoAnnotateSetupTeardown(ClassNode classNode) { |
| 226 | + MethodNode setupMethod = classNode.getMethod(SET_UP_METHOD, GrailsArtefactClassInjector.ZERO_PARAMETERS); |
| 227 | + if ( setupMethod != null && setupMethod.getAnnotations(BEFORE_CLASS_NODE).size() == 0) { |
| 228 | + setupMethod.addAnnotation(BEFORE_ANNOTATION); |
| 229 | + } |
| 230 | + |
| 231 | + MethodNode tearDown = classNode.getMethod(TEAR_DOWN_METHOD, GrailsArtefactClassInjector.ZERO_PARAMETERS); |
| 232 | + if ( tearDown != null && tearDown.getAnnotations(AFTER_CLASS_NODE).size() == 0) { |
| 233 | + tearDown.addAnnotation(AFTER_ANNOTATION); |
| 234 | + } |
| 235 | + |
| 236 | + } |
| 237 | + |
218 | 238 | private Map<ClassNode, List<Class>> wovenMixins = new HashMap<ClassNode, List<Class>>(); |
219 | 239 | protected MethodNode weaveMock(ClassNode classNode, ClassExpression value, boolean isClassUnderTest) { |
220 | 240 |
|
|
0 commit comments