You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2019/11/01 07:39:40 UTC

[groovy] branch master updated: GROOVY-8457: use ClassHelper.make(Class) for resolved exception type

This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new 1437642  GROOVY-8457: use ClassHelper.make(Class) for resolved exception type
1437642 is described below

commit 1437642286adfc0b892f34abc1ad2738b6ea8595
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Thu Oct 31 20:17:18 2019 -0500

    GROOVY-8457: use ClassHelper.make(Class) for resolved exception type
---
 .../NotYetImplementedASTTransformation.java        |  3 +-
 .../NotYetImplementedTransformTest.groovy          | 43 ++++++++++++++++++++++
 2 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/subprojects/groovy-test/src/main/java/org/apache/groovy/test/transform/NotYetImplementedASTTransformation.java b/subprojects/groovy-test/src/main/java/org/apache/groovy/test/transform/NotYetImplementedASTTransformation.java
index 2b8cba3..7c6250c 100644
--- a/subprojects/groovy-test/src/main/java/org/apache/groovy/test/transform/NotYetImplementedASTTransformation.java
+++ b/subprojects/groovy-test/src/main/java/org/apache/groovy/test/transform/NotYetImplementedASTTransformation.java
@@ -33,6 +33,7 @@ import org.codehaus.groovy.transform.AbstractASTTransformation;
 import org.codehaus.groovy.transform.GroovyASTTransformation;
 
 import java.util.Arrays;
+import junit.framework.AssertionFailedError;
 
 import static org.codehaus.groovy.ast.tools.GeneralUtils.args;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.block;
@@ -52,7 +53,7 @@ import static org.codehaus.groovy.ast.tools.GeneralUtils.tryCatchS;
 public class NotYetImplementedASTTransformation extends AbstractASTTransformation {
 
     private static final ClassNode CATCH_TYPE = ClassHelper.make(Throwable.class);
-    private static final ClassNode THROW_TYPE = ClassHelper.make("junit.framework.AssertionFailedError"); // TODO: java.lang.AssertionError
+    private static final ClassNode THROW_TYPE = ClassHelper.make(AssertionFailedError.class); // TODO: java.lang.AssertionError
 
     public void visit(ASTNode[] nodes, SourceUnit source) {
         if (!(nodes.length == 2 && nodes[0] instanceof AnnotationNode && nodes[1] instanceof MethodNode)) {
diff --git a/subprojects/groovy-test/src/test/groovy/org/apache/groovy/test/transform/NotYetImplementedTransformTest.groovy b/subprojects/groovy-test/src/test/groovy/org/apache/groovy/test/transform/NotYetImplementedTransformTest.groovy
index 99314d9..f6eef26 100644
--- a/subprojects/groovy-test/src/test/groovy/org/apache/groovy/test/transform/NotYetImplementedTransformTest.groovy
+++ b/subprojects/groovy-test/src/test/groovy/org/apache/groovy/test/transform/NotYetImplementedTransformTest.groovy
@@ -117,6 +117,27 @@ final class NotYetImplementedTransformTest {
         assert output.wasSuccessful() : '@Test method marked with @NotYetImplemented must NOT throw an AssertionFailedError'
     }
 
+    @Test // GROOVY-8457
+    void testNotYetImplementedJUnit4Failure_atCompileStatic()  {
+        def output = shell.evaluate('''
+            import groovy.transform.CompileStatic
+            import groovy.test.NotYetImplemented
+            import org.junit.Test
+            import org.junit.runner.JUnitCore
+
+            @CompileStatic
+            class MyTests {
+                @NotYetImplemented @Test void testThatFails()  {
+                    assert false
+                }
+            }
+
+            new JUnitCore().run(MyTests)
+        ''')
+
+        assert output.wasSuccessful() : '@Test method marked with @CompileStatic and @NotYetImplemented must NOT throw an AssertionFailedError'
+    }
+
     @Test
     void testNotYetImplementedJUnit4Success() {
         def output = shell.evaluate('''
@@ -137,4 +158,26 @@ final class NotYetImplementedTransformTest {
         assert output.failureCount == 1 : '@Test method marked with @NotYetImplemented must throw an AssertionFailedError'
         assert output.failures.first().exception instanceof AssertionFailedError : '@Test method marked with @NotYetImplemented must throw an AssertionFailedError'
     }
+
+    @Test // GROOVY-8457
+    void testNotYetImplementedJUnit4Success_atCompileStatic()  {
+        def output = shell.evaluate('''
+            import groovy.transform.CompileStatic
+            import groovy.test.NotYetImplemented
+            import org.junit.Test
+            import org.junit.runner.JUnitCore
+
+            @CompileStatic
+            class MyTests {
+                @NotYetImplemented @Test void testThatFails()  {
+                    assert true
+                }
+            }
+
+            new JUnitCore().run(MyTests)
+        ''')
+
+        assert output.failureCount == 1 : '@Test method marked with @CompileStatic and @NotYetImplemented must throw an AssertionFailedError'
+        assert output.failures.first().exception instanceof AssertionFailedError : '@Test method marked with @CompileStatic and @NotYetImplemented must throw an AssertionFailedError'
+    }
 }