You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2019/11/11 21:23:27 UTC

[groovy] branch GROOVY_2_5_X updated: GROOVY-8457: use ClassHelper.make(Class) for resolved exception type (port to 2_5_X)

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

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


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

commit 31532a98a60d3bd88ee34ac8788a15672a02cbdb
Author: Paul King <pa...@asert.com.au>
AuthorDate: Tue Nov 12 07:23:10 2019 +1000

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

diff --git a/subprojects/groovy-test/src/main/java/org/codehaus/groovy/transform/NotYetImplementedASTTransformation.java b/subprojects/groovy-test/src/main/java/org/codehaus/groovy/transform/NotYetImplementedASTTransformation.java
index c520bfb..75ee9f5 100644
--- a/subprojects/groovy-test/src/main/java/org/codehaus/groovy/transform/NotYetImplementedASTTransformation.java
+++ b/subprojects/groovy-test/src/main/java/org/codehaus/groovy/transform/NotYetImplementedASTTransformation.java
@@ -18,6 +18,7 @@
  */
 package org.codehaus.groovy.transform;
 
+import junit.framework.AssertionFailedError;
 import org.codehaus.groovy.ast.ASTNode;
 import org.codehaus.groovy.ast.AnnotatedNode;
 import org.codehaus.groovy.ast.AnnotationNode;
@@ -52,7 +53,7 @@ import static org.codehaus.groovy.ast.tools.GeneralUtils.throwS;
 public class NotYetImplementedASTTransformation extends AbstractASTTransformation {
 
     private static final ClassNode CATCHED_THROWABLE_TYPE = ClassHelper.make(Throwable.class);
-    private static final ClassNode ASSERTION_FAILED_ERROR_TYPE = ClassHelper.make("junit.framework.AssertionFailedError");
+    private static final ClassNode ASSERTION_FAILED_ERROR_TYPE = ClassHelper.make(AssertionFailedError.class);
 
     public void visit(ASTNode[] nodes, SourceUnit source) {
         if (nodes.length != 2 || !(nodes[0] instanceof AnnotationNode) || !(nodes[1] instanceof AnnotatedNode)) {
diff --git a/subprojects/groovy-test/src/test/groovy/org/codehaus/groovy/transform/NotYetImplementedTransformTest.groovy b/subprojects/groovy-test/src/test/groovy/org/codehaus/groovy/transform/NotYetImplementedTransformTest.groovy
index 50fb658..4365012 100644
--- a/subprojects/groovy-test/src/test/groovy/org/codehaus/groovy/transform/NotYetImplementedTransformTest.groovy
+++ b/subprojects/groovy-test/src/test/groovy/org/codehaus/groovy/transform/NotYetImplementedTransformTest.groovy
@@ -131,4 +131,47 @@ class NotYetImplementedTransformTest extends GroovyShellTestCase {
         assertEquals "test method marked with @NotYetImplemented must throw an AssertionFailedError", 1, output.failureCount
         assertEquals "test method marked with @NotYetImplemented must throw an AssertionFailedError", AssertionFailedError, output.failures.first().exception.class
     }
+
+    // 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() : '@CompileStatic @Test method with failing assertion marked with @NotYetImplemented should pass'
+    }
+
+
+    // 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 : 'Passing @CompileStatic @Test method marked with @NotYetImplemented should fail'
+            assert output.failures.first().exception instanceof AssertionFailedError : 'Passing @CompileStatic @Test method marked with @NotYetImplemented should throw an AssertionFailedError'
+        ''')
+    }
 }
\ No newline at end of file