Skip to content

Commit d7f4dbb

Browse files
[SUREFIRE-2270] Use JUnit5 in surefire-shadefire
1 parent 7a98850 commit d7f4dbb

File tree

8 files changed

+132
-13
lines changed

8 files changed

+132
-13
lines changed

maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,7 +1154,9 @@ protected List<ProviderInfo> createProviders(TestClassPath testClasspath) throws
11541154
new TestNgProviderInfo(getTestNgArtifact()),
11551155
new JUnitCoreProviderInfo(getJunitArtifact(), junitDepArtifact),
11561156
new JUnit4ProviderInfo(getJunitArtifact(), junitDepArtifact),
1157-
new JUnit3ProviderInfo());
1157+
new JUnit3ProviderInfo(),
1158+
new JUnitPlatformProviderShadefireInfo(
1159+
getJUnitPlatformRunnerArtifact(), getJUnit5Artifact(), testClasspath));
11581160
}
11591161

11601162
SurefireProperties setupProperties() {
@@ -3034,7 +3036,7 @@ public Set<Artifact> getProviderClasspath() throws MojoExecutionException {
30343036
}
30353037
}
30363038

3037-
final class JUnitPlatformProviderInfo implements ProviderInfo {
3039+
class JUnitPlatformProviderInfo implements ProviderInfo {
30383040
private static final String PROVIDER_DEP_GID = "org.junit.platform";
30393041
private static final String PROVIDER_DEP_AID = "junit-platform-launcher";
30403042

@@ -3057,6 +3059,10 @@ public String getProviderName() {
30573059
return "org.apache.maven.surefire.junitplatform.JUnitPlatformProvider";
30583060
}
30593061

3062+
protected String getProviderArtifactName() {
3063+
return "surefire-junit-platform";
3064+
}
3065+
30603066
@Override
30613067
public boolean isApplicable() {
30623068
return junitPlatformRunnerArtifact == null && junitPlatformArtifact != null;
@@ -3082,7 +3088,7 @@ public Set<Artifact> getProviderClasspath() throws MojoExecutionException {
30823088
Map<String, Artifact> providerArtifacts = surefireDependencyResolver.getProviderClasspathAsMap(
30833089
session.getRepositorySession(),
30843090
project.getRemotePluginRepositories(),
3085-
"surefire-junit-platform",
3091+
getProviderArtifactName(),
30863092
surefireVersion);
30873093
Map<String, Artifact> testDeps = testClasspath.getTestDependencies();
30883094

@@ -3162,7 +3168,7 @@ private void narrowDependencies(
31623168
providerArtifacts.keySet().removeAll(testDependencies.keySet());
31633169
}
31643170

3165-
private void alignProviderVersions(Map<String, Artifact> providerArtifacts) throws MojoExecutionException {
3171+
protected void alignProviderVersions(Map<String, Artifact> providerArtifacts) throws MojoExecutionException {
31663172
String version = junitPlatformArtifact.getBaseVersion();
31673173
for (Artifact launcherArtifact : resolve(PROVIDER_DEP_GID, PROVIDER_DEP_AID, version, null, "jar")) {
31683174
String key = launcherArtifact.getGroupId() + ":" + launcherArtifact.getArtifactId();
@@ -3197,6 +3203,41 @@ private boolean hasDependencyPlatformEngine(Map<String, Artifact> dependencies)
31973203
}
31983204
}
31993205

3206+
final class JUnitPlatformProviderShadefireInfo extends JUnitPlatformProviderInfo {
3207+
3208+
JUnitPlatformProviderShadefireInfo(
3209+
Artifact junitPlatformRunnerArtifact,
3210+
Artifact junitPlatformArtifact,
3211+
@Nonnull TestClassPath testClasspath) {
3212+
super(junitPlatformRunnerArtifact, junitPlatformArtifact, testClasspath);
3213+
}
3214+
3215+
@Override
3216+
public boolean isApplicable() {
3217+
// newer discover this provider automatically
3218+
return false;
3219+
}
3220+
3221+
@Override
3222+
@Nonnull
3223+
public String getProviderName() {
3224+
return "org.apache.maven.shadefire.surefire.junitplatform.JUnitPlatformProvider";
3225+
}
3226+
3227+
@Override
3228+
protected String getProviderArtifactName() {
3229+
return "surefire-shadefire";
3230+
}
3231+
3232+
@Override
3233+
protected void alignProviderVersions(Map<String, Artifact> providerArtifacts) throws MojoExecutionException {
3234+
// shadefire is used as booter we can not provide additional dependencies,
3235+
// so we need add a launcher here
3236+
providerArtifacts.put("org.junit.platform:junit-platform-launcher", null);
3237+
super.alignProviderVersions(providerArtifacts);
3238+
}
3239+
}
3240+
32003241
final class JUnitCoreProviderInfo implements ProviderInfo {
32013242
private final Artifact junitArtifact;
32023243

surefire-its/src/test/java/org/apache/maven/surefire/its/jiras/Surefire2006ShadefireTransformersIT.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,31 @@
1818
*/
1919
package org.apache.maven.surefire.its.jiras;
2020

21+
import org.apache.maven.shared.verifier.VerificationException;
2122
import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase;
2223
import org.junit.Test;
2324

25+
import static org.hamcrest.Matchers.is;
26+
import static org.hamcrest.core.StringContains.containsString;
27+
2428
/**
2529
* Test for shadefire usage
2630
*
2731
* @author Slawomir Jaranowski
2832
*/
2933
public class Surefire2006ShadefireTransformersIT extends SurefireJUnit4IntegrationTestCase {
3034
@Test
31-
public void shadefireShouldBeUsed() {
35+
public void shadefireShouldBeUsed() throws VerificationException {
3236
unpack("surefire-2006-shadefire-transformers")
37+
.debugLogging()
3338
.executeTest()
34-
.assertTestSuiteResults(1, 0, 0, 0)
35-
.verifyTextInLog(
36-
"[INFO] Using configured provider org.apache.maven.shadefire.surefire.junit.JUnit3Provider");
39+
.assertTestSuiteResults(2, 0, 0, 0)
40+
.assertThatLogLine(
41+
containsString(
42+
"[INFO] Using configured provider org.apache.maven.shadefire.surefire.junitplatform.JUnitPlatformProvider"),
43+
is(1))
44+
.assertThatLogLine(containsString("[INFO] Running PojoTest"), is(0))
45+
.assertThatLogLine(containsString("[INFO] Running JUnit4Test"), is(1))
46+
.assertThatLogLine(containsString("[INFO] Running JUnit5Test"), is(1));
3747
}
3848
}

surefire-its/src/test/resources/surefire-2006-shadefire-transformers/pom.xml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,21 @@
3333
<maven.compiler.target>${java.specification.version}</maven.compiler.target>
3434
</properties>
3535

36-
<!-- NOTE: This has no dependencies on JUnit or TestNG, just nothing -->
36+
<!-- shadefire will support JUnit5 an JUnit4 by vintage engine -->
37+
<dependencies>
38+
<dependency>
39+
<groupId>org.junit.jupiter</groupId>
40+
<artifactId>junit-jupiter-api</artifactId>
41+
<version>5.11.0</version>
42+
<scope>test</scope>
43+
</dependency>
44+
<dependency>
45+
<groupId>junit</groupId>
46+
<artifactId>junit</artifactId>
47+
<version>4.13.2</version>
48+
<scope>test</scope>
49+
</dependency>
50+
</dependencies>
3751

3852
<build>
3953
<plugins>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import org.junit.Test;
21+
22+
public class JUnit4Test {
23+
24+
@Test
25+
public void success() {}
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import org.junit.jupiter.api.Test;
21+
22+
public class JUnit5Test {
23+
24+
@Test
25+
public void success() {}
26+
}

surefire-its/src/test/resources/surefire-2006-shadefire-transformers/src/test/java/PojoTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
* under the License.
1818
*/
1919

20+
/**
21+
* This test will be not executed ...
22+
*/
2023
public class PojoTest
2124
{
2225
public void testSuccess()

surefire-shadefire/pom.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
<dependencies>
4545
<dependency>
4646
<groupId>org.apache.maven.surefire</groupId>
47-
<artifactId>surefire-junit3</artifactId>
47+
<artifactId>surefire-junit-platform</artifactId>
4848
<version>${project.version}</version>
4949
<scope>runtime</scope>
5050
</dependency>
@@ -81,8 +81,7 @@
8181
<include>org.apache.maven.surefire:surefire-extensions-spi</include>
8282
<include>org.apache.maven.surefire:surefire-booter</include>
8383
<include>org.apache.maven.surefire:common-java5</include>
84-
<include>org.apache.maven.surefire:common-junit3</include>
85-
<include>org.apache.maven.surefire:surefire-junit3</include>
84+
<include>org.apache.maven.surefire:surefire-junit-platform</include>
8685
</includes>
8786
<excludes>
8887
<!-- with rebuild old shaded artifact is used -->

surefire-shadefire/src/main/resources/META-INF/services/org.apache.maven.surefire.api.provider.SurefireProvider

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616
# specific language governing permissions and limitations
1717
# under the License.
1818
#
19-
org.apache.maven.shadefire.surefire.junit.JUnit3Provider
19+
org.apache.maven.shadefire.surefire.junitplatform.JUnitPlatformProvider

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy