Remove direct junit-platform-launcher dependency
Replace any direct `junit-platform-launcher` dependencies and instead rely on the test runner providing it. Launcher related class are not handled via reflection. This update allows us to workaround SUREFIRE-1679. Closes gh-17517
This commit is contained in:
@@ -21,11 +21,6 @@ import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.platform.engine.discovery.DiscoverySelectors;
|
||||
import org.junit.platform.launcher.Launcher;
|
||||
import org.junit.platform.launcher.LauncherDiscoveryRequest;
|
||||
import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder;
|
||||
import org.junit.platform.launcher.core.LauncherFactory;
|
||||
import org.junit.runners.model.InitializationError;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurationPackage;
|
||||
@@ -33,6 +28,9 @@ import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.domain.EntityScan;
|
||||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
|
||||
import org.springframework.boot.test.autoconfigure.orm.jpa.ExampleEntity;
|
||||
import org.springframework.boot.testsupport.junit.platform.Launcher;
|
||||
import org.springframework.boot.testsupport.junit.platform.LauncherDiscoveryRequest;
|
||||
import org.springframework.boot.testsupport.junit.platform.LauncherDiscoveryRequestBuilder;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
@@ -51,7 +49,7 @@ class ImportsContextCustomizerFactoryWithAutoConfigurationTests {
|
||||
static ApplicationContext contextFromTest;
|
||||
|
||||
@Test
|
||||
void testClassesThatHaveSameAnnotationsShareAContext() throws InitializationError {
|
||||
void testClassesThatHaveSameAnnotationsShareAContext() throws Throwable {
|
||||
executeTests(DataJpaTest1.class);
|
||||
ApplicationContext test1Context = contextFromTest;
|
||||
executeTests(DataJpaTest3.class);
|
||||
@@ -60,7 +58,7 @@ class ImportsContextCustomizerFactoryWithAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testClassesThatOnlyHaveDifferingUnrelatedAnnotationsShareAContext() throws InitializationError {
|
||||
void testClassesThatOnlyHaveDifferingUnrelatedAnnotationsShareAContext() throws Throwable {
|
||||
executeTests(DataJpaTest1.class);
|
||||
ApplicationContext test1Context = contextFromTest;
|
||||
executeTests(DataJpaTest2.class);
|
||||
@@ -69,8 +67,7 @@ class ImportsContextCustomizerFactoryWithAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testClassesThatOnlyHaveDifferingPropertyMappedAnnotationAttributesDoNotShareAContext()
|
||||
throws InitializationError {
|
||||
void testClassesThatOnlyHaveDifferingPropertyMappedAnnotationAttributesDoNotShareAContext() throws Throwable {
|
||||
executeTests(DataJpaTest1.class);
|
||||
ApplicationContext test1Context = contextFromTest;
|
||||
executeTests(DataJpaTest4.class);
|
||||
@@ -78,10 +75,11 @@ class ImportsContextCustomizerFactoryWithAutoConfigurationTests {
|
||||
assertThat(test1Context).isNotSameAs(test2Context);
|
||||
}
|
||||
|
||||
private void executeTests(Class<?> testClass) {
|
||||
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request()
|
||||
private void executeTests(Class<?> testClass) throws Throwable {
|
||||
ClassLoader classLoader = testClass.getClassLoader();
|
||||
LauncherDiscoveryRequest request = new LauncherDiscoveryRequestBuilder(classLoader)
|
||||
.selectors(DiscoverySelectors.selectClass(testClass)).build();
|
||||
Launcher launcher = LauncherFactory.create();
|
||||
Launcher launcher = new Launcher(testClass.getClassLoader());
|
||||
launcher.execute(request);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,16 +19,15 @@ package org.springframework.boot.test.autoconfigure.web.servlet.mockmvc;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junit.platform.engine.discovery.DiscoverySelectors;
|
||||
import org.junit.platform.launcher.Launcher;
|
||||
import org.junit.platform.launcher.LauncherDiscoveryRequest;
|
||||
import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder;
|
||||
import org.junit.platform.launcher.core.LauncherFactory;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.boot.test.system.CapturedOutput;
|
||||
import org.springframework.boot.test.system.OutputCaptureExtension;
|
||||
import org.springframework.boot.testsupport.junit.platform.Launcher;
|
||||
import org.springframework.boot.testsupport.junit.platform.LauncherDiscoveryRequest;
|
||||
import org.springframework.boot.testsupport.junit.platform.LauncherDiscoveryRequestBuilder;
|
||||
import org.springframework.security.test.context.support.WithMockUser;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
@@ -47,21 +46,22 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
class WebMvcTestPrintDefaultIntegrationTests {
|
||||
|
||||
@Test
|
||||
void shouldNotPrint(CapturedOutput output) {
|
||||
void shouldNotPrint(CapturedOutput output) throws Throwable {
|
||||
executeTests(ShouldNotPrint.class);
|
||||
assertThat(output).doesNotContain("HTTP Method");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldPrint(CapturedOutput output) {
|
||||
void shouldPrint(CapturedOutput output) throws Throwable {
|
||||
executeTests(ShouldPrint.class);
|
||||
assertThat(output).contains("HTTP Method");
|
||||
}
|
||||
|
||||
private void executeTests(Class<?> testClass) {
|
||||
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request()
|
||||
private void executeTests(Class<?> testClass) throws Throwable {
|
||||
ClassLoader classLoader = testClass.getClassLoader();
|
||||
LauncherDiscoveryRequest request = new LauncherDiscoveryRequestBuilder(classLoader)
|
||||
.selectors(DiscoverySelectors.selectClass(testClass)).build();
|
||||
Launcher launcher = LauncherFactory.create();
|
||||
Launcher launcher = new Launcher(testClass.getClassLoader());
|
||||
launcher.execute(request);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user