groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject [groovy] 06/09: GROOVY-8457: use ClassHelper.make(Class) for resolved exception type
Date Fri, 01 Nov 2019 16:45:44 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit dd3a64f3a0546f6626982bc5ba8f68e43d27631e
Author: Eric Milles <eric.milles@thomsonreuters.com>
AuthorDate: Thu Oct 31 20:17:18 2019 -0500

    GROOVY-8457: use ClassHelper.make(Class) for resolved exception type
    
    (cherry picked from commit 1437642286adfc0b892f34abc1ad2738b6ea8595)
---
 .../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'
+    }
 }


Mime
View raw message