Skip to content

Commit 7c0f397

Browse files
committed
Merge branch '2.6.x' into 2.7.x
See gh-33015
2 parents e44b114 + ac6ad7c commit 7c0f397

File tree

3 files changed

+56
-22
lines changed

3 files changed

+56
-22
lines changed

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

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@
3232
import org.junit.platform.launcher.listeners.SummaryGeneratingListener;
3333
import org.junit.platform.launcher.listeners.TestExecutionSummary;
3434

35-
import org.springframework.util.Assert;
3635
import org.springframework.util.CollectionUtils;
37-
import org.springframework.util.ReflectionUtils;
3836

3937
/**
4038
* A custom {@link Extension} that runs tests using a modified class path. Entries are
@@ -102,18 +100,16 @@ private void interceptMethod(Invocation<Void> invocation, ReflectiveInvocationCo
102100
ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
103101
Thread.currentThread().setContextClassLoader(modifiedClassLoader);
104102
try {
105-
runTest(modifiedClassLoader, testClass.getName(), testMethod.getName());
103+
runTest(extensionContext.getUniqueId());
106104
}
107105
finally {
108106
Thread.currentThread().setContextClassLoader(originalClassLoader);
109107
}
110108
}
111109

112-
private void runTest(ClassLoader classLoader, String testClassName, String testMethodName) throws Throwable {
113-
Class<?> testClass = classLoader.loadClass(testClassName);
114-
Method testMethod = findMethod(testClass, testMethodName);
110+
private void runTest(String testId) throws Throwable {
115111
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request()
116-
.selectors(DiscoverySelectors.selectMethod(testClass, testMethod)).build();
112+
.selectors(DiscoverySelectors.selectUniqueId(testId)).build();
117113
Launcher launcher = LauncherFactory.create();
118114
TestPlan testPlan = launcher.discover(request);
119115
SummaryGeneratingListener listener = new SummaryGeneratingListener();
@@ -125,20 +121,6 @@ private void runTest(ClassLoader classLoader, String testClassName, String testM
125121
}
126122
}
127123

128-
private Method findMethod(Class<?> testClass, String testMethodName) {
129-
Method method = ReflectionUtils.findMethod(testClass, testMethodName);
130-
if (method == null) {
131-
Method[] methods = ReflectionUtils.getUniqueDeclaredMethods(testClass);
132-
for (Method candidate : methods) {
133-
if (candidate.getName().equals(testMethodName)) {
134-
return candidate;
135-
}
136-
}
137-
}
138-
Assert.state(method != null, () -> "Unable to find " + testClass + "." + testMethodName);
139-
return method;
140-
}
141-
142124
private void intercept(Invocation<Void> invocation, ExtensionContext extensionContext) throws Throwable {
143125
if (isModifiedClassPathClassLoader(extensionContext)) {
144126
invocation.proceed();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2012-2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.testsupport.classpath;
18+
19+
import java.util.ArrayList;
20+
import java.util.List;
21+
22+
import org.junit.jupiter.params.ParameterizedTest;
23+
import org.junit.jupiter.params.provider.CsvSource;
24+
25+
import static org.assertj.core.api.Assertions.assertThat;
26+
27+
/**
28+
* Tests for {@link ForkedClassPath @ForkedClassPath}.
29+
*
30+
* @author Andy Wilkinson
31+
*/
32+
@ForkedClassPath
33+
class ModifiedClassPathExtensionForkParameterizedTests {
34+
35+
private static final List<String> arguments = new ArrayList<>();
36+
37+
@ParameterizedTest
38+
@CsvSource({ "one", "two", "three" })
39+
void testIsInvokedOnceForEachArgument(String argument) {
40+
if (argument.equals("one")) {
41+
assertThat(arguments).isEmpty();
42+
}
43+
else if (argument.equals("two")) {
44+
assertThat(arguments).doesNotContain("two", "three");
45+
}
46+
else if (argument.equals("three")) {
47+
assertThat(arguments).doesNotContain("three");
48+
}
49+
arguments.add(argument);
50+
}
51+
52+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
*
3333
* @author Phillip Webb
3434
*/
35-
class ModifiedClassPathExtensionOverridesParametrizedTests {
35+
class ModifiedClassPathExtensionOverridesParameterizedTests {
3636

3737
@ParameterizedTest
3838
@ForkedClassPath

0 commit comments

Comments
 (0)