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/04/17 01:35:29 UTC

[groovy] 02/02: more consistent JDK version checking in tests

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

commit db9349ead6c0c4f7540281946de600d4c959b759
Author: Paul King <pa...@asert.com.au>
AuthorDate: Wed Apr 17 11:28:35 2019 +1000

    more consistent JDK version checking in tests
---
 src/test/groovy/execute/ExecuteTest.groovy                       | 6 ++++--
 src/test/groovy/transform/ThreadInterruptTest.groovy             | 5 +++--
 src/test/groovy/util/logging/CommonsTest.groovy                  | 4 +++-
 src/test/org/codehaus/groovy/reflection/SecurityTest.java        | 4 +++-
 .../groovy/runtime/m12n/ExtensionModuleHelperForTests.groovy     | 9 +++------
 .../groovy-ant/src/test/groovy/groovy/ant/Groovy8872Test.groovy  | 5 ++++-
 .../groovy-ant/src/test/groovy/groovy/ant/Groovy8969Test.groovy  | 5 ++++-
 .../codehaus/groovy/tools/shell/commands/EditCommandTest.groovy  | 5 +++--
 .../vm8/StaticMethodOverloadCompileStaticTest.groovy             | 4 ++--
 9 files changed, 29 insertions(+), 18 deletions(-)

diff --git a/src/test/groovy/execute/ExecuteTest.groovy b/src/test/groovy/execute/ExecuteTest.groovy
index 458de33..bc458ba 100644
--- a/src/test/groovy/execute/ExecuteTest.groovy
+++ b/src/test/groovy/execute/ExecuteTest.groovy
@@ -18,6 +18,8 @@
  */
 package groovy.execute
 
+import static groovy.test.GroovyAssert.isAtLeastJdk
+
 /**
  *  Cross platform tests for the DGM#execute() family of methods.
  */
@@ -72,7 +74,7 @@ class ExecuteTest extends GroovyTestCase {
                 "groovy.ui.GroovyMain",
                 "-e",
                 "sleep(2000); println('Done'); System.exit(0)"]
-        if (System.getProperty('java.specification.version') >= '9') {
+        if (isAtLeastJdk('9.0')) {
             javaArgs.add(3, '--add-modules')
             javaArgs.add(4, 'java.xml.bind')
         }
@@ -124,7 +126,7 @@ class ExecuteTest extends GroovyTestCase {
                 "groovy.ui.GroovyMain",
                 "-e",
                 "println(System.getenv('foo'))"]
-        if (System.getProperty('java.specification.version') >= '9') {
+        if (isAtLeastJdk('9.0')) {
             javaArgs.add(3, '--add-modules')
             javaArgs.add(4, 'java.xml.bind')
         }
diff --git a/src/test/groovy/transform/ThreadInterruptTest.groovy b/src/test/groovy/transform/ThreadInterruptTest.groovy
index 5c488fb..4747d2d 100644
--- a/src/test/groovy/transform/ThreadInterruptTest.groovy
+++ b/src/test/groovy/transform/ThreadInterruptTest.groovy
@@ -27,14 +27,15 @@ import org.junit.Test
 
 import java.lang.reflect.Modifier
 
-import static groovy.util.GroovyAssert.shouldFail
+import static groovy.test.GroovyAssert.isAtLeastJdk
+import static groovy.test.GroovyAssert.shouldFail
 import static org.junit.Assume.assumeTrue
 
 /**
  * Test for @ThreadInterrupt.
  */
 class ThreadInterruptTest {
-    private static final boolean jdk12plus = System.getProperty('java.specification.version') >= '12'
+    private static final boolean jdk12plus = isAtLeastJdk('12.0')
     private Map<String, MethodNode> oldValues = [:]
 
     @After
diff --git a/src/test/groovy/util/logging/CommonsTest.groovy b/src/test/groovy/util/logging/CommonsTest.groovy
index 44fe3ef..6b89079 100644
--- a/src/test/groovy/util/logging/CommonsTest.groovy
+++ b/src/test/groovy/util/logging/CommonsTest.groovy
@@ -21,6 +21,8 @@ package groovy.util.logging
 import java.lang.reflect.Field
 import java.lang.reflect.Modifier
 
+import static groovy.test.GroovyAssert.isAtLeastJdk
+
 /**
  * Unit test for the commons logging @Log based annotation.
  */
@@ -161,7 +163,7 @@ class CommonsTest extends GroovyTestCase {
         // JDK12+ doesn't allow adjusting static final fields even via reflection
         // so skip this test on such JDK versions - it is only this test which is affected
         // and currently we have coverage from builds with lower JDK versions.
-        if (System.getProperty('java.specification.version') >= '12') return
+        if (isAtLeastJdk('12')) return
 
         Class clazz = new GroovyClassLoader().parseClass('''
             class LogDecorator extends groovy.util.Proxy {
diff --git a/src/test/org/codehaus/groovy/reflection/SecurityTest.java b/src/test/org/codehaus/groovy/reflection/SecurityTest.java
index a5fd724..ac0d874 100644
--- a/src/test/org/codehaus/groovy/reflection/SecurityTest.java
+++ b/src/test/org/codehaus/groovy/reflection/SecurityTest.java
@@ -31,6 +31,8 @@ import java.security.Permission;
 import java.security.Permissions;
 import java.security.ProtectionDomain;
 
+import static groovy.test.GroovyAssert.isAtLeastJdk;
+
 public class SecurityTest extends GroovyTestCase {
 
     @SuppressWarnings("unused")
@@ -216,7 +218,7 @@ public class SecurityTest extends GroovyTestCase {
 
     public void testChecksReflectPermissionForInvokeOnPackagePrivateMethodsInRestrictedJavaPackages() throws Exception {
         // FIX_JDK9 remove this exemption for JDK9
-        if (new BigDecimal(System.getProperty("java.specification.version")).compareTo(new BigDecimal("9.0")) >= 0) {
+        if (isAtLeastJdk("9.0")) {
             return;
         }
         cachedMethodUnderTest = createCachedMethod(ClassLoader.class, "getBootstrapClassPath", new Class[0]);
diff --git a/src/test/org/codehaus/groovy/runtime/m12n/ExtensionModuleHelperForTests.groovy b/src/test/org/codehaus/groovy/runtime/m12n/ExtensionModuleHelperForTests.groovy
index caba115..a3da1de 100644
--- a/src/test/org/codehaus/groovy/runtime/m12n/ExtensionModuleHelperForTests.groovy
+++ b/src/test/org/codehaus/groovy/runtime/m12n/ExtensionModuleHelperForTests.groovy
@@ -20,6 +20,8 @@ package org.codehaus.groovy.runtime.m12n
 
 import org.codehaus.groovy.runtime.DefaultGroovyStaticMethods
 
+import static groovy.test.GroovyAssert.isAtLeastJdk
+
 class ExtensionModuleHelperForTests {
     static void doInFork(String code) {
         doInFork("GroovyTestCase", code)
@@ -40,12 +42,7 @@ class ExtensionModuleHelperForTests {
         Set<String> cp = System.getProperty("java.class.path").split(File.pathSeparator) as Set
         cp << baseDir.absolutePath
 
-        boolean jdk9 = false
-        try {
-            jdk9 = new BigDecimal(System.getProperty("java.specification.version")).compareTo(new BigDecimal("9.0")) >= 0
-        } catch (e) {
-            // ignore
-        }
+        boolean jdk9 = isAtLeastJdk('9.0')
 
         def ant = new AntBuilder()
         def allowed = [
diff --git a/subprojects/groovy-ant/src/test/groovy/groovy/ant/Groovy8872Test.groovy b/subprojects/groovy-ant/src/test/groovy/groovy/ant/Groovy8872Test.groovy
index bc7953f..bc46aed 100644
--- a/subprojects/groovy-ant/src/test/groovy/groovy/ant/Groovy8872Test.groovy
+++ b/subprojects/groovy-ant/src/test/groovy/groovy/ant/Groovy8872Test.groovy
@@ -18,6 +18,8 @@
  */
 package groovy.ant
 
+import static groovy.test.GroovyAssert.isAtLeastJdk
+
 class Groovy8872Test extends AntTestCase {
     private scriptParamNameCheck = '''
         @ExtractParamNames
@@ -28,7 +30,8 @@ class Groovy8872Test extends AntTestCase {
     '''
 
     void testParameterNamesSeenInAST() {
-        if (System.getProperty('java.specification.version') < '1.8') return
+        // parameter name inclusion in bytecode is a JDK8+ feature
+        if (!isAtLeastJdk('1.8')) return
 //        def debugLogger = new org.apache.tools.ant.DefaultLogger()
 //        debugLogger.setMessageOutputLevel(4)
 //        debugLogger.setOutputPrintStream(System.out)
diff --git a/subprojects/groovy-ant/src/test/groovy/groovy/ant/Groovy8969Test.groovy b/subprojects/groovy-ant/src/test/groovy/groovy/ant/Groovy8969Test.groovy
index cdadb16..0bc4244 100644
--- a/subprojects/groovy-ant/src/test/groovy/groovy/ant/Groovy8969Test.groovy
+++ b/subprojects/groovy-ant/src/test/groovy/groovy/ant/Groovy8969Test.groovy
@@ -18,6 +18,8 @@
  */
 package groovy.ant
 
+import static groovy.test.GroovyAssert.isAtLeastJdk
+
 class Groovy8969Test extends AntTestCase {
     private scriptParamNameCheck = '''
         import org.codehaus.groovy.control.CompilerConfiguration
@@ -38,7 +40,8 @@ class Groovy8969Test extends AntTestCase {
     '''
 
     void testParameterNamesSeenInAST() {
-        if (System.getProperty('java.specification.version') < '1.8') return
+        // parameter name inclusion in bytecode is a JDK8+ feature
+        if (!isAtLeastJdk('1.8')) return
 //        def debugLogger = new org.apache.tools.ant.DefaultLogger()
 //        debugLogger.setMessageOutputLevel(4)
 //        debugLogger.setOutputPrintStream(System.out)
diff --git a/subprojects/groovy-groovysh/src/test/groovy/org/codehaus/groovy/tools/shell/commands/EditCommandTest.groovy b/subprojects/groovy-groovysh/src/test/groovy/org/codehaus/groovy/tools/shell/commands/EditCommandTest.groovy
index acf9de1..56b30d5 100644
--- a/subprojects/groovy-groovysh/src/test/groovy/org/codehaus/groovy/tools/shell/commands/EditCommandTest.groovy
+++ b/subprojects/groovy-groovysh/src/test/groovy/org/codehaus/groovy/tools/shell/commands/EditCommandTest.groovy
@@ -18,6 +18,8 @@
  */
 package org.codehaus.groovy.tools.shell.commands
 
+import static groovy.test.GroovyAssert.isAtLeastJdk
+
 /**
  * Tests for the {@link EditCommand} class.
  */
@@ -33,8 +35,7 @@ class EditCommandTest
 
         // GROOVY-6201: Editor should inherit I/O from the current process.
         //    Fixed only for java >= 1.7 using new ProcessBuilder api
-        def javaVer = Double.valueOf(System.getProperty('java.specification.version'))
-        if (javaVer >= 1.7) {
+        if (isAtLeastJdk('1.7')) {
             assert pb.redirectInput() == ProcessBuilder.Redirect.INHERIT
             assert pb.redirectOutput() == ProcessBuilder.Redirect.INHERIT
         }
diff --git a/subprojects/tests-vm8/src/test/groovy/org/apache/groovy/runtime/methoddispatching/vm8/StaticMethodOverloadCompileStaticTest.groovy b/subprojects/tests-vm8/src/test/groovy/org/apache/groovy/runtime/methoddispatching/vm8/StaticMethodOverloadCompileStaticTest.groovy
index e04e94c..604ee3b 100644
--- a/subprojects/tests-vm8/src/test/groovy/org/apache/groovy/runtime/methoddispatching/vm8/StaticMethodOverloadCompileStaticTest.groovy
+++ b/subprojects/tests-vm8/src/test/groovy/org/apache/groovy/runtime/methoddispatching/vm8/StaticMethodOverloadCompileStaticTest.groovy
@@ -20,7 +20,7 @@ package org.apache.groovy.runtime.methoddispatching.vm8
 
 import groovy.transform.CompileStatic
 
-import static org.codehaus.groovy.control.CompilerConfiguration.isPostJDK9
+import static groovy.test.GroovyAssert.isAtLeastJdk
 
 @CompileStatic
 class StaticMethodOverloadCompileStaticTest extends GroovyTestCase {
@@ -51,6 +51,6 @@ class StaticMethodOverloadCompileStaticTest extends GroovyTestCase {
     // FIX_JDK9 JDK9 (and presumably 10+) doesn't like the way we do static methods in interfaces - remove this version
     // check once we fix the problem
     boolean isJdk9() {
-        isPostJDK9(System.getProperty("java.specification.version"))
+        isAtLeastJdk('9.0')
     }
 }