Skip to content

Commit 0fcf6a0

Browse files
committed
Allow to specify multiple auto-configs in autoConfigFirst
1 parent f2fe2c4 commit 0fcf6a0

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,16 @@ public ContextLoader autoConfig(Class<?>... autoConfigurations) {
154154
}
155155

156156
/**
157-
* Add the specified auto-configuration at the beginning so that it is
158-
* applied before any other existing auto-configurations, but after any
159-
* user configuration.
160-
* @param autoConfiguration the auto-configuration to add
157+
* Add the specified auto-configurations at the beginning (in that order) so that it
158+
* is applied before any other existing auto-configurations, but after any
159+
* user configuration. If {@code A} and {@code B} are specified, {@code A} will
160+
* be processed, then {@code B} and finally the rest of the existing
161+
* auto-configuration.
162+
* @param autoConfigurations the auto-configuration to add
161163
* @return this instance
162164
*/
163-
public ContextLoader autoConfigFirst(Class<?> autoConfiguration) {
164-
this.autoConfigurations.addFirst(autoConfiguration);
165+
public ContextLoader autoConfigFirst(Class<?>... autoConfigurations) {
166+
this.autoConfigurations.addAll(0, Arrays.asList(autoConfigurations));
165167
return this;
166168
}
167169

spring-boot-test/src/test/java/org/springframework/boot/test/rule/ContextLoaderTests.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,16 @@ public void autoConfigureFirstIsAppliedProperly() {
145145
assertThat(context.getBean("a")).isEqualTo("a"));
146146
}
147147

148+
@Test
149+
public void autoConfigureFirstWithSeveralConfigsIsAppliedProperly() {
150+
this.contextLoader.autoConfig(ConfigA.class, ConfigB.class)
151+
.autoConfigFirst(AutoConfigA.class, AutoConfigB.class)
152+
.load(context -> {
153+
assertThat(context.getBean("a")).isEqualTo("a");
154+
assertThat(context.getBean("b")).isEqualTo(1);
155+
});
156+
}
157+
148158
@Test
149159
public void autoConfigurationIsAdditive() {
150160
this.contextLoader.autoConfig(AutoConfigA.class)

0 commit comments

Comments
 (0)