Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add convinient method to check for the currently used Java Version #120

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions surefire-integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -47,10 +48,10 @@ public class CheckTestNgListenerReporterIT
public static Collection<Object[]> 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<ReporterConfig>
{ "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<ReporterConfig>
// "listener" param becomes String instead of List<Class>

// configure(Map) in 5.14.1 and 5.14.2 is transforming List<Class> into a String with a space as separator.
Expand All @@ -69,24 +70,24 @@ public static Collection<Object[]> 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
});
}

@Parameter
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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,20 @@
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.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;
import static org.junit.Assume.assumeTrue;

@SuppressWarnings( { "JavaDoc" } )
public class HelperAssertions
Expand Down Expand Up @@ -163,4 +170,10 @@ public static List<ReportTestSuite> extractITReports( File... testDirs )
throw new RuntimeException( "Couldn't parse XML reports", e );
}
}

public static void assumeJavaVersion( JavaVersion version )
{
assumeTrue( "java.specification.version: " + JAVA_SPECIFICATION_VERSION,
SystemUtils.isJavaVersionAtLeast( version ) );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this is cool. Thx.
I will come back to your PRs soon.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am running the build mvn install -Prun-its, let's wait for the result.

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 )
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a> * @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" ); }}
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 <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a> * @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" ); }}
Expand Down