Repository: maven-surefire Updated Branches: refs/heads/junit5 9580f5ef2 -> 507809204
SUREFIRE-1384: Start implemeting JUnit Plattform ProviderInfo for automatic provider lookup Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/1a7dd9b8 Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/1a7dd9b8 Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/1a7dd9b8 Branch: refs/heads/junit5 Commit: 1a7dd9b84f8462fa841e015826b44c553ff64b5e Parents: 9580f5e Author: Benedikt Ritter <[email protected]> Authored: Thu Jun 8 14:46:04 2017 +0200 Committer: Benedikt Ritter <[email protected]> Committed: Sat Aug 19 11:42:54 2017 +0200 ---------------------------------------------------------------------- .../plugin/surefire/AbstractSurefireMojo.java | 48 ++++++++++++++- .../maven/surefire/its/JUnitPlattformIT.java | 48 +++++++++++++++ .../src/test/resources/junit-plattform/pom.xml | 58 +++++++++++++++++ .../src/test/java/junitplattform/BasicTest.java | 65 ++++++++++++++++++++ 4 files changed, 217 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/1a7dd9b8/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java ---------------------------------------------------------------------- diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java index a3ab13e..ef81cb8 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java @@ -933,6 +933,7 @@ public abstract class AbstractSurefireMojo new TestNgProviderInfo( getTestNgArtifact() ), new JUnitCoreProviderInfo( getJunitArtifact(), junitDepArtifact ), new JUnit4ProviderInfo( getJunitArtifact(), junitDepArtifact ), + new JUnitPlattformProviderInfo( getJunitArtifact() ), new JUnit3ProviderInfo() ) .resolve(); } @@ -1430,12 +1431,22 @@ public abstract class AbstractSurefireMojo private boolean isJunit47Compatible( Artifact artifact ) { - return dependencyResolver.isWithinVersionSpec( artifact, "[4.7,)" ); + return dependencyResolver.isWithinVersionSpec( artifact, "[4.7,4.12.0)" ); } private boolean isAnyJunit4( Artifact artifact ) { - return dependencyResolver.isWithinVersionSpec( artifact, "[4.0,)" ); + return dependencyResolver.isWithinVersionSpec( artifact, "[4.0,4.12.0)" ); + } + + private boolean isJunitJupiter( Artifact artifact ) + { + return dependencyResolver.isWithinVersionSpec( artifact, "[5.0.0,)" ); + } + + private boolean isJunitVintage( Artifact artifact ) + { + return dependencyResolver.isWithinVersionSpec( artifact, "[4.12.0,5.0.0)" ); } static boolean isForkModeNever( String forkMode ) @@ -2602,6 +2613,39 @@ public abstract class AbstractSurefireMojo } + final class JUnitPlattformProviderInfo + implements ProviderInfo + { + private final Artifact junitArtifact; + + JUnitPlattformProviderInfo( Artifact junitArtifact ) + { + this.junitArtifact = junitArtifact; + } + + @Nonnull public String getProviderName() + { + return "org.apache.maven.surefire.junitplatform.JUnitPlatformProvider"; + } + + public boolean isApplicable() + { + return isJunitJupiter( junitArtifact ) || isJunitVintage( junitArtifact ); + } + + public void addProviderProperties() throws MojoExecutionException + { + } + + public Classpath getProviderClasspath() + throws ArtifactResolutionException, ArtifactNotFoundException, ArtifactResolverException + { + return dependencyResolver.getProviderClasspath( "surefire-junit-platform", + surefireBooterArtifact.getBaseVersion() ); + } + + } + final class JUnitCoreProviderInfo implements ProviderInfo { http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/1a7dd9b8/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/JUnitPlattformIT.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/JUnitPlattformIT.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/JUnitPlattformIT.java new file mode 100644 index 0000000..b046dcc --- /dev/null +++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/JUnitPlattformIT.java @@ -0,0 +1,48 @@ +package org.apache.maven.surefire.its; + +/* + * 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; + +public class JUnitPlattformIT + extends SurefireJUnit4IntegrationTestCase +{ + private SurefireLauncher unpack() + { + return unpack( "/junit-plattform" ); + } + + @Test + public void test40() + throws Exception + { + assumeThat( "java.specification.version: ", + getProperty( "java.specification.version" ), is( greaterThanOrEqualTo( "1.8" ) ) ); + + unpack().executeTest().verifyErrorFree( 1 ); + } +} http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/1a7dd9b8/surefire-integration-tests/src/test/resources/junit-plattform/pom.xml ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/junit-plattform/pom.xml b/surefire-integration-tests/src/test/resources/junit-plattform/pom.xml new file mode 100644 index 0000000..44105ee --- /dev/null +++ b/surefire-integration-tests/src/test/resources/junit-plattform/pom.xml @@ -0,0 +1,58 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ 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. + --> + +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>org.apache.maven.plugins.surefire</groupId> + <artifactId>junit-plattform</artifactId> + <version>1.0-SNAPSHOT</version> + <name>Test for JUnit Plattform</name> + + <dependencies> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-api</artifactId> + <version>5.0.0-M4</version> + <scope>test</scope> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <source>1.8</source> + <target>1.8</target> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <version>${surefire.version}</version> + </plugin> + </plugins> + </build> + +</project> http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/1a7dd9b8/surefire-integration-tests/src/test/resources/junit-plattform/src/test/java/junitplattform/BasicTest.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/junit-plattform/src/test/java/junitplattform/BasicTest.java b/surefire-integration-tests/src/test/resources/junit-plattform/src/test/java/junitplattform/BasicTest.java new file mode 100644 index 0000000..3f03bdd --- /dev/null +++ b/surefire-integration-tests/src/test/resources/junit-plattform/src/test/java/junitplattform/BasicTest.java @@ -0,0 +1,65 @@ +package junitplattform; + +/* + * 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 static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class BasicTest +{ + + private boolean setUpCalled = false; + + private static boolean tearDownCalled = false; + + @BeforeEach + public void setUp() + { + setUpCalled = true; + tearDownCalled = false; + System.out.println( "Called setUp" ); + } + + @AfterEach + public void tearDown() + { + setUpCalled = false; + tearDownCalled = true; + System.out.println( "Called tearDown" ); + } + + @Test + public void testSetUp() + { + assertTrue( setUpCalled, "setUp was not called" ); + } + + + @AfterAll + public static void oneTimeTearDown() + { + + } + +}
