groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject [groovy] branch GROOVY_2_5_X updated: GROOVY-9135: Additional support for @Testable annotation in JUnit5Runner
Date Wed, 22 May 2019 15:03:45 GMT
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 a995ad2  GROOVY-9135: Additional support for @Testable annotation in JUnit5Runner
a995ad2 is described below

commit a995ad2deca3c9df655af158e32fc08c4742848e
Author: Paul King <paulk@asert.com.au>
AuthorDate: Thu May 23 00:53:04 2019 +1000

    GROOVY-9135: Additional support for @Testable annotation in JUnit5Runner
---
 .../main/java/groovy/junit5/plugin/JUnit5Runner.java   | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/subprojects/groovy-test-junit5/src/main/java/groovy/junit5/plugin/JUnit5Runner.java
b/subprojects/groovy-test-junit5/src/main/java/groovy/junit5/plugin/JUnit5Runner.java
index 15e6709..9d6d125 100644
--- a/subprojects/groovy-test-junit5/src/main/java/groovy/junit5/plugin/JUnit5Runner.java
+++ b/subprojects/groovy-test-junit5/src/main/java/groovy/junit5/plugin/JUnit5Runner.java
@@ -25,6 +25,8 @@ import org.codehaus.groovy.runtime.InvokerHelper;
 
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
+import java.util.HashSet;
+import java.util.Set;
 
 /**
  * Integration code for running JUnit5 tests in Groovy.
@@ -63,18 +65,30 @@ public class JUnit5Runner implements GroovyRunner {
             if (name.startsWith("org.junit.jupiter.api.") && tryLoadClass(name, loader))
{
                 return true;
             }
-            if (isJUnit5TestableMetaAnnotationPresent(type) && tryLoadClass(name,
loader)) {
+            // it might directly annotate a class, e.g. Specification in Spock 2
+            if (name.equals("org.junit.platform.commons.annotation.Testable") &&
tryLoadClass(name, loader)) {
+                return true;
+            }
+            if (isJUnit5TestableMetaAnnotationPresent(type, new HashSet<>()) &&
tryLoadClass(name, loader)) {
                 return true;
             }
         }
         return false;
     }
 
-    private boolean isJUnit5TestableMetaAnnotationPresent(Class<? extends Annotation>
type) {
+    private boolean isJUnit5TestableMetaAnnotationPresent(Class<? extends Annotation>
type, Set<String> seen) {
         for (Annotation annotation : type.getAnnotations()) {
+            // It might annotate an annotation, e.g. jqwik @Property
             if ("org.junit.platform.commons.annotation.Testable".equals(annotation.annotationType().getName()))
{
                 return true;
             }
+            // perhaps it's a meta-annotation, e.g. jqwik @Example is annotated with @Property
+            if (!seen.contains(annotation.annotationType().getName())) {
+                seen.add(annotation.annotationType().getName());
+                if (isJUnit5TestableMetaAnnotationPresent(annotation.annotationType(), seen))
{
+                    return true;
+                }
+            }
         }
         return false;
     }


Mime
View raw message