Skip to content

Commit b73d503

Browse files
committed
Merge branch '2.2.x'
2 parents 8f5ef95 + 9bb53a4 commit b73d503

File tree

4 files changed

+24
-17
lines changed

4 files changed

+24
-17
lines changed

spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootContextLoader.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,9 @@ protected ConfigurableEnvironment getEnvironment() {
146146
* @deprecated since 2.2.7
147147
* @see SpringApplication#run(String...)
148148
*/
149+
@Deprecated
149150
protected String[] getArgs(MergedContextConfiguration config) {
150-
ContextCustomizer customizer = config.getContextCustomizers().stream()
151-
.filter((c) -> c instanceof SpringBootTestArgsTrackingContextCustomizer).findFirst().orElse(null);
152-
if (customizer != null) {
153-
return ((SpringBootTestArgsTrackingContextCustomizer) customizer).getArgs();
154-
}
155-
return SpringBootTestArgsTrackingContextCustomizer.NO_ARGS;
151+
return SpringBootTestArgs.get(config.getContextCustomizers());
156152
}
157153

158154
private void setActiveProfiles(ConfigurableEnvironment environment, String[] profiles) {

spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
* @return the application arguments to pass to the application under test.
102102
* @see ApplicationArguments
103103
* @see SpringApplication#run(String...)
104+
* @since 2.2.0
104105
*/
105106
String[] args() default {};
106107

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.boot.test.context;
1818

1919
import java.util.Arrays;
20+
import java.util.Set;
2021

2122
import org.springframework.context.ConfigurableApplicationContext;
2223
import org.springframework.core.annotation.MergedAnnotations;
@@ -31,39 +32,48 @@
3132
*
3233
* @author Madhura Bhave
3334
*/
34-
class SpringBootTestArgsTrackingContextCustomizer implements ContextCustomizer {
35+
class SpringBootTestArgs implements ContextCustomizer {
3536

36-
static final String[] NO_ARGS = new String[0];
37+
private static final String[] NO_ARGS = new String[0];
3738

38-
private String[] args;
39+
private final String[] args;
3940

40-
SpringBootTestArgsTrackingContextCustomizer(Class<?> testClass) {
41+
SpringBootTestArgs(Class<?> testClass) {
4142
this.args = MergedAnnotations.from(testClass, MergedAnnotations.SearchStrategy.TYPE_HIERARCHY)
4243
.get(SpringBootTest.class).getValue("args", String[].class).orElse(NO_ARGS);
4344
}
4445

4546
@Override
4647
public void customizeContext(ConfigurableApplicationContext context, MergedContextConfiguration mergedConfig) {
47-
4848
}
4949

50-
/**
51-
* Return the application arguments that are tracked by this customizer.
52-
* @return the args
53-
*/
5450
String[] getArgs() {
5551
return this.args;
5652
}
5753

5854
@Override
5955
public boolean equals(Object obj) {
6056
return (obj != null) && (getClass() == obj.getClass())
61-
&& Arrays.equals(this.args, ((SpringBootTestArgsTrackingContextCustomizer) obj).args);
57+
&& Arrays.equals(this.args, ((SpringBootTestArgs) obj).args);
6258
}
6359

6460
@Override
6561
public int hashCode() {
6662
return Arrays.hashCode(this.args);
6763
}
6864

65+
/**
66+
* Return the application arguments from the given customizers.
67+
* @param customizers the customizers to check
68+
* @return the application args or an empty array
69+
*/
70+
static String[] get(Set<ContextCustomizer> customizers) {
71+
for (ContextCustomizer customizer : customizers) {
72+
if (customizer instanceof SpringBootTestArgs) {
73+
return ((SpringBootTestArgs) customizer).args;
74+
}
75+
}
76+
return NO_ARGS;
77+
}
78+
6979
}

spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootTestContextBootstrapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ protected final MergedContextConfiguration createModifiedConfig(MergedContextCon
358358
protected final MergedContextConfiguration createModifiedConfig(MergedContextConfiguration mergedConfig,
359359
Class<?>[] classes, String[] propertySourceProperties) {
360360
Set<ContextCustomizer> contextCustomizers = new LinkedHashSet<>(mergedConfig.getContextCustomizers());
361-
contextCustomizers.add(new SpringBootTestArgsTrackingContextCustomizer(mergedConfig.getTestClass()));
361+
contextCustomizers.add(new SpringBootTestArgs(mergedConfig.getTestClass()));
362362
return new MergedContextConfiguration(mergedConfig.getTestClass(), mergedConfig.getLocations(), classes,
363363
mergedConfig.getContextInitializerClasses(), mergedConfig.getActiveProfiles(),
364364
mergedConfig.getPropertySourceLocations(), propertySourceProperties, contextCustomizers,

0 commit comments

Comments
 (0)