Skip to content

Commit 95e8e95

Browse files
committed
[SUREFIRE-2157] Upgrade junit-jupiter to 5.9.3/junit-platform to 1.9.2
1 parent 9092b5e commit 95e8e95

File tree

4 files changed

+56
-32
lines changed

4 files changed

+56
-32
lines changed

pom.xml

+4-3
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
<commonsCompress>1.21</commonsCompress>
9494
<commonsIoVersion>2.12.0</commonsIoVersion>
9595
<plexus-java-version>1.1.2</plexus-java-version>
96+
<junit5Version>5.9.3</junit5Version>
9697
<!-- maven-shared-utils:3.3.4 uses org.fusesource.jansi:jansi:2.2.0 -->
9798
<mavenSharedUtilsVersion>3.3.4</mavenSharedUtilsVersion>
9899
<powermockVersion>2.0.9</powermockVersion>
@@ -240,17 +241,17 @@
240241
<dependency>
241242
<groupId>org.junit.platform</groupId>
242243
<artifactId>junit-platform-launcher</artifactId>
243-
<version>1.3.2</version>
244+
<version>1.9.2</version>
244245
</dependency>
245246
<dependency>
246247
<groupId>org.junit.jupiter</groupId>
247248
<artifactId>junit-jupiter-engine</artifactId>
248-
<version>5.3.2</version>
249+
<version>${junit5Version}</version>
249250
</dependency>
250251
<dependency>
251252
<groupId>org.junit.jupiter</groupId>
252253
<artifactId>junit-jupiter-params</artifactId>
253-
<version>5.3.2</version>
254+
<version>${junit5Version}</version>
254255
</dependency>
255256
<dependency>
256257
<groupId>org.mockito</groupId>

surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/LazyLauncher.java

+11
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import org.apache.maven.surefire.api.util.ReflectionUtils;
2222
import org.junit.platform.launcher.Launcher;
23+
import org.junit.platform.launcher.LauncherDiscoveryListener;
2324
import org.junit.platform.launcher.LauncherDiscoveryRequest;
2425
import org.junit.platform.launcher.TestExecutionListener;
2526
import org.junit.platform.launcher.TestPlan;
@@ -34,6 +35,11 @@ class LazyLauncher implements Launcher, AutoCloseable {
3435

3536
private Launcher launcher;
3637

38+
@Override
39+
public void registerLauncherDiscoveryListeners(LauncherDiscoveryListener... listeners) {
40+
launcher().registerLauncherDiscoveryListeners(listeners);
41+
}
42+
3743
@Override
3844
public void registerTestExecutionListeners(TestExecutionListener... testExecutionListeners) {
3945
launcher().registerTestExecutionListeners(testExecutionListeners);
@@ -50,6 +56,11 @@ public void execute(
5056
launcher().execute(launcherDiscoveryRequest, testExecutionListeners);
5157
}
5258

59+
@Override
60+
public void execute(TestPlan testPlan, TestExecutionListener... listeners) {
61+
launcher().execute(testPlan, listeners);
62+
}
63+
5364
private Launcher launcher() {
5465
if (launcher == null) {
5566
try {

surefire-providers/surefire-junit-platform/src/test/java/org/apache/maven/surefire/junitplatform/RunListenerAdapterTest.java

+37-27
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
import org.junit.Before;
3333
import org.junit.Test;
3434
import org.junit.jupiter.api.DisplayName;
35+
import org.junit.jupiter.api.DisplayNameGenerator;
36+
import org.junit.jupiter.engine.config.DefaultJupiterConfiguration;
37+
import org.junit.jupiter.engine.config.JupiterConfiguration;
3538
import org.junit.jupiter.engine.descriptor.ClassTestDescriptor;
3639
import org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor;
3740
import org.junit.jupiter.engine.descriptor.TestTemplateTestDescriptor;
@@ -89,15 +92,15 @@ public class RunListenerAdapterTest {
8992
public void setUp() {
9093
listener = mock(TestReportListener.class);
9194
adapter = new RunListenerAdapter(listener);
92-
adapter.testPlanExecutionStarted(TestPlan.from(emptyList()));
95+
adapter.testPlanExecutionStarted(TestPlan.from(emptyList(), CONFIG_PARAMS));
9396
adapter.setRunMode(NORMAL_RUN);
9497
}
9598

9699
@Test
97100
public void notifiedWithCorrectNamesWhenMethodExecutionStarted() throws Exception {
98101
ArgumentCaptor<ReportEntry> entryCaptor = ArgumentCaptor.forClass(ReportEntry.class);
99102

100-
TestPlan testPlan = TestPlan.from(singletonList(new EngineDescriptor(newId(), "Luke's Plan")));
103+
TestPlan testPlan = TestPlan.from(singletonList(new EngineDescriptor(newId(), "Luke's Plan")), CONFIG_PARAMS);
101104
adapter.testPlanExecutionStarted(testPlan);
102105

103106
TestIdentifier methodIdentifier =
@@ -116,7 +119,7 @@ public void notifiedWithCorrectNamesWhenMethodExecutionStarted() throws Exceptio
116119
public void notifiedWithCompatibleNameForMethodWithArguments() throws Exception {
117120
ArgumentCaptor<ReportEntry> entryCaptor = ArgumentCaptor.forClass(ReportEntry.class);
118121

119-
TestPlan testPlan = TestPlan.from(singletonList(new EngineDescriptor(newId(), "Luke's Plan")));
122+
TestPlan testPlan = TestPlan.from(singletonList(new EngineDescriptor(newId(), "Luke's Plan")), CONFIG_PARAMS);
120123
adapter.testPlanExecutionStarted(testPlan);
121124

122125
TestIdentifier methodIdentifier =
@@ -140,7 +143,7 @@ public void notifiedEagerlyForTestSetWhenClassExecutionStarted() throws Exceptio
140143
engine.addChild(parent);
141144
TestDescriptor child = newMethodDescriptor();
142145
parent.addChild(child);
143-
TestPlan plan = TestPlan.from(singletonList(engine));
146+
TestPlan plan = TestPlan.from(singletonList(engine), CONFIG_PARAMS);
144147

145148
String className = MyTestClass.class.getName();
146149

@@ -196,10 +199,11 @@ public void displayNamesInClassAndMethods() throws Exception {
196199

197200
UniqueId id2 = parent.getUniqueId().append(MyTestClass.class.getName(), MY_TEST_METHOD_NAME);
198201
Method m2 = MyTestClass.class.getDeclaredMethod(MY_TEST_METHOD_NAME, String.class);
199-
TestDescriptor child2 = new TestMethodTestDescriptor(id2, MyTestClass.class, m2);
202+
TestDescriptor child2 = new TestMethodTestDescriptor(
203+
id2, MyTestClass.class, m2, new DefaultJupiterConfiguration(CONFIG_PARAMS));
200204
parent.addChild(child2);
201205

202-
TestPlan plan = TestPlan.from(singletonList(engine));
206+
TestPlan plan = TestPlan.from(singletonList(engine), CONFIG_PARAMS);
203207

204208
InOrder inOrder = inOrder(listener);
205209

@@ -291,7 +295,7 @@ public Type getType() {
291295
return TEST;
292296
}
293297
};
294-
TestPlan plan = TestPlan.from(singletonList(engine));
298+
TestPlan plan = TestPlan.from(singletonList(engine), CONFIG_PARAMS);
295299

296300
adapter.testPlanExecutionStarted(plan);
297301
assertThat((TestPlan) getInternalState(adapter, "testPlan")).isSameAs(plan);
@@ -343,7 +347,7 @@ public void notifiedWithCorrectNamesWhenClassExecutionSkipped() throws Exception
343347
TestDescriptor method2 = newMethodDescriptor();
344348
classTestDescriptor.addChild(method2);
345349
engineDescriptor.addChild(classTestDescriptor);
346-
TestPlan testPlan = TestPlan.from(singletonList(engineDescriptor));
350+
TestPlan testPlan = TestPlan.from(singletonList(engineDescriptor), CONFIG_PARAMS);
347351
adapter.testPlanExecutionStarted(testPlan);
348352

349353
TestIdentifier classIdentifier =
@@ -414,7 +418,7 @@ public void notifiedWhenMethodExecutionFailedWithError() throws Exception {
414418
@Test
415419
public void notifiedWithCorrectNamesWhenClassExecutionFailed() {
416420
ArgumentCaptor<ReportEntry> entryCaptor = ArgumentCaptor.forClass(ReportEntry.class);
417-
TestPlan testPlan = TestPlan.from(singletonList(new EngineDescriptor(newId(), "Luke's Plan")));
421+
TestPlan testPlan = TestPlan.from(singletonList(new EngineDescriptor(newId(), "Luke's Plan")), CONFIG_PARAMS);
418422
adapter.testPlanExecutionStarted(testPlan);
419423

420424
adapter.executionFinished(
@@ -432,7 +436,7 @@ public void notifiedWithCorrectNamesWhenClassExecutionFailed() {
432436
@Test
433437
public void notifiedWithCorrectNamesWhenClassExecutionErrored() {
434438
ArgumentCaptor<ReportEntry> entryCaptor = ArgumentCaptor.forClass(ReportEntry.class);
435-
TestPlan testPlan = TestPlan.from(singletonList(new EngineDescriptor(newId(), "Luke's Plan")));
439+
TestPlan testPlan = TestPlan.from(singletonList(new EngineDescriptor(newId(), "Luke's Plan")), CONFIG_PARAMS);
436440
adapter.testPlanExecutionStarted(testPlan);
437441

438442
adapter.executionFinished(
@@ -450,7 +454,7 @@ public void notifiedWithCorrectNamesWhenClassExecutionErrored() {
450454
@Test
451455
public void notifiedWithCorrectNamesWhenContainerFailed() throws Exception {
452456
ArgumentCaptor<ReportEntry> entryCaptor = ArgumentCaptor.forClass(ReportEntry.class);
453-
TestPlan testPlan = TestPlan.from(singletonList(new EngineDescriptor(newId(), "Luke's Plan")));
457+
TestPlan testPlan = TestPlan.from(singletonList(new EngineDescriptor(newId(), "Luke's Plan")), CONFIG_PARAMS);
454458
adapter.testPlanExecutionStarted(testPlan);
455459

456460
adapter.executionFinished(newContainerIdentifier(), failed(new RuntimeException()));
@@ -475,7 +479,7 @@ public void notifiedForTestSetWhenClassExecutionSucceeded() {
475479
EngineDescriptor engineDescriptor = newEngineDescriptor();
476480
TestDescriptor classDescriptor = newClassDescriptor();
477481
engineDescriptor.addChild(classDescriptor);
478-
adapter.testPlanExecutionStarted(TestPlan.from(singleton(engineDescriptor)));
482+
adapter.testPlanExecutionStarted(TestPlan.from(singleton(engineDescriptor), CONFIG_PARAMS));
479483
adapter.executionStarted(TestIdentifier.from(classDescriptor));
480484

481485
adapter.executionFinished(TestIdentifier.from(classDescriptor), successful());
@@ -505,7 +509,7 @@ public void notifiedForTestSetWhenClassExecutionSucceeded() {
505509
@Test
506510
public void notifiedWithParentDisplayNameWhenTestClassUnknown() {
507511
// Set up a test plan
508-
TestPlan plan = TestPlan.from(singletonList(new EngineDescriptor(newId(), "Luke's Plan")));
512+
TestPlan plan = TestPlan.from(singletonList(new EngineDescriptor(newId(), "Luke's Plan")), CONFIG_PARAMS);
509513
adapter.testPlanExecutionStarted(plan);
510514

511515
// Use the test plan to set up child with parent.
@@ -525,7 +529,7 @@ public void notifiedWithParentDisplayNameWhenTestClassUnknown() {
525529

526530
@Test
527531
public void stackTraceWriterPresentWhenParentHasSource() {
528-
TestPlan plan = TestPlan.from(singletonList(new EngineDescriptor(newId(), "Some Plan")));
532+
TestPlan plan = TestPlan.from(singletonList(new EngineDescriptor(newId(), "Some Plan")), CONFIG_PARAMS);
529533
adapter.testPlanExecutionStarted(plan);
530534

531535
TestIdentifier child =
@@ -538,7 +542,7 @@ public void stackTraceWriterPresentWhenParentHasSource() {
538542

539543
@Test
540544
public void stackTraceWriterDefaultsToTestClass() {
541-
TestPlan plan = TestPlan.from(singletonList(new EngineDescriptor(newId(), "Some Plan")));
545+
TestPlan plan = TestPlan.from(singletonList(new EngineDescriptor(newId(), "Some Plan")), CONFIG_PARAMS);
542546
adapter.testPlanExecutionStarted(plan);
543547

544548
TestIdentifier child = newSourcelessChildIdentifierWithParent(plan, "Parent", null);
@@ -589,24 +593,29 @@ private static TestDescriptor newMethodDescriptor(Class<?>... parameterTypes) th
589593
return new TestMethodTestDescriptor(
590594
UniqueId.forEngine("method"),
591595
MyTestClass.class,
592-
MyTestClass.class.getDeclaredMethod(MY_TEST_METHOD_NAME, parameterTypes));
596+
MyTestClass.class.getDeclaredMethod(MY_TEST_METHOD_NAME, parameterTypes),
597+
new DefaultJupiterConfiguration(CONFIG_PARAMS));
593598
}
594599

595600
private static TestIdentifier newClassIdentifier() {
596601
return TestIdentifier.from(newClassDescriptor());
597602
}
598603

599604
private static TestDescriptor newClassDescriptor(String displayName) {
605+
JupiterConfiguration jupiterConfiguration = mock(JupiterConfiguration.class);
606+
DisplayNameGenerator displayNameGenerator = mock(DisplayNameGenerator.class);
607+
when(displayNameGenerator.generateDisplayNameForClass(MyTestClass.class))
608+
.thenReturn(displayName);
609+
when(jupiterConfiguration.getDefaultDisplayNameGenerator()).thenReturn(displayNameGenerator);
600610
return new ClassTestDescriptor(
601-
UniqueId.root("class", MyTestClass.class.getName()),
602-
c -> displayName,
603-
MyTestClass.class,
604-
CONFIG_PARAMS) {};
611+
UniqueId.root("class", MyTestClass.class.getName()), MyTestClass.class, jupiterConfiguration) {};
605612
}
606613

607614
private static TestDescriptor newClassDescriptor() {
608615
return new ClassTestDescriptor(
609-
UniqueId.root("class", MyTestClass.class.getName()), MyTestClass.class, CONFIG_PARAMS);
616+
UniqueId.root("class", MyTestClass.class.getName()),
617+
MyTestClass.class,
618+
new DefaultJupiterConfiguration(CONFIG_PARAMS));
610619
}
611620

612621
private static TestIdentifier newSourcelessChildIdentifierWithParent(
@@ -631,8 +640,8 @@ private static TestIdentifier newSourcelessChildIdentifierWithParent(
631640
when(child.getParent()).thenReturn(Optional.of(parent));
632641
TestIdentifier childId = TestIdentifier.from(child);
633642

634-
testPlan.add(childId);
635-
testPlan.add(parentId);
643+
testPlan.addInternal(childId);
644+
testPlan.addInternal(parentId);
636645

637646
return childId;
638647
}
@@ -641,7 +650,8 @@ private static TestIdentifier newContainerIdentifier() throws Exception {
641650
return TestIdentifier.from(new TestTemplateTestDescriptor(
642651
UniqueId.forEngine("method"),
643652
MyTestClass.class,
644-
MyTestClass.class.getDeclaredMethod(MY_TEST_METHOD_NAME)));
653+
MyTestClass.class.getDeclaredMethod(MY_TEST_METHOD_NAME),
654+
new DefaultJupiterConfiguration(CONFIG_PARAMS)));
645655
}
646656

647657
private static TestIdentifier newEngineIdentifier() {
@@ -660,15 +670,15 @@ private static TestIdentifier identifiersAsParentOnTestPlan(
660670
TestIdentifier parentIdentifier = TestIdentifier.from(parent);
661671
TestIdentifier childIdentifier = TestIdentifier.from(child);
662672

663-
plan.add(parentIdentifier);
664-
plan.add(childIdentifier);
673+
plan.addInternal(parentIdentifier);
674+
plan.addInternal(childIdentifier);
665675

666676
return childIdentifier;
667677
}
668678

669679
private static TestIdentifier identifiersAsParentOnTestPlan(TestPlan plan, TestDescriptor root) {
670680
TestIdentifier rootIdentifier = TestIdentifier.from(root);
671-
plan.add(rootIdentifier);
681+
plan.addInternal(rootIdentifier);
672682
return rootIdentifier;
673683
}
674684

surefire-providers/surefire-junit-platform/src/test/java/org/apache/maven/surefire/junitplatform/TestMethodFilterTest.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import org.apache.maven.surefire.api.testset.TestListResolver;
2424
import org.junit.Test;
25+
import org.junit.jupiter.engine.config.DefaultJupiterConfiguration;
2526
import org.junit.jupiter.engine.descriptor.ClassTestDescriptor;
2627
import org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor;
2728
import org.junit.platform.engine.ConfigurationParameters;
@@ -78,12 +79,13 @@ private static TestMethodTestDescriptor newTestMethodDescriptor() throws Excepti
7879
UniqueId uniqueId = UniqueId.forEngine("method");
7980
Class<TestClass> testClass = TestClass.class;
8081
Method testMethod = testClass.getMethod("testMethod");
81-
return new TestMethodTestDescriptor(uniqueId, testClass, testMethod);
82+
return new TestMethodTestDescriptor(
83+
uniqueId, testClass, testMethod, new DefaultJupiterConfiguration(CONFIG_PARAMS));
8284
}
8385

8486
private static ClassTestDescriptor newClassTestDescriptor() {
8587
UniqueId uniqueId = UniqueId.forEngine("class");
86-
return new ClassTestDescriptor(uniqueId, TestClass.class, CONFIG_PARAMS);
88+
return new ClassTestDescriptor(uniqueId, TestClass.class, new DefaultJupiterConfiguration(CONFIG_PARAMS));
8789
}
8890

8991
/**

0 commit comments

Comments
 (0)