Skip to content

Commit 9bdb205

Browse files
committed
Merge pull request #26632 from dreis2211
* pr/26632: Remove workaround for SUREFIRE-1679 Closes gh-26632
2 parents 004363c + 01ee619 commit 9bdb205

File tree

12 files changed

+42
-334
lines changed

12 files changed

+42
-334
lines changed

spring-boot-project/spring-boot-test-autoconfigure/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ dependencies {
7070
testImplementation("org.hibernate.validator:hibernate-validator")
7171
testImplementation("org.hsqldb:hsqldb")
7272
testImplementation("org.jooq:jooq")
73-
testImplementation("org.junit.platform:junit-platform-engine")
7473
testImplementation("org.junit.jupiter:junit-jupiter")
74+
testImplementation("org.junit.platform:junit-platform-engine")
75+
testImplementation("org.junit.platform:junit-platform-launcher")
7576
testImplementation("org.mockito:mockito-core")
7677
testImplementation("org.skyscreamer:jsonassert")
7778
testImplementation("org.springframework.hateoas:spring-hateoas")

spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/cache/ImportsContextCustomizerFactoryWithAutoConfigurationTests.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,16 +21,17 @@
2121

2222
import org.junit.jupiter.api.Test;
2323
import org.junit.platform.engine.discovery.DiscoverySelectors;
24+
import org.junit.platform.launcher.Launcher;
25+
import org.junit.platform.launcher.LauncherDiscoveryRequest;
26+
import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder;
27+
import org.junit.platform.launcher.core.LauncherFactory;
2428

2529
import org.springframework.beans.factory.annotation.Autowired;
2630
import org.springframework.boot.autoconfigure.AutoConfigurationPackage;
2731
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
2832
import org.springframework.boot.autoconfigure.domain.EntityScan;
2933
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
3034
import org.springframework.boot.test.autoconfigure.orm.jpa.ExampleEntity;
31-
import org.springframework.boot.testsupport.junit.platform.Launcher;
32-
import org.springframework.boot.testsupport.junit.platform.LauncherDiscoveryRequest;
33-
import org.springframework.boot.testsupport.junit.platform.LauncherDiscoveryRequestBuilder;
3435
import org.springframework.context.ApplicationContext;
3536
import org.springframework.context.annotation.Configuration;
3637
import org.springframework.test.context.ContextConfiguration;
@@ -49,7 +50,7 @@ class ImportsContextCustomizerFactoryWithAutoConfigurationTests {
4950
static ApplicationContext contextFromTest;
5051

5152
@Test
52-
void testClassesThatHaveSameAnnotationsShareAContext() throws Throwable {
53+
void testClassesThatHaveSameAnnotationsShareAContext() {
5354
executeTests(DataJpaTest1.class);
5455
ApplicationContext test1Context = contextFromTest;
5556
executeTests(DataJpaTest3.class);
@@ -58,7 +59,7 @@ void testClassesThatHaveSameAnnotationsShareAContext() throws Throwable {
5859
}
5960

6061
@Test
61-
void testClassesThatOnlyHaveDifferingUnrelatedAnnotationsShareAContext() throws Throwable {
62+
void testClassesThatOnlyHaveDifferingUnrelatedAnnotationsShareAContext() {
6263
executeTests(DataJpaTest1.class);
6364
ApplicationContext test1Context = contextFromTest;
6465
executeTests(DataJpaTest2.class);
@@ -67,19 +68,18 @@ void testClassesThatOnlyHaveDifferingUnrelatedAnnotationsShareAContext() throws
6768
}
6869

6970
@Test
70-
void testClassesThatOnlyHaveDifferingPropertyMappedAnnotationAttributesDoNotShareAContext() throws Throwable {
71+
void testClassesThatOnlyHaveDifferingPropertyMappedAnnotationAttributesDoNotShareAContext() {
7172
executeTests(DataJpaTest1.class);
7273
ApplicationContext test1Context = contextFromTest;
7374
executeTests(DataJpaTest4.class);
7475
ApplicationContext test2Context = contextFromTest;
7576
assertThat(test1Context).isNotSameAs(test2Context);
7677
}
7778

78-
private void executeTests(Class<?> testClass) throws Throwable {
79-
ClassLoader classLoader = testClass.getClassLoader();
80-
LauncherDiscoveryRequest request = new LauncherDiscoveryRequestBuilder(classLoader)
79+
private void executeTests(Class<?> testClass) {
80+
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request()
8181
.selectors(DiscoverySelectors.selectClass(testClass)).build();
82-
Launcher launcher = new Launcher(testClass.getClassLoader());
82+
Launcher launcher = LauncherFactory.create();
8383
launcher.execute(request);
8484
}
8585

spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/servlet/mockmvc/WebMvcTestPrintDefaultIntegrationTests.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,15 +21,16 @@
2121
import org.junit.jupiter.api.TestMethodOrder;
2222
import org.junit.jupiter.api.extension.ExtendWith;
2323
import org.junit.platform.engine.discovery.DiscoverySelectors;
24+
import org.junit.platform.launcher.Launcher;
25+
import org.junit.platform.launcher.LauncherDiscoveryRequest;
26+
import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder;
27+
import org.junit.platform.launcher.core.LauncherFactory;
2428

2529
import org.springframework.beans.factory.annotation.Autowired;
2630
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
2731
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
2832
import org.springframework.boot.test.system.CapturedOutput;
2933
import org.springframework.boot.test.system.OutputCaptureExtension;
30-
import org.springframework.boot.testsupport.junit.platform.Launcher;
31-
import org.springframework.boot.testsupport.junit.platform.LauncherDiscoveryRequest;
32-
import org.springframework.boot.testsupport.junit.platform.LauncherDiscoveryRequestBuilder;
3334
import org.springframework.security.test.context.support.WithMockUser;
3435
import org.springframework.test.web.servlet.MockMvc;
3536

@@ -49,22 +50,21 @@
4950
class WebMvcTestPrintDefaultIntegrationTests {
5051

5152
@Test
52-
void shouldNotPrint(CapturedOutput output) throws Throwable {
53+
void shouldNotPrint(CapturedOutput output) {
5354
executeTests(ShouldNotPrint.class);
5455
assertThat(output).doesNotContain("HTTP Method");
5556
}
5657

5758
@Test
58-
void shouldPrint(CapturedOutput output) throws Throwable {
59+
void shouldPrint(CapturedOutput output) {
5960
executeTests(ShouldPrint.class);
6061
assertThat(output).containsOnlyOnce("HTTP Method");
6162
}
6263

63-
private void executeTests(Class<?> testClass) throws Throwable {
64-
ClassLoader classLoader = testClass.getClassLoader();
65-
LauncherDiscoveryRequest request = new LauncherDiscoveryRequestBuilder(classLoader)
64+
private void executeTests(Class<?> testClass) {
65+
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request()
6666
.selectors(DiscoverySelectors.selectClass(testClass)).build();
67-
Launcher launcher = new Launcher(testClass.getClassLoader());
67+
Launcher launcher = LauncherFactory.create();
6868
launcher.execute(request);
6969
}
7070

spring-boot-project/spring-boot-tools/spring-boot-test-support/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ dependencies {
1414
compileOnly("org.elasticsearch:elasticsearch")
1515
compileOnly("org.junit.jupiter:junit-jupiter")
1616
compileOnly("org.junit.platform:junit-platform-engine")
17+
compileOnly("org.junit.platform:junit-platform-launcher")
1718
compileOnly("org.mockito:mockito-core")
1819
compileOnly("org.neo4j:neo4j-ogm-core")
1920
compileOnly("org.springframework:spring-context")

spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/classpath/ModifiedClassPathExtension.java

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,12 +24,16 @@
2424
import org.junit.jupiter.api.extension.InvocationInterceptor;
2525
import org.junit.jupiter.api.extension.ReflectiveInvocationContext;
2626
import org.junit.platform.engine.discovery.DiscoverySelectors;
27+
import org.junit.platform.launcher.Launcher;
28+
import org.junit.platform.launcher.LauncherDiscoveryRequest;
29+
import org.junit.platform.launcher.TestPlan;
30+
import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder;
31+
import org.junit.platform.launcher.core.LauncherFactory;
32+
import org.junit.platform.launcher.listeners.SummaryGeneratingListener;
33+
import org.junit.platform.launcher.listeners.TestExecutionSummary;
2734

28-
import org.springframework.boot.testsupport.junit.platform.Launcher;
29-
import org.springframework.boot.testsupport.junit.platform.LauncherDiscoveryRequest;
30-
import org.springframework.boot.testsupport.junit.platform.LauncherDiscoveryRequestBuilder;
31-
import org.springframework.boot.testsupport.junit.platform.SummaryGeneratingListener;
3235
import org.springframework.util.Assert;
36+
import org.springframework.util.CollectionUtils;
3337
import org.springframework.util.ReflectionUtils;
3438

3539
/**
@@ -94,17 +98,18 @@ private void runTestWithModifiedClassPath(ReflectiveInvocationContext<Method> in
9498
}
9599

96100
private void runTest(ClassLoader classLoader, String testClassName, String testMethodName) throws Throwable {
97-
Class<?> testClass = Class.forName(testClassName, false, classLoader);
101+
Class<?> testClass = classLoader.loadClass(testClassName);
98102
Method testMethod = findMethod(testClass, testMethodName);
99-
LauncherDiscoveryRequest request = new LauncherDiscoveryRequestBuilder(classLoader)
103+
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request()
100104
.selectors(DiscoverySelectors.selectMethod(testClass, testMethod)).build();
101-
Launcher launcher = new Launcher(classLoader);
102-
SummaryGeneratingListener listener = new SummaryGeneratingListener(classLoader);
105+
Launcher launcher = LauncherFactory.create();
106+
TestPlan testPlan = launcher.discover(request);
107+
SummaryGeneratingListener listener = new SummaryGeneratingListener();
103108
launcher.registerTestExecutionListeners(listener);
104-
launcher.execute(request);
105-
Throwable failure = listener.getSummary().getFailure();
106-
if (failure != null) {
107-
throw failure;
109+
launcher.execute(testPlan);
110+
TestExecutionSummary summary = listener.getSummary();
111+
if (!CollectionUtils.isEmpty(summary.getFailures())) {
112+
throw summary.getFailures().get(0).getException();
108113
}
109114
}
110115

spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/junit/platform/Launcher.java

Lines changed: 0 additions & 52 deletions
This file was deleted.

spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/junit/platform/LauncherDiscoveryRequest.java

Lines changed: 0 additions & 34 deletions
This file was deleted.

spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/junit/platform/LauncherDiscoveryRequestBuilder.java

Lines changed: 0 additions & 54 deletions
This file was deleted.

spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/junit/platform/ReflectiveWrapper.java

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)