From 39563f1050c2fc201ffbae22cdaf3ca6e7bdb2ad Mon Sep 17 00:00:00 2001 From: Benedikt Ritter Date: Sat, 10 Sep 2016 15:13:24 +0200 Subject: [PATCH 1/3] Add convinient method to check for the currently used Java Version --- surefire-integration-tests/pom.xml | 4 +++ .../its/CheckTestNgListenerReporterIT.java | 27 ++++++++++--------- .../surefire/its/Junit47WithCucumberIT.java | 6 +++-- .../its/fixture/HelperAssertions.java | 13 ++++++++- .../Surefire1177TestngParallelSuitesIT.java | 7 +++-- .../its/jiras/Surefire1211JUnitTestNgIT.java | 2 +- 6 files changed, 38 insertions(+), 21 deletions(-) diff --git a/surefire-integration-tests/pom.xml b/surefire-integration-tests/pom.xml index 727a24f12f..3fe4f55e3a 100644 --- a/surefire-integration-tests/pom.xml +++ b/surefire-integration-tests/pom.xml @@ -75,6 +75,10 @@ commons-io commons-io + + org.apache.commons + commons-lang3 + diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/CheckTestNgListenerReporterIT.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/CheckTestNgListenerReporterIT.java index c16967991a..e028215bea 100644 --- a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/CheckTestNgListenerReporterIT.java +++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/CheckTestNgListenerReporterIT.java @@ -19,6 +19,7 @@ * under the License. */ +import org.apache.commons.lang3.JavaVersion; import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase; import org.junit.Test; import org.junit.runner.RunWith; @@ -27,9 +28,9 @@ import java.util.Arrays; import java.util.Collection; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.greaterThanOrEqualTo; -import static org.junit.Assume.assumeThat; +import static org.apache.commons.lang3.JavaVersion.JAVA_1_5; +import static org.apache.commons.lang3.JavaVersion.JAVA_1_7; +import static org.apache.maven.surefire.its.fixture.HelperAssertions.assumeJavaVersion; import static org.junit.runners.Parameterized.Parameter; import static org.junit.runners.Parameterized.Parameters; @@ -47,10 +48,10 @@ public class CheckTestNgListenerReporterIT public static Collection data() { return Arrays.asList(new Object[][] { - { "5.6", "1.5" }, // First TestNG version with reporter support - { "5.7", "1.5" }, // default version from pom of the test case - { "5.10", "1.5" }, - { "5.13", "1.5" }, // "reporterslist" param becomes String instead of List + { "5.6", JAVA_1_5 }, // First TestNG version with reporter support + { "5.7", JAVA_1_5 }, // default version from pom of the test case + { "5.10", JAVA_1_5 }, + { "5.13", JAVA_1_5 }, // "reporterslist" param becomes String instead of List // "listener" param becomes String instead of List // configure(Map) in 5.14.1 and 5.14.2 is transforming List into a String with a space as separator. @@ -69,10 +70,10 @@ public static Collection data() //{ "5.14.4", "1.5" }, { "5.14.5", "1.5" }, // Fails: not able to test due to system dependency org.testng:guice missed the path and use to break CI // ClassNotFoundException: com.beust.jcommander.ParameterException - { "5.14.6", "1.5" }, // Usage of org.testng:guice removed - { "5.14.9", "1.5" }, // Latest 5.14.x TestNG version - { "6.0", "1.5" }, - { "6.9.9", "1.7" } // Currently latest TestNG version + { "5.14.6", JAVA_1_5 }, // Usage of org.testng:guice removed + { "5.14.9", JAVA_1_5 }, // Latest 5.14.x TestNG version + { "6.0", JAVA_1_5 }, + { "6.9.9", JAVA_1_7 } // Currently latest TestNG version }); } @@ -80,13 +81,13 @@ public static Collection data() public String version; @Parameter(1) - public String javaVersion; + public JavaVersion javaVersion; @Test public void testNgListenerReporter() { - assumeThat( System.getProperty( "java.version" ), is( greaterThanOrEqualTo( javaVersion ) ) ); + assumeJavaVersion( javaVersion ); unpack( "testng-listener-reporter", "_" + version ) .resetInitialGoals( version ) .executeTest() diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/Junit47WithCucumberIT.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/Junit47WithCucumberIT.java index 09e857ab9d..4850005f69 100644 --- a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/Junit47WithCucumberIT.java +++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/Junit47WithCucumberIT.java @@ -20,10 +20,12 @@ */ import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase; -import org.junit.Assume; import org.junit.Before; import org.junit.Test; +import static org.apache.commons.lang3.JavaVersion.JAVA_1_6; +import static org.apache.maven.surefire.its.fixture.HelperAssertions.assumeJavaVersion; + /** * Tests the JUnit 47 provider with the cucumber runner. At the moment, they don't play along that perfectly (minor * glitches in the reports with parallel=classes), but at least all tests are executed, the execution times are counted @@ -39,7 +41,7 @@ public class Junit47WithCucumberIT @Before public void assumeJdk16() { - Assume.assumeTrue( System.getProperty( "java.version" ).compareTo( "1.6" ) > 0 ); + assumeJavaVersion( JAVA_1_6 ); } @Test diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/HelperAssertions.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/HelperAssertions.java index 2e835dafac..0a6e918deb 100644 --- a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/HelperAssertions.java +++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/HelperAssertions.java @@ -23,13 +23,18 @@ import java.util.List; import java.util.Locale; +import org.apache.commons.lang3.JavaVersion; +import org.apache.commons.lang3.SystemUtils; import org.apache.maven.plugin.surefire.log.api.ConsoleLogger; import org.apache.maven.plugin.surefire.log.api.PrintStreamLogger; import org.apache.maven.plugins.surefire.report.ReportTestSuite; import org.apache.maven.plugins.surefire.report.SurefireReportParser; -import static junit.framework.Assert.assertTrue; import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertTrue; +import static org.hamcrest.Matchers.greaterThanOrEqualTo; +import static org.hamcrest.Matchers.is; +import static org.junit.Assume.assumeThat; @SuppressWarnings( { "JavaDoc" } ) public class HelperAssertions @@ -163,4 +168,10 @@ public static List extractITReports( File... testDirs ) throw new RuntimeException( "Couldn't parse XML reports", e ); } } + + public static void assumeJavaVersion( JavaVersion version ) + { + assumeThat( "java.specification.version: ", + SystemUtils.JAVA_SPECIFICATION_VERSION, is( greaterThanOrEqualTo( version.toString() ) ) ); + } } diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1177TestngParallelSuitesIT.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1177TestngParallelSuitesIT.java index 4f5befbcbf..a99e636d73 100644 --- a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1177TestngParallelSuitesIT.java +++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1177TestngParallelSuitesIT.java @@ -24,11 +24,11 @@ import org.apache.maven.surefire.its.fixture.SurefireLauncher; import org.junit.Test; +import static org.apache.commons.lang3.JavaVersion.JAVA_1_7; +import static org.apache.maven.surefire.its.fixture.HelperAssertions.assumeJavaVersion; import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.startsWith; -import static org.junit.Assume.assumeThat; /** * IT for https://issues.apache.org/jira/browse/SUREFIRE-1177 @@ -43,8 +43,7 @@ public class Surefire1177TestngParallelSuitesIT public void shouldRunTwoSuitesInParallel() throws VerificationException { - assumeThat( "java.specification.version: ", - System.getProperty( "java.specification.version" ), is( greaterThanOrEqualTo( "1.7" ) ) ); + assumeJavaVersion( JAVA_1_7 ); unpack().executeTest() .verifyErrorFree( 2 ) diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1211JUnitTestNgIT.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1211JUnitTestNgIT.java index 7846b7bf3e..da69e9da35 100644 --- a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1211JUnitTestNgIT.java +++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1211JUnitTestNgIT.java @@ -1 +1 @@ -package org.apache.maven.surefire.its.jiras; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase; import org.apache.maven.surefire.its.fixture.SurefireLauncher; import org.junit.Test; import static java.lang.System.getProperty; import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.is; import static org.junit.Assume.assumeThat; /** * @author Tibor Digana (tibor17) * @see {@linkplain https://jira.codehaus.org/browse/SUREFIRE-1211} * @since 2.19.1 */ public class Surefire1211JUnitTestNgIT extends SurefireJUnit4IntegrationTestCase { @Test public void withJUnit() { assumeThat( "java.specification.version: ", getProperty( "java.specification.version" ), is( greaterThanOrEqualTo( "1.7" ) ) ); unpack().threadCount( 1 ) .executeTest() .verifyErrorFree( 2 ); } @Test public void withoutJUnit() { assumeThat( "java.specification.version: ", getProperty( "java.specification.version" ), is( greaterThanOrEqualTo( "1.7" ) ) ); unpack().threadCount( 1 ) .sysProp( "junit", "false" ) .executeTest() .verifyErrorFree( 1 ); } private SurefireLauncher unpack() { return unpack( "surefire-1211" ); } } \ No newline at end of file +package org.apache.maven.surefire.its.jiras; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase; import org.apache.maven.surefire.its.fixture.SurefireLauncher; import org.junit.Test; import static org.apache.commons.lang3.JavaVersion.JAVA_1_7; import static org.apache.maven.surefire.its.fixture.HelperAssertions.assumeJavaVersion; /** * @author Tibor Digana (tibor17) * @see {@linkplain https://jira.codehaus.org/browse/SUREFIRE-1211} * @since 2.19.1 */ public class Surefire1211JUnitTestNgIT extends SurefireJUnit4IntegrationTestCase { @Test public void withJUnit() { assumeJavaVersion( JAVA_1_7 ); unpack().threadCount( 1 ) .executeTest() .verifyErrorFree( 2 ); } @Test public void withoutJUnit() { assumeJavaVersion( JAVA_1_7 ); unpack().threadCount( 1 ) .sysProp( "junit", "false" ) .executeTest() .verifyErrorFree( 1 ); } private SurefireLauncher unpack() { return unpack( "surefire-1211" ); } } \ No newline at end of file From 498942b7e0722a877ce46020840f5de75c148b46 Mon Sep 17 00:00:00 2001 From: Benedikt Ritter Date: Wed, 14 Sep 2016 17:46:16 +0200 Subject: [PATCH 2/3] Statically import SystemUtils.JAVA_SPECIFICATION_VERSION --- .../apache/maven/surefire/its/fixture/HelperAssertions.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/HelperAssertions.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/HelperAssertions.java index 0a6e918deb..4502b1baef 100644 --- a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/HelperAssertions.java +++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/HelperAssertions.java @@ -32,6 +32,7 @@ import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertTrue; +import static org.apache.commons.lang3.SystemUtils.JAVA_SPECIFICATION_VERSION; import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.is; import static org.junit.Assume.assumeThat; @@ -172,6 +173,6 @@ public static List extractITReports( File... testDirs ) public static void assumeJavaVersion( JavaVersion version ) { assumeThat( "java.specification.version: ", - SystemUtils.JAVA_SPECIFICATION_VERSION, is( greaterThanOrEqualTo( version.toString() ) ) ); + JAVA_SPECIFICATION_VERSION, is( greaterThanOrEqualTo( version.toString() ) ) ); } } From a23b25439cacc1fc369ac962fd031dab585c473c Mon Sep 17 00:00:00 2001 From: Benedikt Ritter Date: Sat, 17 Sep 2016 16:16:12 +0200 Subject: [PATCH 3/3] Don't compare strings --- .../apache/maven/surefire/its/fixture/HelperAssertions.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/HelperAssertions.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/HelperAssertions.java index 4502b1baef..98edcfb398 100644 --- a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/HelperAssertions.java +++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/HelperAssertions.java @@ -36,6 +36,7 @@ import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.is; import static org.junit.Assume.assumeThat; +import static org.junit.Assume.assumeTrue; @SuppressWarnings( { "JavaDoc" } ) public class HelperAssertions @@ -172,7 +173,7 @@ public static List extractITReports( File... testDirs ) public static void assumeJavaVersion( JavaVersion version ) { - assumeThat( "java.specification.version: ", - JAVA_SPECIFICATION_VERSION, is( greaterThanOrEqualTo( version.toString() ) ) ); + assumeTrue( "java.specification.version: " + JAVA_SPECIFICATION_VERSION, + SystemUtils.isJavaVersionAtLeast( version ) ); } }