Browse Source

Allow to specify multiple auto-configs in autoConfigFirst

pull/9645/merge
Stephane Nicoll 9 years ago
parent
commit
0fcf6a0e51
  1. 14
      spring-boot-test/src/main/java/org/springframework/boot/test/context/ContextLoader.java
  2. 10
      spring-boot-test/src/test/java/org/springframework/boot/test/rule/ContextLoaderTests.java

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

@ -154,14 +154,16 @@ public class ContextLoader { @@ -154,14 +154,16 @@ public class ContextLoader {
}
/**
* Add the specified auto-configuration at the beginning so that it is
* applied before any other existing auto-configurations, but after any
* user configuration.
* @param autoConfiguration the auto-configuration to add
* Add the specified auto-configurations at the beginning (in that order) so that it
* is applied before any other existing auto-configurations, but after any
* user configuration. If {@code A} and {@code B} are specified, {@code A} will
* be processed, then {@code B} and finally the rest of the existing
* auto-configuration.
* @param autoConfigurations the auto-configuration to add
* @return this instance
*/
public ContextLoader autoConfigFirst(Class<?> autoConfiguration) {
this.autoConfigurations.addFirst(autoConfiguration);
public ContextLoader autoConfigFirst(Class<?>... autoConfigurations) {
this.autoConfigurations.addAll(0, Arrays.asList(autoConfigurations));
return this;
}

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

@ -145,6 +145,16 @@ public class ContextLoaderTests { @@ -145,6 +145,16 @@ public class ContextLoaderTests {
assertThat(context.getBean("a")).isEqualTo("a"));
}
@Test
public void autoConfigureFirstWithSeveralConfigsIsAppliedProperly() {
this.contextLoader.autoConfig(ConfigA.class, ConfigB.class)
.autoConfigFirst(AutoConfigA.class, AutoConfigB.class)
.load(context -> {
assertThat(context.getBean("a")).isEqualTo("a");
assertThat(context.getBean("b")).isEqualTo(1);
});
}
@Test
public void autoConfigurationIsAdditive() {
this.contextLoader.autoConfig(AutoConfigA.class)

Loading…
Cancel
Save