Skip to content

Commit

Permalink
[SUREFIRE-2157] Upgrade junit-jupiter to 5.9.3/junit-platform to 1.9.2
Browse files Browse the repository at this point in the history
  • Loading branch information
slachiewicz committed Jun 1, 2023
1 parent 9092b5e commit 95e8e95
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 32 deletions.
7 changes: 4 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
<commonsCompress>1.21</commonsCompress>
<commonsIoVersion>2.12.0</commonsIoVersion>
<plexus-java-version>1.1.2</plexus-java-version>
<junit5Version>5.9.3</junit5Version>
<!-- maven-shared-utils:3.3.4 uses org.fusesource.jansi:jansi:2.2.0 -->
<mavenSharedUtilsVersion>3.3.4</mavenSharedUtilsVersion>
<powermockVersion>2.0.9</powermockVersion>
Expand Down Expand Up @@ -240,17 +241,17 @@
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>1.3.2</version>
<version>1.9.2</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.3.2</version>
<version>${junit5Version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.3.2</version>
<version>${junit5Version}</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.apache.maven.surefire.api.util.ReflectionUtils;
import org.junit.platform.launcher.Launcher;
import org.junit.platform.launcher.LauncherDiscoveryListener;
import org.junit.platform.launcher.LauncherDiscoveryRequest;
import org.junit.platform.launcher.TestExecutionListener;
import org.junit.platform.launcher.TestPlan;
Expand All @@ -34,6 +35,11 @@ class LazyLauncher implements Launcher, AutoCloseable {

private Launcher launcher;

@Override
public void registerLauncherDiscoveryListeners(LauncherDiscoveryListener... listeners) {
launcher().registerLauncherDiscoveryListeners(listeners);
}

@Override
public void registerTestExecutionListeners(TestExecutionListener... testExecutionListeners) {
launcher().registerTestExecutionListeners(testExecutionListeners);
Expand All @@ -50,6 +56,11 @@ public void execute(
launcher().execute(launcherDiscoveryRequest, testExecutionListeners);
}

@Override
public void execute(TestPlan testPlan, TestExecutionListener... listeners) {
launcher().execute(testPlan, listeners);
}

private Launcher launcher() {
if (launcher == null) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.DisplayNameGenerator;
import org.junit.jupiter.engine.config.DefaultJupiterConfiguration;
import org.junit.jupiter.engine.config.JupiterConfiguration;
import org.junit.jupiter.engine.descriptor.ClassTestDescriptor;
import org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor;
import org.junit.jupiter.engine.descriptor.TestTemplateTestDescriptor;
Expand Down Expand Up @@ -89,15 +92,15 @@ public class RunListenerAdapterTest {
public void setUp() {
listener = mock(TestReportListener.class);
adapter = new RunListenerAdapter(listener);
adapter.testPlanExecutionStarted(TestPlan.from(emptyList()));
adapter.testPlanExecutionStarted(TestPlan.from(emptyList(), CONFIG_PARAMS));
adapter.setRunMode(NORMAL_RUN);
}

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

TestPlan testPlan = TestPlan.from(singletonList(new EngineDescriptor(newId(), "Luke's Plan")));
TestPlan testPlan = TestPlan.from(singletonList(new EngineDescriptor(newId(), "Luke's Plan")), CONFIG_PARAMS);
adapter.testPlanExecutionStarted(testPlan);

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

TestPlan testPlan = TestPlan.from(singletonList(new EngineDescriptor(newId(), "Luke's Plan")));
TestPlan testPlan = TestPlan.from(singletonList(new EngineDescriptor(newId(), "Luke's Plan")), CONFIG_PARAMS);
adapter.testPlanExecutionStarted(testPlan);

TestIdentifier methodIdentifier =
Expand All @@ -140,7 +143,7 @@ public void notifiedEagerlyForTestSetWhenClassExecutionStarted() throws Exceptio
engine.addChild(parent);
TestDescriptor child = newMethodDescriptor();
parent.addChild(child);
TestPlan plan = TestPlan.from(singletonList(engine));
TestPlan plan = TestPlan.from(singletonList(engine), CONFIG_PARAMS);

String className = MyTestClass.class.getName();

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

UniqueId id2 = parent.getUniqueId().append(MyTestClass.class.getName(), MY_TEST_METHOD_NAME);
Method m2 = MyTestClass.class.getDeclaredMethod(MY_TEST_METHOD_NAME, String.class);
TestDescriptor child2 = new TestMethodTestDescriptor(id2, MyTestClass.class, m2);
TestDescriptor child2 = new TestMethodTestDescriptor(
id2, MyTestClass.class, m2, new DefaultJupiterConfiguration(CONFIG_PARAMS));
parent.addChild(child2);

TestPlan plan = TestPlan.from(singletonList(engine));
TestPlan plan = TestPlan.from(singletonList(engine), CONFIG_PARAMS);

InOrder inOrder = inOrder(listener);

Expand Down Expand Up @@ -291,7 +295,7 @@ public Type getType() {
return TEST;
}
};
TestPlan plan = TestPlan.from(singletonList(engine));
TestPlan plan = TestPlan.from(singletonList(engine), CONFIG_PARAMS);

adapter.testPlanExecutionStarted(plan);
assertThat((TestPlan) getInternalState(adapter, "testPlan")).isSameAs(plan);
Expand Down Expand Up @@ -343,7 +347,7 @@ public void notifiedWithCorrectNamesWhenClassExecutionSkipped() throws Exception
TestDescriptor method2 = newMethodDescriptor();
classTestDescriptor.addChild(method2);
engineDescriptor.addChild(classTestDescriptor);
TestPlan testPlan = TestPlan.from(singletonList(engineDescriptor));
TestPlan testPlan = TestPlan.from(singletonList(engineDescriptor), CONFIG_PARAMS);
adapter.testPlanExecutionStarted(testPlan);

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

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

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

adapter.executionFinished(newContainerIdentifier(), failed(new RuntimeException()));
Expand All @@ -475,7 +479,7 @@ public void notifiedForTestSetWhenClassExecutionSucceeded() {
EngineDescriptor engineDescriptor = newEngineDescriptor();
TestDescriptor classDescriptor = newClassDescriptor();
engineDescriptor.addChild(classDescriptor);
adapter.testPlanExecutionStarted(TestPlan.from(singleton(engineDescriptor)));
adapter.testPlanExecutionStarted(TestPlan.from(singleton(engineDescriptor), CONFIG_PARAMS));
adapter.executionStarted(TestIdentifier.from(classDescriptor));

adapter.executionFinished(TestIdentifier.from(classDescriptor), successful());
Expand Down Expand Up @@ -505,7 +509,7 @@ public void notifiedForTestSetWhenClassExecutionSucceeded() {
@Test
public void notifiedWithParentDisplayNameWhenTestClassUnknown() {
// Set up a test plan
TestPlan plan = TestPlan.from(singletonList(new EngineDescriptor(newId(), "Luke's Plan")));
TestPlan plan = TestPlan.from(singletonList(new EngineDescriptor(newId(), "Luke's Plan")), CONFIG_PARAMS);
adapter.testPlanExecutionStarted(plan);

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

@Test
public void stackTraceWriterPresentWhenParentHasSource() {
TestPlan plan = TestPlan.from(singletonList(new EngineDescriptor(newId(), "Some Plan")));
TestPlan plan = TestPlan.from(singletonList(new EngineDescriptor(newId(), "Some Plan")), CONFIG_PARAMS);
adapter.testPlanExecutionStarted(plan);

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

@Test
public void stackTraceWriterDefaultsToTestClass() {
TestPlan plan = TestPlan.from(singletonList(new EngineDescriptor(newId(), "Some Plan")));
TestPlan plan = TestPlan.from(singletonList(new EngineDescriptor(newId(), "Some Plan")), CONFIG_PARAMS);
adapter.testPlanExecutionStarted(plan);

TestIdentifier child = newSourcelessChildIdentifierWithParent(plan, "Parent", null);
Expand Down Expand Up @@ -589,24 +593,29 @@ private static TestDescriptor newMethodDescriptor(Class<?>... parameterTypes) th
return new TestMethodTestDescriptor(
UniqueId.forEngine("method"),
MyTestClass.class,
MyTestClass.class.getDeclaredMethod(MY_TEST_METHOD_NAME, parameterTypes));
MyTestClass.class.getDeclaredMethod(MY_TEST_METHOD_NAME, parameterTypes),
new DefaultJupiterConfiguration(CONFIG_PARAMS));
}

private static TestIdentifier newClassIdentifier() {
return TestIdentifier.from(newClassDescriptor());
}

private static TestDescriptor newClassDescriptor(String displayName) {
JupiterConfiguration jupiterConfiguration = mock(JupiterConfiguration.class);
DisplayNameGenerator displayNameGenerator = mock(DisplayNameGenerator.class);
when(displayNameGenerator.generateDisplayNameForClass(MyTestClass.class))
.thenReturn(displayName);
when(jupiterConfiguration.getDefaultDisplayNameGenerator()).thenReturn(displayNameGenerator);
return new ClassTestDescriptor(
UniqueId.root("class", MyTestClass.class.getName()),
c -> displayName,
MyTestClass.class,
CONFIG_PARAMS) {};
UniqueId.root("class", MyTestClass.class.getName()), MyTestClass.class, jupiterConfiguration) {};
}

private static TestDescriptor newClassDescriptor() {
return new ClassTestDescriptor(
UniqueId.root("class", MyTestClass.class.getName()), MyTestClass.class, CONFIG_PARAMS);
UniqueId.root("class", MyTestClass.class.getName()),
MyTestClass.class,
new DefaultJupiterConfiguration(CONFIG_PARAMS));
}

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

testPlan.add(childId);
testPlan.add(parentId);
testPlan.addInternal(childId);
testPlan.addInternal(parentId);

return childId;
}
Expand All @@ -641,7 +650,8 @@ private static TestIdentifier newContainerIdentifier() throws Exception {
return TestIdentifier.from(new TestTemplateTestDescriptor(
UniqueId.forEngine("method"),
MyTestClass.class,
MyTestClass.class.getDeclaredMethod(MY_TEST_METHOD_NAME)));
MyTestClass.class.getDeclaredMethod(MY_TEST_METHOD_NAME),
new DefaultJupiterConfiguration(CONFIG_PARAMS)));
}

private static TestIdentifier newEngineIdentifier() {
Expand All @@ -660,15 +670,15 @@ private static TestIdentifier identifiersAsParentOnTestPlan(
TestIdentifier parentIdentifier = TestIdentifier.from(parent);
TestIdentifier childIdentifier = TestIdentifier.from(child);

plan.add(parentIdentifier);
plan.add(childIdentifier);
plan.addInternal(parentIdentifier);
plan.addInternal(childIdentifier);

return childIdentifier;
}

private static TestIdentifier identifiersAsParentOnTestPlan(TestPlan plan, TestDescriptor root) {
TestIdentifier rootIdentifier = TestIdentifier.from(root);
plan.add(rootIdentifier);
plan.addInternal(rootIdentifier);
return rootIdentifier;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import org.apache.maven.surefire.api.testset.TestListResolver;
import org.junit.Test;
import org.junit.jupiter.engine.config.DefaultJupiterConfiguration;
import org.junit.jupiter.engine.descriptor.ClassTestDescriptor;
import org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor;
import org.junit.platform.engine.ConfigurationParameters;
Expand Down Expand Up @@ -78,12 +79,13 @@ private static TestMethodTestDescriptor newTestMethodDescriptor() throws Excepti
UniqueId uniqueId = UniqueId.forEngine("method");
Class<TestClass> testClass = TestClass.class;
Method testMethod = testClass.getMethod("testMethod");
return new TestMethodTestDescriptor(uniqueId, testClass, testMethod);
return new TestMethodTestDescriptor(
uniqueId, testClass, testMethod, new DefaultJupiterConfiguration(CONFIG_PARAMS));
}

private static ClassTestDescriptor newClassTestDescriptor() {
UniqueId uniqueId = UniqueId.forEngine("class");
return new ClassTestDescriptor(uniqueId, TestClass.class, CONFIG_PARAMS);
return new ClassTestDescriptor(uniqueId, TestClass.class, new DefaultJupiterConfiguration(CONFIG_PARAMS));
}

/**
Expand Down

0 comments on commit 95e8e95

Please sign in to comment.