This is an automated email from the ASF dual-hosted git repository. slachiewicz pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/maven-surefire.git
commit 95e8e95ee02ee0e12af70850440bd3d4c053d5db Author: Sylwester Lachiewicz <slachiew...@apache.org> AuthorDate: Sat Mar 11 22:34:38 2023 +0100 [SUREFIRE-2157] Upgrade junit-jupiter to 5.9.3/junit-platform to 1.9.2 --- pom.xml | 7 ++- .../maven/surefire/junitplatform/LazyLauncher.java | 11 ++++ .../junitplatform/RunListenerAdapterTest.java | 64 +++++++++++++--------- .../junitplatform/TestMethodFilterTest.java | 6 +- 4 files changed, 56 insertions(+), 32 deletions(-) diff --git a/pom.xml b/pom.xml index 1db582084..9004b0adc 100644 --- a/pom.xml +++ b/pom.xml @@ -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> @@ -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> diff --git a/surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/LazyLauncher.java b/surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/LazyLauncher.java index 76b4a2e75..6d4b00068 100644 --- a/surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/LazyLauncher.java +++ b/surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/LazyLauncher.java @@ -20,6 +20,7 @@ package org.apache.maven.surefire.junitplatform; 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; @@ -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); @@ -50,6 +56,11 @@ class LazyLauncher implements Launcher, AutoCloseable { launcher().execute(launcherDiscoveryRequest, testExecutionListeners); } + @Override + public void execute(TestPlan testPlan, TestExecutionListener... listeners) { + launcher().execute(testPlan, listeners); + } + private Launcher launcher() { if (launcher == null) { try { diff --git a/surefire-providers/surefire-junit-platform/src/test/java/org/apache/maven/surefire/junitplatform/RunListenerAdapterTest.java b/surefire-providers/surefire-junit-platform/src/test/java/org/apache/maven/surefire/junitplatform/RunListenerAdapterTest.java index b6ab26364..b75ac6aa6 100644 --- a/surefire-providers/surefire-junit-platform/src/test/java/org/apache/maven/surefire/junitplatform/RunListenerAdapterTest.java +++ b/surefire-providers/surefire-junit-platform/src/test/java/org/apache/maven/surefire/junitplatform/RunListenerAdapterTest.java @@ -32,6 +32,9 @@ import org.apache.maven.surefire.report.PojoStackTraceWriter; 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; @@ -89,7 +92,7 @@ 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); } @@ -97,7 +100,7 @@ public class RunListenerAdapterTest { 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 = @@ -116,7 +119,7 @@ public class RunListenerAdapterTest { 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 = @@ -140,7 +143,7 @@ public class RunListenerAdapterTest { 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(); @@ -196,10 +199,11 @@ public class RunListenerAdapterTest { 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); @@ -291,7 +295,7 @@ public class RunListenerAdapterTest { 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); @@ -343,7 +347,7 @@ public class RunListenerAdapterTest { 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 = @@ -414,7 +418,7 @@ public class RunListenerAdapterTest { @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( @@ -432,7 +436,7 @@ public class RunListenerAdapterTest { @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( @@ -450,7 +454,7 @@ public class RunListenerAdapterTest { @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())); @@ -475,7 +479,7 @@ public class RunListenerAdapterTest { 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()); @@ -505,7 +509,7 @@ public class RunListenerAdapterTest { @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. @@ -525,7 +529,7 @@ public class RunListenerAdapterTest { @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 = @@ -538,7 +542,7 @@ public class RunListenerAdapterTest { @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); @@ -589,7 +593,8 @@ public class RunListenerAdapterTest { 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() { @@ -597,16 +602,20 @@ public class RunListenerAdapterTest { } 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( @@ -631,8 +640,8 @@ public class RunListenerAdapterTest { 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; } @@ -641,7 +650,8 @@ public class RunListenerAdapterTest { 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() { @@ -660,15 +670,15 @@ public class RunListenerAdapterTest { 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; } diff --git a/surefire-providers/surefire-junit-platform/src/test/java/org/apache/maven/surefire/junitplatform/TestMethodFilterTest.java b/surefire-providers/surefire-junit-platform/src/test/java/org/apache/maven/surefire/junitplatform/TestMethodFilterTest.java index 18b81e502..aa1b80a40 100644 --- a/surefire-providers/surefire-junit-platform/src/test/java/org/apache/maven/surefire/junitplatform/TestMethodFilterTest.java +++ b/surefire-providers/surefire-junit-platform/src/test/java/org/apache/maven/surefire/junitplatform/TestMethodFilterTest.java @@ -22,6 +22,7 @@ import java.lang.reflect.Method; 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; @@ -78,12 +79,13 @@ public class TestMethodFilterTest { 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)); } /**