Commit 6823c2ad authored by Phillip Webb's avatar Phillip Webb

Merge branch 'gh-9875'

Closes gh-9875
parents 56169156 89ad0660
...@@ -93,7 +93,7 @@ public class MixedNeo4jRepositoriesAutoConfigurationTests { ...@@ -93,7 +93,7 @@ public class MixedNeo4jRepositoriesAutoConfigurationTests {
private void load(Class<?> config, String... environment) { private void load(Class<?> config, String... environment) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
TestPropertyValues.of(environment).and("spring.datasource.initialize", "false") TestPropertyValues.of(environment).and("spring.datasource.initialize=false")
.applyTo(context); .applyTo(context);
context.register(config); context.register(config);
context.register(DataSourceAutoConfiguration.class, context.register(DataSourceAutoConfiguration.class,
......
...@@ -29,7 +29,7 @@ import org.springframework.boot.autoconfigure.data.neo4j.city.City; ...@@ -29,7 +29,7 @@ import org.springframework.boot.autoconfigure.data.neo4j.city.City;
import org.springframework.boot.autoconfigure.data.neo4j.country.Country; import org.springframework.boot.autoconfigure.data.neo4j.country.Country;
import org.springframework.boot.autoconfigure.domain.EntityScan; import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration; import org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration;
import org.springframework.boot.test.context.WebApplicationContextTester; import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -54,30 +54,31 @@ import static org.mockito.Mockito.verify; ...@@ -54,30 +54,31 @@ import static org.mockito.Mockito.verify;
*/ */
public class Neo4jDataAutoConfigurationTests { public class Neo4jDataAutoConfigurationTests {
private WebApplicationContextTester context = new WebApplicationContextTester() private WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
.withUserConfiguration(TestConfiguration.class) .withUserConfiguration(TestConfiguration.class)
.withConfiguration(AutoConfigurations.of(Neo4jDataAutoConfiguration.class, .withConfiguration(AutoConfigurations.of(Neo4jDataAutoConfiguration.class,
TransactionAutoConfiguration.class)); TransactionAutoConfiguration.class));
@Test @Test
public void defaultConfiguration() { public void defaultConfiguration() {
this.context.withPropertyValues("spring.data.neo4j.uri=http://localhost:8989") this.contextRunner
.run((loaded) -> { .withPropertyValues("spring.data.neo4j.uri=http://localhost:8989")
assertThat(loaded) .run((context) -> {
assertThat(context)
.hasSingleBean(org.neo4j.ogm.config.Configuration.class); .hasSingleBean(org.neo4j.ogm.config.Configuration.class);
assertThat(loaded).hasSingleBean(SessionFactory.class); assertThat(context).hasSingleBean(SessionFactory.class);
assertThat(loaded).hasSingleBean(Neo4jTransactionManager.class); assertThat(context).hasSingleBean(Neo4jTransactionManager.class);
assertThat(loaded).hasSingleBean(OpenSessionInViewInterceptor.class); assertThat(context).hasSingleBean(OpenSessionInViewInterceptor.class);
}); });
} }
@Test @Test
public void customNeo4jTransactionManagerUsingProperties() { public void customNeo4jTransactionManagerUsingProperties() {
this.context this.contextRunner
.withPropertyValues("spring.transaction.default-timeout=30", .withPropertyValues("spring.transaction.default-timeout=30",
"spring.transaction.rollback-on-commit-failure:true") "spring.transaction.rollback-on-commit-failure:true")
.run((loaded) -> { .run((context) -> {
Neo4jTransactionManager transactionManager = loaded Neo4jTransactionManager transactionManager = context
.getBean(Neo4jTransactionManager.class); .getBean(Neo4jTransactionManager.class);
assertThat(transactionManager.getDefaultTimeout()).isEqualTo(30); assertThat(transactionManager.getDefaultTimeout()).isEqualTo(30);
assertThat(transactionManager.isRollbackOnCommitFailure()).isTrue(); assertThat(transactionManager.isRollbackOnCommitFailure()).isTrue();
...@@ -86,20 +87,24 @@ public class Neo4jDataAutoConfigurationTests { ...@@ -86,20 +87,24 @@ public class Neo4jDataAutoConfigurationTests {
@Test @Test
public void customSessionFactory() { public void customSessionFactory() {
this.context.withUserConfiguration(CustomSessionFactory.class).run((loaded) -> { this.contextRunner.withUserConfiguration(CustomSessionFactory.class)
assertThat(loaded).doesNotHaveBean(org.neo4j.ogm.config.Configuration.class); .run((context) -> {
assertThat(loaded).hasSingleBean(SessionFactory.class); assertThat(context)
}); .doesNotHaveBean(org.neo4j.ogm.config.Configuration.class);
assertThat(context).hasSingleBean(SessionFactory.class);
});
} }
@Test @Test
public void customConfiguration() { public void customConfiguration() {
this.context.withUserConfiguration(CustomConfiguration.class).run((loaded) -> { this.contextRunner.withUserConfiguration(CustomConfiguration.class)
assertThat(loaded.getBean(org.neo4j.ogm.config.Configuration.class)) .run((context) -> {
.isSameAs(loaded.getBean("myConfiguration")); assertThat(context.getBean(org.neo4j.ogm.config.Configuration.class))
assertThat(loaded).hasSingleBean(SessionFactory.class); .isSameAs(context.getBean("myConfiguration"));
assertThat(loaded).hasSingleBean(org.neo4j.ogm.config.Configuration.class); assertThat(context).hasSingleBean(SessionFactory.class);
}); assertThat(context)
.hasSingleBean(org.neo4j.ogm.config.Configuration.class);
});
} }
...@@ -122,21 +127,21 @@ public class Neo4jDataAutoConfigurationTests { ...@@ -122,21 +127,21 @@ public class Neo4jDataAutoConfigurationTests {
@Test @Test
public void openSessionInViewInterceptorCanBeDisabled() { public void openSessionInViewInterceptorCanBeDisabled() {
this.context.withPropertyValues("spring.data.neo4j.open-in-view:false") this.contextRunner.withPropertyValues("spring.data.neo4j.open-in-view:false")
.run((loaded) -> assertThat(loaded) .run((context) -> assertThat(context)
.doesNotHaveBean(OpenSessionInViewInterceptor.class)); .doesNotHaveBean(OpenSessionInViewInterceptor.class));
} }
@Test @Test
public void eventListenersAreAutoRegistered() { public void eventListenersAreAutoRegistered() {
this.context.withUserConfiguration(EventListenerConfiguration.class) this.contextRunner.withUserConfiguration(EventListenerConfiguration.class)
.run((loaded) -> { .run((context) -> {
Session session = loaded.getBean(SessionFactory.class).openSession(); Session session = context.getBean(SessionFactory.class).openSession();
session.notifyListeners( session.notifyListeners(
new PersistenceEvent(null, Event.TYPE.PRE_SAVE)); new PersistenceEvent(null, Event.TYPE.PRE_SAVE));
verify(loaded.getBean("eventListenerOne", EventListener.class)) verify(context.getBean("eventListenerOne", EventListener.class))
.onPreSave(any(Event.class)); .onPreSave(any(Event.class));
verify(loaded.getBean("eventListenerTwo", EventListener.class)) verify(context.getBean("eventListenerTwo", EventListener.class))
.onPreSave(any(Event.class)); .onPreSave(any(Event.class));
}); });
} }
......
...@@ -30,7 +30,7 @@ import org.junit.Test; ...@@ -30,7 +30,7 @@ import org.junit.Test;
import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.BeanCreationException;
import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.ApplicationContextTester; import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -61,17 +61,17 @@ public class HazelcastAutoConfigurationClientTests { ...@@ -61,17 +61,17 @@ public class HazelcastAutoConfigurationClientTests {
} }
} }
private final ApplicationContextTester context = new ApplicationContextTester() private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(HazelcastAutoConfiguration.class)); .withConfiguration(AutoConfigurations.of(HazelcastAutoConfiguration.class));
@Test @Test
public void systemProperty() throws IOException { public void systemProperty() throws IOException {
this.context this.contextRunner
.withSystemProperties(HazelcastClientConfiguration.CONFIG_SYSTEM_PROPERTY .withSystemProperties(HazelcastClientConfiguration.CONFIG_SYSTEM_PROPERTY
+ "=classpath:org/springframework/boot/autoconfigure/hazelcast/" + "=classpath:org/springframework/boot/autoconfigure/hazelcast/"
+ "hazelcast-client-specific.xml") + "hazelcast-client-specific.xml")
.run((loaded) -> { .run((context) -> {
assertThat(loaded).getBean(HazelcastInstance.class) assertThat(context).getBean(HazelcastInstance.class)
.isInstanceOf(HazelcastInstance.class) .isInstanceOf(HazelcastInstance.class)
.has(nameStartingWith("hz.client_")); .has(nameStartingWith("hz.client_"));
}); });
...@@ -79,12 +79,12 @@ public class HazelcastAutoConfigurationClientTests { ...@@ -79,12 +79,12 @@ public class HazelcastAutoConfigurationClientTests {
@Test @Test
public void explicitConfigFile() throws IOException { public void explicitConfigFile() throws IOException {
this.context this.contextRunner
.withPropertyValues( .withPropertyValues(
"spring.hazelcast.config=org/springframework/boot/autoconfigure/" "spring.hazelcast.config=org/springframework/boot/autoconfigure/"
+ "hazelcast/hazelcast-client-specific.xml") + "hazelcast/hazelcast-client-specific.xml")
.run((loaded) -> { .run((context) -> {
assertThat(loaded).getBean(HazelcastInstance.class) assertThat(context).getBean(HazelcastInstance.class)
.isInstanceOf(HazelcastClientProxy.class) .isInstanceOf(HazelcastClientProxy.class)
.has(nameStartingWith("hz.client_")); .has(nameStartingWith("hz.client_"));
}); });
...@@ -92,11 +92,11 @@ public class HazelcastAutoConfigurationClientTests { ...@@ -92,11 +92,11 @@ public class HazelcastAutoConfigurationClientTests {
@Test @Test
public void explicitConfigUrl() throws IOException { public void explicitConfigUrl() throws IOException {
this.context this.contextRunner
.withPropertyValues( .withPropertyValues(
"spring.hazelcast.config=hazelcast-client-default.xml") "spring.hazelcast.config=hazelcast-client-default.xml")
.run((loaded) -> { .run((context) -> {
assertThat(loaded).getBean(HazelcastInstance.class) assertThat(context).getBean(HazelcastInstance.class)
.isInstanceOf(HazelcastClientProxy.class) .isInstanceOf(HazelcastClientProxy.class)
.has(nameStartingWith("hz.client_")); .has(nameStartingWith("hz.client_"));
}); });
...@@ -104,9 +104,10 @@ public class HazelcastAutoConfigurationClientTests { ...@@ -104,9 +104,10 @@ public class HazelcastAutoConfigurationClientTests {
@Test @Test
public void unknownConfigFile() { public void unknownConfigFile() {
this.context.withPropertyValues("spring.hazelcast.config=foo/bar/unknown.xml") this.contextRunner
.run((loaded) -> { .withPropertyValues("spring.hazelcast.config=foo/bar/unknown.xml")
assertThat(loaded).getFailure() .run((context) -> {
assertThat(context).getFailure()
.isInstanceOf(BeanCreationException.class) .isInstanceOf(BeanCreationException.class)
.hasMessageContaining("foo/bar/unknown.xml"); .hasMessageContaining("foo/bar/unknown.xml");
}); });
...@@ -114,10 +115,10 @@ public class HazelcastAutoConfigurationClientTests { ...@@ -114,10 +115,10 @@ public class HazelcastAutoConfigurationClientTests {
@Test @Test
public void clientConfigTakesPrecedence() { public void clientConfigTakesPrecedence() {
this.context.withUserConfiguration(HazelcastServerAndClientConfig.class) this.contextRunner.withUserConfiguration(HazelcastServerAndClientConfig.class)
.withPropertyValues("spring.hazelcast.config=this-is-ignored.xml") .withPropertyValues("spring.hazelcast.config=this-is-ignored.xml")
.run((loaded) -> { .run((context) -> {
assertThat(loaded).getBean(HazelcastInstance.class) assertThat(context).getBean(HazelcastInstance.class)
.isInstanceOf(HazelcastClientProxy.class); .isInstanceOf(HazelcastClientProxy.class);
}); });
} }
......
...@@ -28,7 +28,7 @@ import org.junit.runner.RunWith; ...@@ -28,7 +28,7 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.BeanCreationException;
import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.ApplicationContextTester; import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.boot.testsupport.runner.classpath.ClassPathExclusions; import org.springframework.boot.testsupport.runner.classpath.ClassPathExclusions;
import org.springframework.boot.testsupport.runner.classpath.ModifiedClassPathRunner; import org.springframework.boot.testsupport.runner.classpath.ModifiedClassPathRunner;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
...@@ -46,14 +46,14 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -46,14 +46,14 @@ import static org.assertj.core.api.Assertions.assertThat;
@ClassPathExclusions("hazelcast-client-*.jar") @ClassPathExclusions("hazelcast-client-*.jar")
public class HazelcastAutoConfigurationServerTests { public class HazelcastAutoConfigurationServerTests {
private final ApplicationContextTester context = new ApplicationContextTester() private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(HazelcastAutoConfiguration.class)); .withConfiguration(AutoConfigurations.of(HazelcastAutoConfiguration.class));
@Test @Test
public void defaultConfigFile() throws IOException { public void defaultConfigFile() throws IOException {
// hazelcast.xml present in root classpath // hazelcast.xml present in root classpath
this.context.run((loaded) -> { this.contextRunner.run((context) -> {
Config config = loaded.getBean(HazelcastInstance.class).getConfig(); Config config = context.getBean(HazelcastInstance.class).getConfig();
assertThat(config.getConfigurationUrl()) assertThat(config.getConfigurationUrl())
.isEqualTo(new ClassPathResource("hazelcast.xml").getURL()); .isEqualTo(new ClassPathResource("hazelcast.xml").getURL());
}); });
...@@ -61,22 +61,22 @@ public class HazelcastAutoConfigurationServerTests { ...@@ -61,22 +61,22 @@ public class HazelcastAutoConfigurationServerTests {
@Test @Test
public void systemProperty() throws IOException { public void systemProperty() throws IOException {
this.context this.contextRunner
.withSystemProperties(HazelcastServerConfiguration.CONFIG_SYSTEM_PROPERTY .withSystemProperties(HazelcastServerConfiguration.CONFIG_SYSTEM_PROPERTY
+ "=classpath:org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.xml") + "=classpath:org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.xml")
.run((loaded) -> { .run((context) -> {
Config config = loaded.getBean(HazelcastInstance.class).getConfig(); Config config = context.getBean(HazelcastInstance.class).getConfig();
assertThat(config.getQueueConfigs().keySet()).containsOnly("foobar"); assertThat(config.getQueueConfigs().keySet()).containsOnly("foobar");
}); });
} }
@Test @Test
public void explicitConfigFile() throws IOException { public void explicitConfigFile() throws IOException {
this.context.withPropertyValues( this.contextRunner.withPropertyValues(
"spring.hazelcast.config=org/springframework/boot/autoconfigure/hazelcast/" "spring.hazelcast.config=org/springframework/boot/autoconfigure/hazelcast/"
+ "hazelcast-specific.xml") + "hazelcast-specific.xml")
.run((loaded) -> { .run((context) -> {
Config config = loaded.getBean(HazelcastInstance.class).getConfig(); Config config = context.getBean(HazelcastInstance.class).getConfig();
assertThat(config.getConfigurationFile()) assertThat(config.getConfigurationFile())
.isEqualTo(new ClassPathResource( .isEqualTo(new ClassPathResource(
"org/springframework/boot/autoconfigure/hazelcast" "org/springframework/boot/autoconfigure/hazelcast"
...@@ -86,9 +86,10 @@ public class HazelcastAutoConfigurationServerTests { ...@@ -86,9 +86,10 @@ public class HazelcastAutoConfigurationServerTests {
@Test @Test
public void explicitConfigUrl() throws IOException { public void explicitConfigUrl() throws IOException {
this.context.withPropertyValues("spring.hazelcast.config=hazelcast-default.xml") this.contextRunner
.run((loaded) -> { .withPropertyValues("spring.hazelcast.config=hazelcast-default.xml")
Config config = loaded.getBean(HazelcastInstance.class).getConfig(); .run((context) -> {
Config config = context.getBean(HazelcastInstance.class).getConfig();
assertThat(config.getConfigurationUrl()).isEqualTo( assertThat(config.getConfigurationUrl()).isEqualTo(
new ClassPathResource("hazelcast-default.xml").getURL()); new ClassPathResource("hazelcast-default.xml").getURL());
}); });
...@@ -96,9 +97,10 @@ public class HazelcastAutoConfigurationServerTests { ...@@ -96,9 +97,10 @@ public class HazelcastAutoConfigurationServerTests {
@Test @Test
public void unknownConfigFile() { public void unknownConfigFile() {
this.context.withPropertyValues("spring.hazelcast.config=foo/bar/unknown.xml") this.contextRunner
.run((loaded) -> { .withPropertyValues("spring.hazelcast.config=foo/bar/unknown.xml")
assertThat(loaded).getFailure() .run((context) -> {
assertThat(context).getFailure()
.isInstanceOf(BeanCreationException.class) .isInstanceOf(BeanCreationException.class)
.hasMessageContaining("foo/bar/unknown.xml"); .hasMessageContaining("foo/bar/unknown.xml");
}); });
...@@ -109,10 +111,10 @@ public class HazelcastAutoConfigurationServerTests { ...@@ -109,10 +111,10 @@ public class HazelcastAutoConfigurationServerTests {
Config config = new Config("my-test-instance"); Config config = new Config("my-test-instance");
HazelcastInstance existing = Hazelcast.newHazelcastInstance(config); HazelcastInstance existing = Hazelcast.newHazelcastInstance(config);
try { try {
this.context.withUserConfiguration(HazelcastConfigWithName.class) this.contextRunner.withUserConfiguration(HazelcastConfigWithName.class)
.withPropertyValues("spring.hazelcast.config=this-is-ignored.xml") .withPropertyValues("spring.hazelcast.config=this-is-ignored.xml")
.run(loaded -> { .run((context) -> {
HazelcastInstance hazelcast = (loaded) HazelcastInstance hazelcast = context
.getBean(HazelcastInstance.class); .getBean(HazelcastInstance.class);
assertThat(hazelcast.getConfig().getInstanceName()) assertThat(hazelcast.getConfig().getInstanceName())
.isEqualTo("my-test-instance"); .isEqualTo("my-test-instance");
...@@ -127,10 +129,10 @@ public class HazelcastAutoConfigurationServerTests { ...@@ -127,10 +129,10 @@ public class HazelcastAutoConfigurationServerTests {
@Test @Test
public void configInstanceWithoutName() { public void configInstanceWithoutName() {
this.context.withUserConfiguration(HazelcastConfigNoName.class) this.contextRunner.withUserConfiguration(HazelcastConfigNoName.class)
.withPropertyValues("spring.hazelcast.config=this-is-ignored.xml") .withPropertyValues("spring.hazelcast.config=this-is-ignored.xml")
.run((loaded) -> { .run((context) -> {
Config config = loaded.getBean(HazelcastInstance.class).getConfig(); Config config = context.getBean(HazelcastInstance.class).getConfig();
Map<String, QueueConfig> queueConfigs = config.getQueueConfigs(); Map<String, QueueConfig> queueConfigs = config.getQueueConfigs();
assertThat(queueConfigs.keySet()).containsOnly("another-queue"); assertThat(queueConfigs.keySet()).containsOnly("another-queue");
}); });
......
...@@ -23,7 +23,7 @@ import com.hazelcast.core.HazelcastInstance; ...@@ -23,7 +23,7 @@ import com.hazelcast.core.HazelcastInstance;
import org.junit.Test; import org.junit.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.ApplicationContextTester; import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
...@@ -35,14 +35,14 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -35,14 +35,14 @@ import static org.assertj.core.api.Assertions.assertThat;
*/ */
public class HazelcastAutoConfigurationTests { public class HazelcastAutoConfigurationTests {
private final ApplicationContextTester context = new ApplicationContextTester() private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(HazelcastAutoConfiguration.class)); .withConfiguration(AutoConfigurations.of(HazelcastAutoConfiguration.class));
@Test @Test
public void defaultConfigFile() throws IOException { public void defaultConfigFile() throws IOException {
// no hazelcast-client.xml and hazelcast.xml is present in root classpath // no hazelcast-client.xml and hazelcast.xml is present in root classpath
this.context.run((loaded) -> { this.contextRunner.run((context) -> {
Config config = loaded.getBean(HazelcastInstance.class).getConfig(); Config config = context.getBean(HazelcastInstance.class).getConfig();
assertThat(config.getConfigurationUrl()) assertThat(config.getConfigurationUrl())
.isEqualTo(new ClassPathResource("hazelcast.xml").getURL()); .isEqualTo(new ClassPathResource("hazelcast.xml").getURL());
}); });
......
...@@ -25,8 +25,8 @@ import retrofit2.Retrofit; ...@@ -25,8 +25,8 @@ import retrofit2.Retrofit;
import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.DirectFieldAccessor;
import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.ApplicationContextTester; import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
import org.springframework.boot.test.context.AssertableApplicationContext; import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -41,59 +41,60 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -41,59 +41,60 @@ import static org.assertj.core.api.Assertions.assertThat;
*/ */
public class InfluxDbAutoConfigurationTests { public class InfluxDbAutoConfigurationTests {
private final ApplicationContextTester context = new ApplicationContextTester() private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(InfluxDbAutoConfiguration.class)); .withConfiguration(AutoConfigurations.of(InfluxDbAutoConfiguration.class));
@Test @Test
public void influxDbRequiresUrl() { public void influxDbRequiresUrl() {
this.context.run( this.contextRunner
(loaded) -> assertThat(loaded.getBeansOfType(InfluxDB.class)).isEmpty()); .run((context) -> assertThat(context.getBeansOfType(InfluxDB.class))
.isEmpty());
} }
@Test @Test
public void influxDbCanBeCustomized() { public void influxDbCanBeCustomized() {
this.context this.contextRunner
.withPropertyValues("spring.influx.url=http://localhost", .withPropertyValues("spring.influx.url=http://localhost",
"spring.influx.password:password", "spring.influx.user:user") "spring.influx.password:password", "spring.influx.user:user")
.run((loaded -> assertThat(loaded.getBeansOfType(InfluxDB.class)) .run(((context) -> assertThat(context.getBeansOfType(InfluxDB.class))
.hasSize(1))); .hasSize(1)));
} }
@Test @Test
public void influxDbCanBeCreatedWithoutCredentials() { public void influxDbCanBeCreatedWithoutCredentials() {
this.context.withPropertyValues("spring.influx.url=http://localhost") this.contextRunner.withPropertyValues("spring.influx.url=http://localhost")
.run((loaded) -> { .run((context) -> {
assertThat(loaded.getBeansOfType(InfluxDB.class)).hasSize(1); assertThat(context.getBeansOfType(InfluxDB.class)).hasSize(1);
int readTimeout = getReadTimeoutProperty(loaded); int readTimeout = getReadTimeoutProperty(context);
assertThat(readTimeout).isEqualTo(10_000); assertThat(readTimeout).isEqualTo(10_000);
}); });
} }
@Test @Test
public void influxDbWithoutCredentialsAndOkHttpClientBuilder() { public void influxDbWithoutCredentialsAndOkHttpClientBuilder() {
this.context.withUserConfiguration(CustomOkHttpClientBuilderConfig.class) this.contextRunner.withUserConfiguration(CustomOkHttpClientBuilderConfig.class)
.withPropertyValues("spring.influx.url=http://localhost") .withPropertyValues("spring.influx.url=http://localhost")
.run((loaded) -> { .run((context) -> {
assertThat(loaded.getBeansOfType(InfluxDB.class)).hasSize(1); assertThat(context.getBeansOfType(InfluxDB.class)).hasSize(1);
int readTimeout = getReadTimeoutProperty(loaded); int readTimeout = getReadTimeoutProperty(context);
assertThat(readTimeout).isEqualTo(30_000); assertThat(readTimeout).isEqualTo(30_000);
}); });
} }
@Test @Test
public void influxDbWithOkHttpClientBuilder() { public void influxDbWithOkHttpClientBuilder() {
this.context.withUserConfiguration(CustomOkHttpClientBuilderConfig.class) this.contextRunner.withUserConfiguration(CustomOkHttpClientBuilderConfig.class)
.withPropertyValues("spring.influx.url=http://localhost", .withPropertyValues("spring.influx.url=http://localhost",
"spring.influx.password:password", "spring.influx.user:user") "spring.influx.password:password", "spring.influx.user:user")
.run((loaded) -> { .run((context) -> {
assertThat(loaded.getBeansOfType(InfluxDB.class)).hasSize(1); assertThat(context.getBeansOfType(InfluxDB.class)).hasSize(1);
int readTimeout = getReadTimeoutProperty(loaded); int readTimeout = getReadTimeoutProperty(context);
assertThat(readTimeout).isEqualTo(30_000); assertThat(readTimeout).isEqualTo(30_000);
}); });
} }
private int getReadTimeoutProperty(AssertableApplicationContext loaded) { private int getReadTimeoutProperty(AssertableApplicationContext context) {
InfluxDB influxDB = loaded.getBean(InfluxDB.class); InfluxDB influxDB = context.getBean(InfluxDB.class);
Retrofit retrofit = (Retrofit) new DirectFieldAccessor(influxDB) Retrofit retrofit = (Retrofit) new DirectFieldAccessor(influxDB)
.getPropertyValue("retrofit"); .getPropertyValue("retrofit");
OkHttpClient callFactory = (OkHttpClient) new DirectFieldAccessor(retrofit) OkHttpClient callFactory = (OkHttpClient) new DirectFieldAccessor(retrofit)
......
...@@ -39,9 +39,9 @@ import org.springframework.beans.factory.BeanCreationException; ...@@ -39,9 +39,9 @@ import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.jdbc.DatabaseDriver; import org.springframework.boot.jdbc.DatabaseDriver;
import org.springframework.boot.test.context.ApplicationContextTester;
import org.springframework.boot.test.context.AssertableApplicationContext;
import org.springframework.boot.test.context.HidePackagesClassLoader; import org.springframework.boot.test.context.HidePackagesClassLoader;
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
...@@ -58,7 +58,7 @@ import static org.mockito.Mockito.mock; ...@@ -58,7 +58,7 @@ import static org.mockito.Mockito.mock;
*/ */
public class DataSourceAutoConfigurationTests { public class DataSourceAutoConfigurationTests {
private final ApplicationContextTester context = new ApplicationContextTester() private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(DataSourceAutoConfiguration.class)) .withConfiguration(AutoConfigurations.of(DataSourceAutoConfiguration.class))
.withPropertyValues("spring.datasource.initialize=false", .withPropertyValues("spring.datasource.initialize=false",
"spring.datasource.url:jdbc:hsqldb:mem:testdb-" "spring.datasource.url:jdbc:hsqldb:mem:testdb-"
...@@ -66,13 +66,14 @@ public class DataSourceAutoConfigurationTests { ...@@ -66,13 +66,14 @@ public class DataSourceAutoConfigurationTests {
@Test @Test
public void testDefaultDataSourceExists() throws Exception { public void testDefaultDataSourceExists() throws Exception {
this.context.run((loaded) -> assertThat(loaded).hasSingleBean(DataSource.class)); this.contextRunner
.run((context) -> assertThat(context).hasSingleBean(DataSource.class));
} }
@Test @Test
public void testDataSourceHasEmbeddedDefault() throws Exception { public void testDataSourceHasEmbeddedDefault() throws Exception {
this.context.run((loaded) -> { this.contextRunner.run((context) -> {
HikariDataSource dataSource = loaded.getBean(HikariDataSource.class); HikariDataSource dataSource = context.getBean(HikariDataSource.class);
assertThat(dataSource.getJdbcUrl()).isNotNull(); assertThat(dataSource.getJdbcUrl()).isNotNull();
assertThat(dataSource.getDriverClassName()).isNotNull(); assertThat(dataSource.getDriverClassName()).isNotNull();
}); });
...@@ -82,10 +83,10 @@ public class DataSourceAutoConfigurationTests { ...@@ -82,10 +83,10 @@ public class DataSourceAutoConfigurationTests {
public void testBadUrl() throws Exception { public void testBadUrl() throws Exception {
try { try {
EmbeddedDatabaseConnection.override = EmbeddedDatabaseConnection.NONE; EmbeddedDatabaseConnection.override = EmbeddedDatabaseConnection.NONE;
this.context this.contextRunner
.withPropertyValues("spring.datasource.url:jdbc:not-going-to-work") .withPropertyValues("spring.datasource.url:jdbc:not-going-to-work")
.run((loaded) -> { .run((context) -> {
assertThat(loaded).getFailure() assertThat(context).getFailure()
.isInstanceOf(BeanCreationException.class); .isInstanceOf(BeanCreationException.class);
}); });
} }
...@@ -96,11 +97,11 @@ public class DataSourceAutoConfigurationTests { ...@@ -96,11 +97,11 @@ public class DataSourceAutoConfigurationTests {
@Test @Test
public void testBadDriverClass() throws Exception { public void testBadDriverClass() throws Exception {
this.context this.contextRunner
.withPropertyValues( .withPropertyValues(
"spring.datasource.driverClassName:org.none.jdbcDriver") "spring.datasource.driverClassName:org.none.jdbcDriver")
.run((loaded) -> { .run((context) -> {
assertThat(loaded).getFailure() assertThat(context).getFailure()
.isInstanceOf(BeanCreationException.class) .isInstanceOf(BeanCreationException.class)
.hasMessageContaining("org.none.jdbcDriver"); .hasMessageContaining("org.none.jdbcDriver");
}); });
...@@ -153,10 +154,10 @@ public class DataSourceAutoConfigurationTests { ...@@ -153,10 +154,10 @@ public class DataSourceAutoConfigurationTests {
@Test @Test
@SuppressWarnings("resource") @SuppressWarnings("resource")
public void testEmbeddedTypeDefaultsUsername() throws Exception { public void testEmbeddedTypeDefaultsUsername() throws Exception {
this.context.withPropertyValues( this.contextRunner.withPropertyValues(
"spring.datasource.driverClassName:org.hsqldb.jdbcDriver", "spring.datasource.driverClassName:org.hsqldb.jdbcDriver",
"spring.datasource.url:jdbc:hsqldb:mem:testdb").run((loaded) -> { "spring.datasource.url:jdbc:hsqldb:mem:testdb").run((context) -> {
DataSource bean = loaded.getBean(DataSource.class); DataSource bean = context.getBean(DataSource.class);
HikariDataSource pool = (HikariDataSource) bean; HikariDataSource pool = (HikariDataSource) bean;
assertThat(pool.getDriverClassName()) assertThat(pool.getDriverClassName())
.isEqualTo("org.hsqldb.jdbcDriver"); .isEqualTo("org.hsqldb.jdbcDriver");
...@@ -170,7 +171,7 @@ public class DataSourceAutoConfigurationTests { ...@@ -170,7 +171,7 @@ public class DataSourceAutoConfigurationTests {
*/ */
@Test @Test
public void explicitTypeNoSupportedDataSource() { public void explicitTypeNoSupportedDataSource() {
this.context this.contextRunner
.withClassLoader(new HidePackagesClassLoader("org.apache.tomcat", .withClassLoader(new HidePackagesClassLoader("org.apache.tomcat",
"com.zaxxer.hikari", "org.apache.commons.dbcp", "com.zaxxer.hikari", "org.apache.commons.dbcp",
"org.apache.commons.dbcp2")) "org.apache.commons.dbcp2"))
...@@ -184,7 +185,7 @@ public class DataSourceAutoConfigurationTests { ...@@ -184,7 +185,7 @@ public class DataSourceAutoConfigurationTests {
@Test @Test
public void explicitTypeSupportedDataSource() { public void explicitTypeSupportedDataSource() {
this.context this.contextRunner
.withPropertyValues( .withPropertyValues(
"spring.datasource.driverClassName:org.hsqldb.jdbcDriver", "spring.datasource.driverClassName:org.hsqldb.jdbcDriver",
"spring.datasource.url:jdbc:hsqldb:mem:testdb", "spring.datasource.url:jdbc:hsqldb:mem:testdb",
...@@ -193,19 +194,20 @@ public class DataSourceAutoConfigurationTests { ...@@ -193,19 +194,20 @@ public class DataSourceAutoConfigurationTests {
.run(this::containsOnlySimpleDriverDataSource); .run(this::containsOnlySimpleDriverDataSource);
} }
private void containsOnlySimpleDriverDataSource(AssertableApplicationContext loaded) { private void containsOnlySimpleDriverDataSource(
assertThat(loaded).hasSingleBean(DataSource.class); AssertableApplicationContext context) {
assertThat(loaded).getBean(DataSource.class) assertThat(context).hasSingleBean(DataSource.class);
assertThat(context).getBean(DataSource.class)
.isExactlyInstanceOf(SimpleDriverDataSource.class); .isExactlyInstanceOf(SimpleDriverDataSource.class);
} }
@Test @Test
public void testExplicitDriverClassClearsUsername() throws Exception { public void testExplicitDriverClassClearsUsername() throws Exception {
this.context.withPropertyValues( this.contextRunner.withPropertyValues(
"spring.datasource.driverClassName:" + DatabaseTestDriver.class.getName(), "spring.datasource.driverClassName:" + DatabaseTestDriver.class.getName(),
"spring.datasource.url:jdbc:foo://localhost").run((loaded) -> { "spring.datasource.url:jdbc:foo://localhost").run((context) -> {
assertThat(loaded).hasSingleBean(DataSource.class); assertThat(context).hasSingleBean(DataSource.class);
HikariDataSource dataSource = loaded.getBean(HikariDataSource.class); HikariDataSource dataSource = context.getBean(HikariDataSource.class);
assertThat(dataSource.getDriverClassName()) assertThat(dataSource.getDriverClassName())
.isEqualTo(DatabaseTestDriver.class.getName()); .isEqualTo(DatabaseTestDriver.class.getName());
assertThat(dataSource.getUsername()).isNull(); assertThat(dataSource.getUsername()).isNull();
...@@ -214,18 +216,19 @@ public class DataSourceAutoConfigurationTests { ...@@ -214,18 +216,19 @@ public class DataSourceAutoConfigurationTests {
@Test @Test
public void testDefaultDataSourceCanBeOverridden() throws Exception { public void testDefaultDataSourceCanBeOverridden() throws Exception {
this.context.withUserConfiguration(TestDataSourceConfiguration.class) this.contextRunner.withUserConfiguration(TestDataSourceConfiguration.class)
.run((loaded) -> { .run((context) -> {
assertThat(loaded).getBean(DataSource.class) assertThat(context).getBean(DataSource.class)
.isInstanceOf(BasicDataSource.class); .isInstanceOf(BasicDataSource.class);
}); });
} }
@Test @Test
public void testDataSourceIsInitializedEarly() { public void testDataSourceIsInitializedEarly() {
this.context.withUserConfiguration(TestInitializedDataSourceConfiguration.class) this.contextRunner
.withUserConfiguration(TestInitializedDataSourceConfiguration.class)
.withPropertyValues("spring.datasource.initialize=true") .withPropertyValues("spring.datasource.initialize=true")
.run((loaded) -> assertThat(loaded .run((context) -> assertThat(context
.getBean(TestInitializedDataSourceConfiguration.class).called) .getBean(TestInitializedDataSourceConfiguration.class).called)
.isTrue()); .isTrue());
} }
...@@ -234,8 +237,8 @@ public class DataSourceAutoConfigurationTests { ...@@ -234,8 +237,8 @@ public class DataSourceAutoConfigurationTests {
List<String> hiddenPackages, Consumer<T> consumer) { List<String> hiddenPackages, Consumer<T> consumer) {
HidePackagesClassLoader classLoader = new HidePackagesClassLoader( HidePackagesClassLoader classLoader = new HidePackagesClassLoader(
hiddenPackages.toArray(new String[hiddenPackages.size()])); hiddenPackages.toArray(new String[hiddenPackages.size()]));
this.context.withClassLoader(classLoader).run((loaded) -> { this.contextRunner.withClassLoader(classLoader).run((context) -> {
DataSource bean = loaded.getBean(DataSource.class); DataSource bean = context.getBean(DataSource.class);
assertThat(bean).isInstanceOf(expectedType); assertThat(bean).isInstanceOf(expectedType);
consumer.accept(expectedType.cast(bean)); consumer.accept(expectedType.cast(bean));
}); });
......
...@@ -130,7 +130,7 @@ public class DataSourceJmxConfigurationTests { ...@@ -130,7 +130,7 @@ public class DataSourceJmxConfigurationTests {
private void load(Class<?> config, String... environment) { private void load(Class<?> config, String... environment) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
String jdbcUrl = "jdbc:hsqldb:mem:test-" + UUID.randomUUID().toString(); String jdbcUrl = "jdbc:hsqldb:mem:test-" + UUID.randomUUID().toString();
TestPropertyValues.of(environment).and("spring.datasource.url", jdbcUrl) TestPropertyValues.of(environment).and("spring.datasource.url=" + jdbcUrl)
.applyTo(context); .applyTo(context);
if (config != null) { if (config != null) {
context.register(config); context.register(config);
......
...@@ -104,8 +104,8 @@ public class HikariDataSourceConfigurationTests { ...@@ -104,8 +104,8 @@ public class HikariDataSourceConfigurationTests {
private void load(String... environment) { private void load(String... environment) {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
TestPropertyValues.of(environment).and("spring.datasource.initialize", "false") TestPropertyValues.of(environment).and("spring.datasource.initialize=false")
.and("spring.datasource.type", HikariDataSource.class.getName()) .and("spring.datasource.type=" + HikariDataSource.class.getName())
.applyTo(ctx); .applyTo(ctx);
ctx.register(DataSourceAutoConfiguration.class); ctx.register(DataSourceAutoConfiguration.class);
ctx.refresh(); ctx.refresh();
......
...@@ -25,7 +25,7 @@ import org.junit.Test; ...@@ -25,7 +25,7 @@ import org.junit.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration; import org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration;
import org.springframework.boot.test.context.ApplicationContextTester; import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -42,36 +42,39 @@ import static org.mockito.Mockito.mockingDetails; ...@@ -42,36 +42,39 @@ import static org.mockito.Mockito.mockingDetails;
*/ */
public class ActiveMQAutoConfigurationTests { public class ActiveMQAutoConfigurationTests {
private final ApplicationContextTester context = new ApplicationContextTester() private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(ActiveMQAutoConfiguration.class, .withConfiguration(AutoConfigurations.of(ActiveMQAutoConfiguration.class,
JmsAutoConfiguration.class)); JmsAutoConfiguration.class));
@Test @Test
public void brokerIsEmbeddedByDefault() { public void brokerIsEmbeddedByDefault() {
this.context.withUserConfiguration(EmptyConfiguration.class).run((loaded) -> { this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
assertThat(loaded).getBean(ConnectionFactory.class) .run((context) -> {
.isInstanceOf(ActiveMQConnectionFactory.class); assertThat(context).getBean(ConnectionFactory.class)
assertThat(loaded.getBean(ActiveMQConnectionFactory.class).getBrokerURL()) .isInstanceOf(ActiveMQConnectionFactory.class);
.isEqualTo("vm://localhost?broker.persistent=false"); assertThat(context.getBean(ActiveMQConnectionFactory.class)
}); .getBrokerURL())
.isEqualTo("vm://localhost?broker.persistent=false");
});
} }
@Test @Test
public void configurationBacksOffWhenCustomConnectionFactoryExists() { public void configurationBacksOffWhenCustomConnectionFactoryExists() {
this.context.withUserConfiguration(CustomConnectionFactoryConfiguration.class) this.contextRunner
.run((loaded) -> assertThat( .withUserConfiguration(CustomConnectionFactoryConfiguration.class)
mockingDetails(loaded.getBean(ConnectionFactory.class)).isMock()) .run((context) -> assertThat(
mockingDetails(context.getBean(ConnectionFactory.class)).isMock())
.isTrue()); .isTrue());
} }
@Test @Test
public void defaultsConnectionFactoryAreApplied() { public void defaultsConnectionFactoryAreApplied() {
this.context.withUserConfiguration(EmptyConfiguration.class) this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
.withPropertyValues("spring.activemq.pool.enabled=false") .withPropertyValues("spring.activemq.pool.enabled=false")
.run((loaded) -> { .run((context) -> {
assertThat(loaded.getBeansOfType(ActiveMQConnectionFactory.class)) assertThat(context.getBeansOfType(ActiveMQConnectionFactory.class))
.hasSize(1); .hasSize(1);
ActiveMQConnectionFactory connectionFactory = loaded ActiveMQConnectionFactory connectionFactory = context
.getBean(ActiveMQConnectionFactory.class); .getBean(ActiveMQConnectionFactory.class);
ActiveMQConnectionFactory defaultFactory = new ActiveMQConnectionFactory( ActiveMQConnectionFactory defaultFactory = new ActiveMQConnectionFactory(
"vm://localhost?broker.persistent=false"); "vm://localhost?broker.persistent=false");
...@@ -94,7 +97,7 @@ public class ActiveMQAutoConfigurationTests { ...@@ -94,7 +97,7 @@ public class ActiveMQAutoConfigurationTests {
@Test @Test
public void customConnectionFactoryAreApplied() { public void customConnectionFactoryAreApplied() {
this.context.withUserConfiguration(EmptyConfiguration.class) this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
.withPropertyValues("spring.activemq.pool.enabled=false", .withPropertyValues("spring.activemq.pool.enabled=false",
"spring.activemq.brokerUrl=vm://localhost?useJmx=false&broker.persistent=false", "spring.activemq.brokerUrl=vm://localhost?useJmx=false&broker.persistent=false",
"spring.activemq.user=foo", "spring.activemq.password=bar", "spring.activemq.user=foo", "spring.activemq.password=bar",
...@@ -103,10 +106,10 @@ public class ActiveMQAutoConfigurationTests { ...@@ -103,10 +106,10 @@ public class ActiveMQAutoConfigurationTests {
"spring.activemq.sendTimeout=1000", "spring.activemq.sendTimeout=1000",
"spring.activemq.packages.trust-all=false", "spring.activemq.packages.trust-all=false",
"spring.activemq.packages.trusted=com.example.acme") "spring.activemq.packages.trusted=com.example.acme")
.run((loaded) -> { .run((context) -> {
assertThat(loaded.getBeansOfType(ActiveMQConnectionFactory.class)) assertThat(context.getBeansOfType(ActiveMQConnectionFactory.class))
.hasSize(1); .hasSize(1);
ActiveMQConnectionFactory connectionFactory = loaded ActiveMQConnectionFactory connectionFactory = context
.getBean(ActiveMQConnectionFactory.class); .getBean(ActiveMQConnectionFactory.class);
assertThat(connectionFactory.getUserName()).isEqualTo("foo"); assertThat(connectionFactory.getUserName()).isEqualTo("foo");
assertThat(connectionFactory.getPassword()).isEqualTo("bar"); assertThat(connectionFactory.getPassword()).isEqualTo("bar");
...@@ -122,11 +125,12 @@ public class ActiveMQAutoConfigurationTests { ...@@ -122,11 +125,12 @@ public class ActiveMQAutoConfigurationTests {
@Test @Test
public void defaultsPooledConnectionFactoryAreApplied() { public void defaultsPooledConnectionFactoryAreApplied() {
this.context.withUserConfiguration(EmptyConfiguration.class) this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
.withPropertyValues("spring.activemq.pool.enabled=true").run((loaded) -> { .withPropertyValues("spring.activemq.pool.enabled=true")
assertThat(loaded.getBeansOfType(PooledConnectionFactory.class)) .run((context) -> {
assertThat(context.getBeansOfType(PooledConnectionFactory.class))
.hasSize(1); .hasSize(1);
PooledConnectionFactory connectionFactory = loaded PooledConnectionFactory connectionFactory = context
.getBean(PooledConnectionFactory.class); .getBean(PooledConnectionFactory.class);
PooledConnectionFactory defaultFactory = new PooledConnectionFactory(); PooledConnectionFactory defaultFactory = new PooledConnectionFactory();
assertThat(connectionFactory.isBlockIfSessionPoolIsFull()) assertThat(connectionFactory.isBlockIfSessionPoolIsFull())
...@@ -157,7 +161,7 @@ public class ActiveMQAutoConfigurationTests { ...@@ -157,7 +161,7 @@ public class ActiveMQAutoConfigurationTests {
@Test @Test
public void customPooledConnectionFactoryAreApplied() { public void customPooledConnectionFactoryAreApplied() {
this.context.withUserConfiguration(EmptyConfiguration.class) this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
.withPropertyValues("spring.activemq.pool.enabled=true", .withPropertyValues("spring.activemq.pool.enabled=true",
"spring.activemq.pool.blockIfFull=false", "spring.activemq.pool.blockIfFull=false",
"spring.activemq.pool.blockIfFullTimeout=64", "spring.activemq.pool.blockIfFullTimeout=64",
...@@ -169,10 +173,10 @@ public class ActiveMQAutoConfigurationTests { ...@@ -169,10 +173,10 @@ public class ActiveMQAutoConfigurationTests {
"spring.activemq.pool.reconnectOnException=false", "spring.activemq.pool.reconnectOnException=false",
"spring.activemq.pool.timeBetweenExpirationCheck=2048", "spring.activemq.pool.timeBetweenExpirationCheck=2048",
"spring.activemq.pool.useAnonymousProducers=false") "spring.activemq.pool.useAnonymousProducers=false")
.run((loaded) -> { .run((context) -> {
assertThat(loaded.getBeansOfType(PooledConnectionFactory.class)) assertThat(context.getBeansOfType(PooledConnectionFactory.class))
.hasSize(1); .hasSize(1);
PooledConnectionFactory connectionFactory = loaded PooledConnectionFactory connectionFactory = context
.getBean(PooledConnectionFactory.class); .getBean(PooledConnectionFactory.class);
assertThat(connectionFactory.isBlockIfSessionPoolIsFull()) assertThat(connectionFactory.isBlockIfSessionPoolIsFull())
.isEqualTo(false); .isEqualTo(false);
...@@ -196,11 +200,12 @@ public class ActiveMQAutoConfigurationTests { ...@@ -196,11 +200,12 @@ public class ActiveMQAutoConfigurationTests {
@Test @Test
public void pooledConnectionFactoryConfiguration() throws JMSException { public void pooledConnectionFactoryConfiguration() throws JMSException {
this.context.withUserConfiguration(EmptyConfiguration.class) this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
.withPropertyValues("spring.activemq.pool.enabled:true").run((loaded) -> { .withPropertyValues("spring.activemq.pool.enabled:true")
ConnectionFactory factory = loaded.getBean(ConnectionFactory.class); .run((context) -> {
ConnectionFactory factory = context.getBean(ConnectionFactory.class);
assertThat(factory).isInstanceOf(PooledConnectionFactory.class); assertThat(factory).isInstanceOf(PooledConnectionFactory.class);
loaded.getSourceApplicationContext().close(); context.getSourceApplicationContext().close();
assertThat(factory.createConnection()).isNull(); assertThat(factory.createConnection()).isNull();
}); });
} }
......
...@@ -213,7 +213,7 @@ public abstract class AbstractJpaAutoConfigurationTests { ...@@ -213,7 +213,7 @@ public abstract class AbstractJpaAutoConfigurationTests {
ctx.setClassLoader(classLoader); ctx.setClassLoader(classLoader);
} }
TestPropertyValues.of(environment) TestPropertyValues.of(environment)
.and("spring.datasource.generate-unique-name", "true").applyTo(ctx); .and("spring.datasource.generate-unique-name=true").applyTo(ctx);
ctx.register(TestConfiguration.class); ctx.register(TestConfiguration.class);
if (!ObjectUtils.isEmpty(configs)) { if (!ObjectUtils.isEmpty(configs)) {
ctx.register(configs); ctx.register(configs);
......
...@@ -19,7 +19,7 @@ package org.springframework.boot.autoconfigure.web.reactive; ...@@ -19,7 +19,7 @@ package org.springframework.boot.autoconfigure.web.reactive;
import org.junit.Test; import org.junit.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.ReactiveWebApplicationContextTester; import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.http.server.reactive.HttpHandler; import org.springframework.http.server.reactive.HttpHandler;
...@@ -39,24 +39,25 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -39,24 +39,25 @@ import static org.assertj.core.api.Assertions.assertThat;
*/ */
public class HttpHandlerAutoConfigurationTests { public class HttpHandlerAutoConfigurationTests {
private final ReactiveWebApplicationContextTester context = new ReactiveWebApplicationContextTester() private final ReactiveWebApplicationContextRunner contextRunner = new ReactiveWebApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(HttpHandlerAutoConfiguration.class)); .withConfiguration(AutoConfigurations.of(HttpHandlerAutoConfiguration.class));
@Test @Test
public void shouldNotProcessIfExistingHttpHandler() { public void shouldNotProcessIfExistingHttpHandler() {
this.context.withUserConfiguration(CustomHttpHandler.class).run((loaded) -> { this.contextRunner.withUserConfiguration(CustomHttpHandler.class)
assertThat(loaded).hasSingleBean(HttpHandler.class); .run((context) -> {
assertThat(loaded).getBean(HttpHandler.class) assertThat(context).hasSingleBean(HttpHandler.class);
.isSameAs(loaded.getBean("customHttpHandler")); assertThat(context).getBean(HttpHandler.class)
}); .isSameAs(context.getBean("customHttpHandler"));
});
} }
@Test @Test
public void shouldConfigureHttpHandlerAnnotation() { public void shouldConfigureHttpHandlerAnnotation() {
this.context this.contextRunner
.withConfiguration(AutoConfigurations.of(WebFluxAutoConfiguration.class)) .withConfiguration(AutoConfigurations.of(WebFluxAutoConfiguration.class))
.run((loaded) -> { .run((context) -> {
assertThat(loaded).hasSingleBean(HttpHandler.class); assertThat(context).hasSingleBean(HttpHandler.class);
}); });
} }
......
...@@ -24,7 +24,7 @@ import org.junit.rules.ExpectedException; ...@@ -24,7 +24,7 @@ import org.junit.rules.ExpectedException;
import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.BeanCreationException;
import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.WebApplicationContextTester; import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.test.util.ReflectionTestUtils; import org.springframework.test.util.ReflectionTestUtils;
...@@ -40,7 +40,7 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -40,7 +40,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*/ */
public class WebServicesAutoConfigurationTests { public class WebServicesAutoConfigurationTests {
private final WebApplicationContextTester context = new WebApplicationContextTester() private final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(WebServicesAutoConfiguration.class)); .withConfiguration(AutoConfigurations.of(WebServicesAutoConfiguration.class));
@Rule @Rule
...@@ -48,15 +48,15 @@ public class WebServicesAutoConfigurationTests { ...@@ -48,15 +48,15 @@ public class WebServicesAutoConfigurationTests {
@Test @Test
public void defaultConfiguration() { public void defaultConfiguration() {
this.context.run((loaded) -> assertThat(loaded) this.contextRunner.run((context) -> assertThat(context)
.hasSingleBean(ServletRegistrationBean.class)); .hasSingleBean(ServletRegistrationBean.class));
} }
@Test @Test
public void customPathMustBeginWithASlash() { public void customPathMustBeginWithASlash() {
this.context.withPropertyValues("spring.webservices.path=invalid") this.contextRunner.withPropertyValues("spring.webservices.path=invalid")
.run((loaded) -> { .run((context) -> {
assertThat(loaded).getFailure() assertThat(context).getFailure()
.isInstanceOf(BeanCreationException.class) .isInstanceOf(BeanCreationException.class)
.hasMessageContaining( .hasMessageContaining(
"Failed to bind properties under 'spring.webservices'"); "Failed to bind properties under 'spring.webservices'");
...@@ -65,21 +65,22 @@ public class WebServicesAutoConfigurationTests { ...@@ -65,21 +65,22 @@ public class WebServicesAutoConfigurationTests {
@Test @Test
public void customPath() { public void customPath() {
this.context.withPropertyValues("spring.webservices.path=/valid") this.contextRunner.withPropertyValues("spring.webservices.path=/valid").run(
.run((loaded) -> assertThat(getUrlMappings(loaded)).contains("/valid/*")); (context) -> assertThat(getUrlMappings(context)).contains("/valid/*"));
} }
@Test @Test
public void customPathWithTrailingSlash() { public void customPathWithTrailingSlash() {
this.context.withPropertyValues("spring.webservices.path=/valid/") this.contextRunner.withPropertyValues("spring.webservices.path=/valid/").run(
.run((loaded) -> assertThat(getUrlMappings(loaded)).contains("/valid/*")); (context) -> assertThat(getUrlMappings(context)).contains("/valid/*"));
} }
@Test @Test
public void customLoadOnStartup() { public void customLoadOnStartup() {
this.context.withPropertyValues("spring.webservices.servlet.load-on-startup=1") this.contextRunner
.run((loaded) -> { .withPropertyValues("spring.webservices.servlet.load-on-startup=1")
ServletRegistrationBean<?> registrationBean = loaded .run((context) -> {
ServletRegistrationBean<?> registrationBean = context
.getBean(ServletRegistrationBean.class); .getBean(ServletRegistrationBean.class);
assertThat(ReflectionTestUtils.getField(registrationBean, assertThat(ReflectionTestUtils.getField(registrationBean,
"loadOnStartup")).isEqualTo(1); "loadOnStartup")).isEqualTo(1);
...@@ -88,17 +89,17 @@ public class WebServicesAutoConfigurationTests { ...@@ -88,17 +89,17 @@ public class WebServicesAutoConfigurationTests {
@Test @Test
public void customInitParameters() { public void customInitParameters() {
this.context this.contextRunner
.withPropertyValues("spring.webservices.servlet.init.key1=value1", .withPropertyValues("spring.webservices.servlet.init.key1=value1",
"spring.webservices.servlet.init.key2=value2") "spring.webservices.servlet.init.key2=value2")
.run(loaded -> assertThat( .run((context) -> assertThat(
getServletRegistrationBean(loaded).getInitParameters()) getServletRegistrationBean(context).getInitParameters())
.containsEntry("key1", "value1") .containsEntry("key1", "value1")
.containsEntry("key2", "value2")); .containsEntry("key2", "value2"));
} }
private Collection<String> getUrlMappings(ApplicationContext loaded) { private Collection<String> getUrlMappings(ApplicationContext context) {
return getServletRegistrationBean(loaded).getUrlMappings(); return getServletRegistrationBean(context).getUrlMappings();
} }
private ServletRegistrationBean<?> getServletRegistrationBean( private ServletRegistrationBean<?> getServletRegistrationBean(
......
...@@ -21,7 +21,7 @@ import javax.sql.DataSource; ...@@ -21,7 +21,7 @@ import javax.sql.DataSource;
import org.junit.Test; import org.junit.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.ApplicationContextTester; import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
...@@ -38,24 +38,26 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -38,24 +38,26 @@ import static org.assertj.core.api.Assertions.assertThat;
*/ */
public class TestDatabaseAutoConfigurationTests { public class TestDatabaseAutoConfigurationTests {
private final ApplicationContextTester context = new ApplicationContextTester() private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration( .withConfiguration(
AutoConfigurations.of(TestDatabaseAutoConfiguration.class)); AutoConfigurations.of(TestDatabaseAutoConfiguration.class));
@Test @Test
public void replaceWithNoDataSourceAvailable() { public void replaceWithNoDataSourceAvailable() {
this.context this.contextRunner
.run((loaded) -> assertThat(loaded).doesNotHaveBean(DataSource.class)); .run((context) -> assertThat(context).doesNotHaveBean(DataSource.class));
} }
@Test @Test
public void replaceWithUniqueDatabase() { public void replaceWithUniqueDatabase() {
this.context.withUserConfiguration(ExistingDataSourceConfiguration.class) this.contextRunner.withUserConfiguration(ExistingDataSourceConfiguration.class)
.run((loaded) -> { .run((context) -> {
DataSource datasource = loaded.getBean(DataSource.class); DataSource datasource = context.getBean(DataSource.class);
JdbcTemplate jdbcTemplate = new JdbcTemplate(datasource); JdbcTemplate jdbcTemplate = new JdbcTemplate(datasource);
jdbcTemplate.execute("create table example (id int, name varchar);"); jdbcTemplate.execute("create table example (id int, name varchar);");
this.context.run((secondContext) -> { this.contextRunner
.withUserConfiguration(ExistingDataSourceConfiguration.class)
.run((secondContext) -> {
DataSource anotherDatasource = secondContext DataSource anotherDatasource = secondContext
.getBean(DataSource.class); .getBean(DataSource.class);
JdbcTemplate anotherJdbcTemplate = new JdbcTemplate( JdbcTemplate anotherJdbcTemplate = new JdbcTemplate(
......
...@@ -24,7 +24,7 @@ import org.junit.runner.RunWith; ...@@ -24,7 +24,7 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.BeanCreationException;
import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfiguration; import org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfiguration;
import org.springframework.boot.test.context.ApplicationContextTester; import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.boot.testsupport.runner.classpath.ClassPathExclusions; import org.springframework.boot.testsupport.runner.classpath.ClassPathExclusions;
import org.springframework.boot.testsupport.runner.classpath.ModifiedClassPathRunner; import org.springframework.boot.testsupport.runner.classpath.ModifiedClassPathRunner;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
...@@ -44,15 +44,15 @@ import static org.mockito.Mockito.mock; ...@@ -44,15 +44,15 @@ import static org.mockito.Mockito.mock;
@ClassPathExclusions({ "h2-*.jar", "hsqldb-*.jar", "derby-*.jar" }) @ClassPathExclusions({ "h2-*.jar", "hsqldb-*.jar", "derby-*.jar" })
public class TestDatabaseAutoConfigurationNoEmbeddedTests { public class TestDatabaseAutoConfigurationNoEmbeddedTests {
private final ApplicationContextTester context = new ApplicationContextTester() private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withUserConfiguration(ExistingDataSourceConfiguration.class) .withUserConfiguration(ExistingDataSourceConfiguration.class)
.withConfiguration( .withConfiguration(
AutoConfigurations.of(TestDatabaseAutoConfiguration.class)); AutoConfigurations.of(TestDatabaseAutoConfiguration.class));
@Test @Test
public void applyAnyReplace() { public void applyAnyReplace() {
this.context.run((loaded) -> { this.contextRunner.run((context) -> {
assertThat(loaded).getFailure().isInstanceOf(BeanCreationException.class) assertThat(context).getFailure().isInstanceOf(BeanCreationException.class)
.hasMessageContaining( .hasMessageContaining(
"Failed to replace DataSource with an embedded database for tests.") "Failed to replace DataSource with an embedded database for tests.")
.hasMessageContaining( .hasMessageContaining(
...@@ -64,11 +64,11 @@ public class TestDatabaseAutoConfigurationNoEmbeddedTests { ...@@ -64,11 +64,11 @@ public class TestDatabaseAutoConfigurationNoEmbeddedTests {
@Test @Test
public void applyNoReplace() { public void applyNoReplace() {
this.context.withPropertyValues("spring.test.database.replace=NONE") this.contextRunner.withPropertyValues("spring.test.database.replace=NONE")
.run((loaded) -> { .run((context) -> {
assertThat(loaded).hasSingleBean(DataSource.class); assertThat(context).hasSingleBean(DataSource.class);
assertThat(loaded).getBean(DataSource.class) assertThat(context).getBean(DataSource.class)
.isSameAs(loaded.getBean("myCustomDataSource")); .isSameAs(context.getBean("myCustomDataSource"));
}); });
} }
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.test.context; package org.springframework.boot.test.context.assertj;
import org.assertj.core.api.AbstractAssert; import org.assertj.core.api.AbstractAssert;
import org.assertj.core.api.AbstractObjectArrayAssert; import org.assertj.core.api.AbstractObjectArrayAssert;
...@@ -25,19 +25,20 @@ import org.assertj.core.api.MapAssert; ...@@ -25,19 +25,20 @@ import org.assertj.core.api.MapAssert;
import org.assertj.core.error.BasicErrorMessageFactory; import org.assertj.core.error.BasicErrorMessageFactory;
import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* AspectJ {@link org.assertj.core.api.Assert assertions} that can be applied to an * AssertJ {@link org.assertj.core.api.Assert assertions} that can be applied to an
* {@link ApplicationContext}. * {@link ApplicationContext}.
* *
* @param <C> The application context type * @param <C> The application context type
* @author Phillip Webb * @author Phillip Webb
* @since 2.0.0 * @since 2.0.0
* @see ApplicationContextTester * @see ApplicationContextRunner
* @see AssertableApplicationContext * @see AssertableApplicationContext
*/ */
public class ApplicationContextAssert<C extends ApplicationContext> public class ApplicationContextAssert<C extends ApplicationContext>
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.test.context; package org.springframework.boot.test.context.assertj;
import java.io.Closeable; import java.io.Closeable;
import java.lang.reflect.Proxy; import java.lang.reflect.Proxy;
...@@ -48,7 +48,7 @@ import org.springframework.util.Assert; ...@@ -48,7 +48,7 @@ import org.springframework.util.Assert;
* @see AssertableReactiveWebApplicationContext * @see AssertableReactiveWebApplicationContext
* @see ApplicationContextAssert * @see ApplicationContextAssert
*/ */
interface AssertProviderApplicationContext<C extends ApplicationContext> extends public interface ApplicationContextAssertProvider<C extends ApplicationContext> extends
ApplicationContext, AssertProvider<ApplicationContextAssert<C>>, Closeable { ApplicationContext, AssertProvider<ApplicationContextAssert<C>>, Closeable {
/** /**
...@@ -88,19 +88,19 @@ interface AssertProviderApplicationContext<C extends ApplicationContext> extends ...@@ -88,19 +88,19 @@ interface AssertProviderApplicationContext<C extends ApplicationContext> extends
void close(); void close();
/** /**
* Factory method to create a new {@link AssertProviderApplicationContext} instance. * Factory method to create a new {@link ApplicationContextAssertProvider} instance.
* @param <T> the assert provider type * @param <T> the assert provider type
* @param <C> the context type * @param <C> the context type
* @param type the type of {@link AssertProviderApplicationContext} required (must be * @param type the type of {@link ApplicationContextAssertProvider} required (must be
* an interface) * an interface)
* @param contextType the type of {@link ApplicationContext} being managed (must be an * @param contextType the type of {@link ApplicationContext} being managed (must be an
* interface) * interface)
* @param contextSupplier a supplier that will either return a fully configured * @param contextSupplier a supplier that will either return a fully configured
* {@link ApplicationContext} or throw an exception if the context fails to start. * {@link ApplicationContext} or throw an exception if the context fails to start.
* @return a {@link AssertProviderApplicationContext} instance * @return a {@link ApplicationContextAssertProvider} instance
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
static <T extends AssertProviderApplicationContext<C>, C extends ApplicationContext> T get( static <T extends ApplicationContextAssertProvider<C>, C extends ApplicationContext> T get(
Class<T> type, Class<? extends C> contextType, Class<T> type, Class<? extends C> contextType,
Supplier<? extends C> contextSupplier) { Supplier<? extends C> contextSupplier) {
Assert.notNull(type, "Type must not be null"); Assert.notNull(type, "Type must not be null");
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.test.context; package org.springframework.boot.test.context.assertj;
import java.io.Closeable; import java.io.Closeable;
import java.io.IOException; import java.io.IOException;
...@@ -31,7 +31,7 @@ import org.springframework.util.Assert; ...@@ -31,7 +31,7 @@ import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
/** /**
* {@link InvocationHandler} used by {@link AssertProviderApplicationContext} generated * {@link InvocationHandler} used by {@link ApplicationContextAssertProvider} generated
* proxies. * proxies.
* *
* @author Phillip Webb * @author Phillip Webb
......
...@@ -14,10 +14,11 @@ ...@@ -14,10 +14,11 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.test.context; package org.springframework.boot.test.context.assertj;
import java.util.function.Supplier; import java.util.function.Supplier;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
...@@ -26,15 +27,15 @@ import org.springframework.context.ConfigurableApplicationContext; ...@@ -26,15 +27,15 @@ import org.springframework.context.ConfigurableApplicationContext;
* be used to decorate and existing application context or an application context that * be used to decorate and existing application context or an application context that
* failed to start. * failed to start.
* <p> * <p>
* See {@link AssertProviderApplicationContext} for more details. * See {@link ApplicationContextAssertProvider} for more details.
* *
* @author Phillip Webb * @author Phillip Webb
* @since 2.0.0 * @since 2.0.0
* @see ApplicationContextTester * @see ApplicationContextRunner
* @see ApplicationContext * @see ApplicationContext
*/ */
public interface AssertableApplicationContext public interface AssertableApplicationContext
extends AssertProviderApplicationContext<ConfigurableApplicationContext> { extends ApplicationContextAssertProvider<ConfigurableApplicationContext> {
/** /**
* Factory method to create a new {@link AssertableApplicationContext} instance. * Factory method to create a new {@link AssertableApplicationContext} instance.
...@@ -45,7 +46,7 @@ public interface AssertableApplicationContext ...@@ -45,7 +46,7 @@ public interface AssertableApplicationContext
*/ */
static AssertableApplicationContext get( static AssertableApplicationContext get(
Supplier<? extends ConfigurableApplicationContext> contextSupplier) { Supplier<? extends ConfigurableApplicationContext> contextSupplier) {
return AssertProviderApplicationContext.get(AssertableApplicationContext.class, return ApplicationContextAssertProvider.get(AssertableApplicationContext.class,
ConfigurableApplicationContext.class, contextSupplier); ConfigurableApplicationContext.class, contextSupplier);
} }
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.test.context; package org.springframework.boot.test.context.assertj;
import java.util.function.Supplier; import java.util.function.Supplier;
...@@ -26,7 +26,7 @@ import org.springframework.boot.web.reactive.context.ReactiveWebApplicationConte ...@@ -26,7 +26,7 @@ import org.springframework.boot.web.reactive.context.ReactiveWebApplicationConte
* assertions. Can be used to decorate and existing reactive web application context or an * assertions. Can be used to decorate and existing reactive web application context or an
* application context that failed to start. * application context that failed to start.
* <p> * <p>
* See {@link AssertProviderApplicationContext} for more details. * See {@link ApplicationContextAssertProvider} for more details.
* *
* @author Phillip Webb * @author Phillip Webb
* @since 2.0.0 * @since 2.0.0
...@@ -34,7 +34,7 @@ import org.springframework.boot.web.reactive.context.ReactiveWebApplicationConte ...@@ -34,7 +34,7 @@ import org.springframework.boot.web.reactive.context.ReactiveWebApplicationConte
* @see ReactiveWebApplicationContext * @see ReactiveWebApplicationContext
*/ */
public interface AssertableReactiveWebApplicationContext extends public interface AssertableReactiveWebApplicationContext extends
AssertProviderApplicationContext<ConfigurableReactiveWebApplicationContext>, ApplicationContextAssertProvider<ConfigurableReactiveWebApplicationContext>,
ReactiveWebApplicationContext { ReactiveWebApplicationContext {
/** /**
...@@ -47,7 +47,7 @@ public interface AssertableReactiveWebApplicationContext extends ...@@ -47,7 +47,7 @@ public interface AssertableReactiveWebApplicationContext extends
*/ */
static AssertableReactiveWebApplicationContext get( static AssertableReactiveWebApplicationContext get(
Supplier<? extends ConfigurableReactiveWebApplicationContext> contextSupplier) { Supplier<? extends ConfigurableReactiveWebApplicationContext> contextSupplier) {
return AssertProviderApplicationContext.get( return ApplicationContextAssertProvider.get(
AssertableReactiveWebApplicationContext.class, AssertableReactiveWebApplicationContext.class,
ConfigurableReactiveWebApplicationContext.class, contextSupplier); ConfigurableReactiveWebApplicationContext.class, contextSupplier);
} }
......
...@@ -14,10 +14,11 @@ ...@@ -14,10 +14,11 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.test.context; package org.springframework.boot.test.context.assertj;
import java.util.function.Supplier; import java.util.function.Supplier;
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
import org.springframework.web.context.ConfigurableWebApplicationContext; import org.springframework.web.context.ConfigurableWebApplicationContext;
import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.WebApplicationContext;
...@@ -26,15 +27,15 @@ import org.springframework.web.context.WebApplicationContext; ...@@ -26,15 +27,15 @@ import org.springframework.web.context.WebApplicationContext;
* Can be used to decorate and existing servlet web application context or an application * Can be used to decorate and existing servlet web application context or an application
* context that failed to start. * context that failed to start.
* <p> * <p>
* See {@link AssertProviderApplicationContext} for more details. * See {@link ApplicationContextAssertProvider} for more details.
* *
* @author Phillip Webb * @author Phillip Webb
* @since 2.0.0 * @since 2.0.0
* @see WebApplicationContextTester * @see WebApplicationContextRunner
* @see WebApplicationContext * @see WebApplicationContext
*/ */
public interface AssertableWebApplicationContext public interface AssertableWebApplicationContext
extends AssertProviderApplicationContext<ConfigurableWebApplicationContext>, extends ApplicationContextAssertProvider<ConfigurableWebApplicationContext>,
WebApplicationContext { WebApplicationContext {
/** /**
...@@ -46,7 +47,7 @@ public interface AssertableWebApplicationContext ...@@ -46,7 +47,7 @@ public interface AssertableWebApplicationContext
*/ */
static AssertableWebApplicationContext get( static AssertableWebApplicationContext get(
Supplier<? extends ConfigurableWebApplicationContext> contextSupplier) { Supplier<? extends ConfigurableWebApplicationContext> contextSupplier) {
return AssertProviderApplicationContext.get(AssertableWebApplicationContext.class, return ApplicationContextAssertProvider.get(AssertableWebApplicationContext.class,
ConfigurableWebApplicationContext.class, contextSupplier); ConfigurableWebApplicationContext.class, contextSupplier);
} }
......
/*
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* AssertJ support for ApplicationContexts.
*/
package org.springframework.boot.test.context.assertj;
...@@ -14,43 +14,67 @@ ...@@ -14,43 +14,67 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.test.context; package org.springframework.boot.test.context.runner;
import java.util.List;
import java.util.function.Supplier; import java.util.function.Supplier;
import org.springframework.boot.context.annotation.Configurations;
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
/** /**
* A {@link AbstractApplicationContextTester ApplicationContext tester} for a standard, * A {@link AbstractApplicationContextRunner ApplicationContext runner} for a standard,
* non-web environment {@link ConfigurableApplicationContext}. * non-web environment {@link ConfigurableApplicationContext}.
* <p> * <p>
* See {@link AbstractApplicationContextTester} for details. * See {@link AbstractApplicationContextRunner} for details.
* *
* @author Stephane Nicoll * @author Stephane Nicoll
* @author Andy Wilkinson * @author Andy Wilkinson
* @author Phillip Webb * @author Phillip Webb
* @since 2.0.0 * @since 2.0.0
*/ */
public class ApplicationContextTester extends public class ApplicationContextRunner extends
AbstractApplicationContextTester<ApplicationContextTester, ConfigurableApplicationContext, AssertableApplicationContext> { AbstractApplicationContextRunner<ApplicationContextRunner, ConfigurableApplicationContext, AssertableApplicationContext> {
/** /**
* Create a new {@link ApplicationContextTester} instance using an * Create a new {@link ApplicationContextRunner} instance using an
* {@link AnnotationConfigApplicationContext} as the underlying source. * {@link AnnotationConfigApplicationContext} as the underlying source.
*/ */
public ApplicationContextTester() { public ApplicationContextRunner() {
this(AnnotationConfigApplicationContext::new); this(AnnotationConfigApplicationContext::new);
} }
/** /**
* Create a new {@link ApplicationContextTester} instance using the specified * Create a new {@link ApplicationContextRunner} instance using the specified
* {@code contextFactory} as the underlying source. * {@code contextFactory} as the underlying source.
* @param contextFactory a supplier that returns a new instance on each call * @param contextFactory a supplier that returns a new instance on each call
*/ */
public ApplicationContextTester( public ApplicationContextRunner(
Supplier<ConfigurableApplicationContext> contextFactory) { Supplier<ConfigurableApplicationContext> contextFactory) {
super(contextFactory); super(contextFactory);
} }
private ApplicationContextRunner(
Supplier<ConfigurableApplicationContext> contextFactory,
TestPropertyValues environmentProperties, TestPropertyValues systemProperties,
ClassLoader classLoader, ApplicationContext parent,
List<Configurations> configurations) {
super(contextFactory, environmentProperties, systemProperties, classLoader,
parent, configurations);
}
@Override
protected ApplicationContextRunner newInstance(
Supplier<ConfigurableApplicationContext> contextFactory,
TestPropertyValues environmentProperties, TestPropertyValues systemProperties,
ClassLoader classLoader, ApplicationContext parent,
List<Configurations> configurations) {
return new ApplicationContextRunner(contextFactory, environmentProperties,
systemProperties, classLoader, parent, configurations);
}
} }
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.test.context; package org.springframework.boot.test.context.runner;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
...@@ -26,7 +26,7 @@ import org.springframework.context.ApplicationContext; ...@@ -26,7 +26,7 @@ import org.springframework.context.ApplicationContext;
* @author Andy Wilkinson * @author Andy Wilkinson
* @param <C> The application context type * @param <C> The application context type
* @since 2.0.0 * @since 2.0.0
* @see AbstractApplicationContextTester * @see AbstractApplicationContextRunner
*/ */
@FunctionalInterface @FunctionalInterface
public interface ContextConsumer<C extends ApplicationContext> { public interface ContextConsumer<C extends ApplicationContext> {
......
...@@ -14,43 +14,68 @@ ...@@ -14,43 +14,68 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.test.context; package org.springframework.boot.test.context.runner;
import java.util.List;
import java.util.function.Supplier; import java.util.function.Supplier;
import org.springframework.boot.context.annotation.Configurations;
import org.springframework.boot.test.context.assertj.AssertableReactiveWebApplicationContext;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.boot.web.reactive.context.ConfigurableReactiveWebApplicationContext; import org.springframework.boot.web.reactive.context.ConfigurableReactiveWebApplicationContext;
import org.springframework.boot.web.reactive.context.GenericReactiveWebApplicationContext; import org.springframework.boot.web.reactive.context.GenericReactiveWebApplicationContext;
import org.springframework.context.ApplicationContext;
/** /**
* A {@link AbstractApplicationContextTester ApplicationContext tester} for a * A {@link AbstractApplicationContextRunner ApplicationContext runner} for a
* {@link ConfigurableReactiveWebApplicationContext}. * {@link ConfigurableReactiveWebApplicationContext}.
* <p> * <p>
* See {@link AbstractApplicationContextTester} for details. * See {@link AbstractApplicationContextRunner} for details.
* *
* @author Andy Wilkinson * @author Andy Wilkinson
* @author Stephane Nicoll * @author Stephane Nicoll
* @author Phillip Webb * @author Phillip Webb
* @since 2.0.0 * @since 2.0.0
*/ */
public final class ReactiveWebApplicationContextTester extends public final class ReactiveWebApplicationContextRunner extends
AbstractApplicationContextTester<ReactiveWebApplicationContextTester, ConfigurableReactiveWebApplicationContext, AssertableReactiveWebApplicationContext> { AbstractApplicationContextRunner<ReactiveWebApplicationContextRunner, ConfigurableReactiveWebApplicationContext, AssertableReactiveWebApplicationContext> {
/** /**
* Create a new {@link ReactiveWebApplicationContextTester} instance using a * Create a new {@link ReactiveWebApplicationContextRunner} instance using a
* {@link GenericReactiveWebApplicationContext} as the underlying source. * {@link GenericReactiveWebApplicationContext} as the underlying source.
*/ */
public ReactiveWebApplicationContextTester() { public ReactiveWebApplicationContextRunner() {
this(GenericReactiveWebApplicationContext::new); this(GenericReactiveWebApplicationContext::new);
} }
/** /**
* Create a new {@link ApplicationContextTester} instance using the specified * Create a new {@link ApplicationContextRunner} instance using the specified
* {@code contextFactory} as the underlying source. * {@code contextFactory} as the underlying source.
* @param contextFactory a supplier that returns a new instance on each call * @param contextFactory a supplier that returns a new instance on each call
*/ */
public ReactiveWebApplicationContextTester( public ReactiveWebApplicationContextRunner(
Supplier<ConfigurableReactiveWebApplicationContext> contextFactory) { Supplier<ConfigurableReactiveWebApplicationContext> contextFactory) {
super(contextFactory); super(contextFactory);
} }
private ReactiveWebApplicationContextRunner(
Supplier<ConfigurableReactiveWebApplicationContext> contextFactory,
TestPropertyValues environmentProperties, TestPropertyValues systemProperties,
ClassLoader classLoader, ApplicationContext parent,
List<Configurations> configurations) {
super(contextFactory, environmentProperties, systemProperties, classLoader,
parent, configurations);
}
@Override
protected ReactiveWebApplicationContextRunner newInstance(
Supplier<ConfigurableReactiveWebApplicationContext> contextFactory,
TestPropertyValues environmentProperties, TestPropertyValues systemProperties,
ClassLoader classLoader, ApplicationContext parent,
List<Configurations> configurations) {
return new ReactiveWebApplicationContextRunner(contextFactory,
environmentProperties, systemProperties, classLoader, parent,
configurations);
}
} }
...@@ -14,49 +14,73 @@ ...@@ -14,49 +14,73 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.test.context; package org.springframework.boot.test.context.runner;
import java.util.List;
import java.util.function.Supplier; import java.util.function.Supplier;
import org.springframework.boot.context.annotation.Configurations;
import org.springframework.boot.test.context.assertj.AssertableWebApplicationContext;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.ApplicationContext;
import org.springframework.mock.web.MockServletContext; import org.springframework.mock.web.MockServletContext;
import org.springframework.web.context.ConfigurableWebApplicationContext; import org.springframework.web.context.ConfigurableWebApplicationContext;
import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
/** /**
* A {@link AbstractApplicationContextTester ApplicationContext tester} for a Servlet * A {@link AbstractApplicationContextRunner ApplicationContext runner} for a Servlet
* based {@link ConfigurableWebApplicationContext}. * based {@link ConfigurableWebApplicationContext}.
* <p> * <p>
* See {@link AbstractApplicationContextTester} for details. * See {@link AbstractApplicationContextRunner} for details.
* *
* @author Andy Wilkinson * @author Andy Wilkinson
* @author Stephane Nicoll * @author Stephane Nicoll
* @author Phillip Webb * @author Phillip Webb
* @since 2.0.0 * @since 2.0.0
*/ */
public final class WebApplicationContextTester extends public final class WebApplicationContextRunner extends
AbstractApplicationContextTester<WebApplicationContextTester, ConfigurableWebApplicationContext, AssertableWebApplicationContext> { AbstractApplicationContextRunner<WebApplicationContextRunner, ConfigurableWebApplicationContext, AssertableWebApplicationContext> {
/** /**
* Create a new {@link WebApplicationContextTester} instance using an * Create a new {@link WebApplicationContextRunner} instance using an
* {@link AnnotationConfigWebApplicationContext} with a {@link MockServletContext} as * {@link AnnotationConfigWebApplicationContext} with a {@link MockServletContext} as
* the underlying source. * the underlying source.
* @see #withMockServletContext(Supplier) * @see #withMockServletContext(Supplier)
*/ */
public WebApplicationContextTester() { public WebApplicationContextRunner() {
this(withMockServletContext(AnnotationConfigWebApplicationContext::new)); this(withMockServletContext(AnnotationConfigWebApplicationContext::new));
} }
/** /**
* Create a new {@link WebApplicationContextTester} instance using the specified * Create a new {@link WebApplicationContextRunner} instance using the specified
* {@code contextFactory} as the underlying source. * {@code contextFactory} as the underlying source.
* @param contextFactory a supplier that returns a new instance on each call * @param contextFactory a supplier that returns a new instance on each call
*/ */
public WebApplicationContextTester( public WebApplicationContextRunner(
Supplier<ConfigurableWebApplicationContext> contextFactory) { Supplier<ConfigurableWebApplicationContext> contextFactory) {
super(contextFactory); super(contextFactory);
} }
private WebApplicationContextRunner(
Supplier<ConfigurableWebApplicationContext> contextFactory,
TestPropertyValues environmentProperties, TestPropertyValues systemProperties,
ClassLoader classLoader, ApplicationContext parent,
List<Configurations> configurations) {
super(contextFactory, environmentProperties, systemProperties, classLoader,
parent, configurations);
}
@Override
protected WebApplicationContextRunner newInstance(
Supplier<ConfigurableWebApplicationContext> contextFactory,
TestPropertyValues environmentProperties, TestPropertyValues systemProperties,
ClassLoader classLoader, ApplicationContext parent,
List<Configurations> configurations) {
return new WebApplicationContextRunner(contextFactory, environmentProperties,
systemProperties, classLoader, parent, configurations);
}
/** /**
* Decorate the specified {@code contextFactory} to set a {@link MockServletContext} * Decorate the specified {@code contextFactory} to set a {@link MockServletContext}
* on each newly created {@link WebApplicationContext}. * on each newly created {@link WebApplicationContext}.
......
/*
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Test utilities to run application contexts for testing.
*/
package org.springframework.boot.test.context.runner;
...@@ -17,9 +17,13 @@ ...@@ -17,9 +17,13 @@
package org.springframework.boot.test.util; package org.springframework.boot.test.util;
import java.io.Closeable; import java.io.Closeable;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.stream.Stream;
import com.google.common.collect.Streams; import com.google.common.collect.Streams;
...@@ -45,56 +49,28 @@ import org.springframework.util.StringUtils; ...@@ -45,56 +49,28 @@ import org.springframework.util.StringUtils;
*/ */
public final class TestPropertyValues { public final class TestPropertyValues {
private final Map<String, Object> properties = new LinkedHashMap<>(); private static final TestPropertyValues EMPTY = new TestPropertyValues(
Collections.emptyMap());
private TestPropertyValues(String[] pairs) { private final Map<String, Object> properties;
addProperties(pairs);
}
private void addProperties(String[] pairs) { private TestPropertyValues(Map<String, Object> properties) {
for (String pair : pairs) { this.properties = Collections.unmodifiableMap(properties);
and(pair);
}
} }
/** /**
* Builder method to append another property pair the underlying map of properties. * Builder method to add more properties.
* @param pair The property pair to add * @param pairs The property pairs to add
* @return the existing instance of {@link TestPropertyValues} * @return a new {@link TestPropertyValues} instance
*/ */
public TestPropertyValues and(String pair) { public TestPropertyValues and(String... pairs) {
int index = getSeparatorIndex(pair); return and(Arrays.stream(pairs).map(Pair::parse));
String key = pair.substring(0, index > 0 ? index : pair.length());
String value = index > 0 ? pair.substring(index + 1) : "";
and(key.trim(), value.trim());
return this;
} }
private int getSeparatorIndex(String pair) { private TestPropertyValues and(Stream<Pair> pairs) {
int colonIndex = pair.indexOf(":"); Map<String, Object> properties = new LinkedHashMap<>(this.properties);
int equalIndex = pair.indexOf("="); pairs.filter(Objects::nonNull).forEach((pair) -> pair.addTo(properties));
if (colonIndex == -1) { return new TestPropertyValues(properties);
return equalIndex;
}
if (equalIndex == -1) {
return colonIndex;
}
return Math.min(colonIndex, equalIndex);
}
/**
* Builder method to append another property to the underlying map of properties.
* @param name The property name
* @param value The property value
* @return the existing instance of {@link TestPropertyValues}
*/
public TestPropertyValues and(String name, String value) {
if (StringUtils.isEmpty(name) && StringUtils.isEmpty(value)) {
return this;
}
Assert.hasLength(name, "Name must not be empty");
this.properties.put(name, value);
return this;
} }
/** /**
...@@ -170,30 +146,21 @@ public final class TestPropertyValues { ...@@ -170,30 +146,21 @@ public final class TestPropertyValues {
return; return;
} }
} }
MapPropertySource source = (type.equals(Type.MAP) Map<String, Object> source = new LinkedHashMap<>(this.properties);
? new MapPropertySource(name, this.properties) sources.addFirst((type.equals(Type.MAP) ? new MapPropertySource(name, source)
: new SystemEnvironmentPropertySource(name, this.properties)); : new SystemEnvironmentPropertySource(name, source)));
sources.addFirst(source);
}
/**
* Return a new empty {@link TestPropertyValues} instance.
* @return an empty instance
*/
public static TestPropertyValues empty() {
return of();
} }
/** /**
* Return a new {@link TestPropertyValues} with the underlying map populated with the * Return a new {@link TestPropertyValues} with the underlying map populated with the
* given property pair. * given property pairs. Name-value pairs can be specified with colon (":") or equals
* @param name the property name * ("=") separators.
* @param value the property value * @param pairs The key value pairs for properties that need to be added to the
* environment
* @return the new instance * @return the new instance
*/ */
public static TestPropertyValues of(String... pairs) {
public static TestPropertyValues ofPair(String name, String value) { return of(Stream.of(pairs));
return of().and(name, value);
} }
/** /**
...@@ -206,9 +173,9 @@ public final class TestPropertyValues { ...@@ -206,9 +173,9 @@ public final class TestPropertyValues {
*/ */
public static TestPropertyValues of(Iterable<String> pairs) { public static TestPropertyValues of(Iterable<String> pairs) {
if (pairs == null) { if (pairs == null) {
return of(); return empty();
} }
return of(Streams.stream(pairs).toArray(String[]::new)); return of(Streams.stream(pairs));
} }
/** /**
...@@ -219,8 +186,19 @@ public final class TestPropertyValues { ...@@ -219,8 +186,19 @@ public final class TestPropertyValues {
* environment * environment
* @return the new instance * @return the new instance
*/ */
public static TestPropertyValues of(String... pairs) { public static TestPropertyValues of(Stream<String> pairs) {
return new TestPropertyValues(pairs); if (pairs == null) {
return empty();
}
return empty().and(pairs.map(Pair::parse));
}
/**
* Return a new empty {@link TestPropertyValues} instance.
* @return an empty instance
*/
public static TestPropertyValues empty() {
return EMPTY;
} }
/** /**
...@@ -250,6 +228,53 @@ public final class TestPropertyValues { ...@@ -250,6 +228,53 @@ public final class TestPropertyValues {
} }
/**
* A single name value pair.
*/
public static class Pair {
private String name;
private String value;
public Pair(String name, String value) {
Assert.hasLength(name, "Name must not be empty");
this.name = name;
this.value = value;
}
public void addTo(Map<String, Object> properties) {
properties.put(this.name, this.value);
}
public static Pair parse(String pair) {
int index = getSeparatorIndex(pair);
String key = pair.substring(0, index > 0 ? index : pair.length());
String value = index > 0 ? pair.substring(index + 1) : "";
return of(key.trim(), value.trim());
}
private static int getSeparatorIndex(String pair) {
int colonIndex = pair.indexOf(":");
int equalIndex = pair.indexOf("=");
if (colonIndex == -1) {
return equalIndex;
}
if (equalIndex == -1) {
return colonIndex;
}
return Math.min(colonIndex, equalIndex);
}
private static Pair of(String name, String value) {
if (StringUtils.isEmpty(name) && StringUtils.isEmpty(value)) {
return null;
}
return new Pair(name, value);
}
}
/** /**
* Handler to apply and restore system properties. * Handler to apply and restore system properties.
*/ */
...@@ -278,7 +303,7 @@ public final class TestPropertyValues { ...@@ -278,7 +303,7 @@ public final class TestPropertyValues {
private String setOrClear(String name, String value) { private String setOrClear(String name, String value) {
Assert.notNull(name, "Name must not be null"); Assert.notNull(name, "Name must not be null");
if (value == null) { if (StringUtils.isEmpty(value)) {
return (String) System.getProperties().remove(name); return (String) System.getProperties().remove(name);
} }
return (String) System.getProperties().setProperty(name, value); return (String) System.getProperties().setProperty(name, value);
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.test.context; package org.springframework.boot.test.context.assertj;
import java.util.function.Supplier; import java.util.function.Supplier;
...@@ -34,12 +34,12 @@ import static org.hamcrest.Matchers.equalTo; ...@@ -34,12 +34,12 @@ import static org.hamcrest.Matchers.equalTo;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
/** /**
* Tests for {@link AssertProviderApplicationContext} and * Tests for {@link ApplicationContextAssertProvider} and
* {@link AssertProviderApplicationContextInvocationHandler}. * {@link AssertProviderApplicationContextInvocationHandler}.
* *
* @author Phillip Webb * @author Phillip Webb
*/ */
public class AssertProviderApplicationContextTests { public class ApplicationContextAssertProviderTests {
@Rule @Rule
public ExpectedException thrown = ExpectedException.none(); public ExpectedException thrown = ExpectedException.none();
...@@ -67,7 +67,7 @@ public class AssertProviderApplicationContextTests { ...@@ -67,7 +67,7 @@ public class AssertProviderApplicationContextTests {
public void getWhenTypeIsNullShouldThrowException() throws Exception { public void getWhenTypeIsNullShouldThrowException() throws Exception {
this.thrown.expect(IllegalArgumentException.class); this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Type must not be null"); this.thrown.expectMessage("Type must not be null");
AssertProviderApplicationContext.get(null, ApplicationContext.class, ApplicationContextAssertProvider.get(null, ApplicationContext.class,
this.mockContextSupplier); this.mockContextSupplier);
} }
...@@ -75,7 +75,7 @@ public class AssertProviderApplicationContextTests { ...@@ -75,7 +75,7 @@ public class AssertProviderApplicationContextTests {
public void getWhenTypeIsClassShouldThrowException() throws Exception { public void getWhenTypeIsClassShouldThrowException() throws Exception {
this.thrown.expect(IllegalArgumentException.class); this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Type must not be null"); this.thrown.expectMessage("Type must not be null");
AssertProviderApplicationContext.get(null, ApplicationContext.class, ApplicationContextAssertProvider.get(null, ApplicationContext.class,
this.mockContextSupplier); this.mockContextSupplier);
} }
...@@ -83,7 +83,7 @@ public class AssertProviderApplicationContextTests { ...@@ -83,7 +83,7 @@ public class AssertProviderApplicationContextTests {
public void getWhenContextTypeIsNullShouldThrowException() throws Exception { public void getWhenContextTypeIsNullShouldThrowException() throws Exception {
this.thrown.expect(IllegalArgumentException.class); this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Type must be an interface"); this.thrown.expectMessage("Type must be an interface");
AssertProviderApplicationContext.get( ApplicationContextAssertProvider.get(
TestAssertProviderApplicationContextClass.class, ApplicationContext.class, TestAssertProviderApplicationContextClass.class, ApplicationContext.class,
this.mockContextSupplier); this.mockContextSupplier);
} }
...@@ -92,7 +92,7 @@ public class AssertProviderApplicationContextTests { ...@@ -92,7 +92,7 @@ public class AssertProviderApplicationContextTests {
public void getWhenContextTypeIsClassShouldThrowException() throws Exception { public void getWhenContextTypeIsClassShouldThrowException() throws Exception {
this.thrown.expect(IllegalArgumentException.class); this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("ContextType must not be null"); this.thrown.expectMessage("ContextType must not be null");
AssertProviderApplicationContext.get(TestAssertProviderApplicationContext.class, ApplicationContextAssertProvider.get(TestAssertProviderApplicationContext.class,
null, this.mockContextSupplier); null, this.mockContextSupplier);
} }
...@@ -100,14 +100,14 @@ public class AssertProviderApplicationContextTests { ...@@ -100,14 +100,14 @@ public class AssertProviderApplicationContextTests {
public void getWhenSupplierIsNullShouldThrowException() throws Exception { public void getWhenSupplierIsNullShouldThrowException() throws Exception {
this.thrown.expect(IllegalArgumentException.class); this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("ContextType must be an interface"); this.thrown.expectMessage("ContextType must be an interface");
AssertProviderApplicationContext.get(TestAssertProviderApplicationContext.class, ApplicationContextAssertProvider.get(TestAssertProviderApplicationContext.class,
StaticApplicationContext.class, this.mockContextSupplier); StaticApplicationContext.class, this.mockContextSupplier);
} }
@Test @Test
public void getWhenContextStartsShouldReturnProxyThatCallsRealMethods() public void getWhenContextStartsShouldReturnProxyThatCallsRealMethods()
throws Exception { throws Exception {
AssertProviderApplicationContext<ApplicationContext> context = get( ApplicationContextAssertProvider<ApplicationContext> context = get(
this.mockContextSupplier); this.mockContextSupplier);
assertThat((Object) context).isNotNull(); assertThat((Object) context).isNotNull();
context.getBean("foo"); context.getBean("foo");
...@@ -117,7 +117,7 @@ public class AssertProviderApplicationContextTests { ...@@ -117,7 +117,7 @@ public class AssertProviderApplicationContextTests {
@Test @Test
public void getWhenContextFailsShouldReturnProxyThatThrowsExceptions() public void getWhenContextFailsShouldReturnProxyThatThrowsExceptions()
throws Exception { throws Exception {
AssertProviderApplicationContext<ApplicationContext> context = get( ApplicationContextAssertProvider<ApplicationContext> context = get(
this.startupFailureSupplier); this.startupFailureSupplier);
assertThat((Object) context).isNotNull(); assertThat((Object) context).isNotNull();
expectStartupFailure(); expectStartupFailure();
...@@ -127,14 +127,14 @@ public class AssertProviderApplicationContextTests { ...@@ -127,14 +127,14 @@ public class AssertProviderApplicationContextTests {
@Test @Test
public void getSourceContextWhenContextStartsShouldReturnSourceContext() public void getSourceContextWhenContextStartsShouldReturnSourceContext()
throws Exception { throws Exception {
AssertProviderApplicationContext<ApplicationContext> context = get( ApplicationContextAssertProvider<ApplicationContext> context = get(
this.mockContextSupplier); this.mockContextSupplier);
assertThat(context.getSourceApplicationContext()).isSameAs(this.mockContext); assertThat(context.getSourceApplicationContext()).isSameAs(this.mockContext);
} }
@Test @Test
public void getSourceContextWhenContextFailsShouldThrowException() throws Exception { public void getSourceContextWhenContextFailsShouldThrowException() throws Exception {
AssertProviderApplicationContext<ApplicationContext> context = get( ApplicationContextAssertProvider<ApplicationContext> context = get(
this.startupFailureSupplier); this.startupFailureSupplier);
expectStartupFailure(); expectStartupFailure();
context.getSourceApplicationContext(); context.getSourceApplicationContext();
...@@ -143,7 +143,7 @@ public class AssertProviderApplicationContextTests { ...@@ -143,7 +143,7 @@ public class AssertProviderApplicationContextTests {
@Test @Test
public void getSourceContextOfTypeWhenContextStartsShouldReturnSourceContext() public void getSourceContextOfTypeWhenContextStartsShouldReturnSourceContext()
throws Exception { throws Exception {
AssertProviderApplicationContext<ApplicationContext> context = get( ApplicationContextAssertProvider<ApplicationContext> context = get(
this.mockContextSupplier); this.mockContextSupplier);
assertThat(context.getSourceApplicationContext(ApplicationContext.class)) assertThat(context.getSourceApplicationContext(ApplicationContext.class))
.isSameAs(this.mockContext); .isSameAs(this.mockContext);
...@@ -152,7 +152,7 @@ public class AssertProviderApplicationContextTests { ...@@ -152,7 +152,7 @@ public class AssertProviderApplicationContextTests {
@Test @Test
public void getSourceContextOfTypeWhenContextFailsToStartShouldThrowException() public void getSourceContextOfTypeWhenContextFailsToStartShouldThrowException()
throws Exception { throws Exception {
AssertProviderApplicationContext<ApplicationContext> context = get( ApplicationContextAssertProvider<ApplicationContext> context = get(
this.startupFailureSupplier); this.startupFailureSupplier);
expectStartupFailure(); expectStartupFailure();
context.getSourceApplicationContext(ApplicationContext.class); context.getSourceApplicationContext(ApplicationContext.class);
...@@ -160,7 +160,7 @@ public class AssertProviderApplicationContextTests { ...@@ -160,7 +160,7 @@ public class AssertProviderApplicationContextTests {
@Test @Test
public void getStartupFailureWhenContextStartsShouldReturnNull() throws Exception { public void getStartupFailureWhenContextStartsShouldReturnNull() throws Exception {
AssertProviderApplicationContext<ApplicationContext> context = get( ApplicationContextAssertProvider<ApplicationContext> context = get(
this.mockContextSupplier); this.mockContextSupplier);
assertThat(context.getStartupFailure()).isNull(); assertThat(context.getStartupFailure()).isNull();
} }
...@@ -168,14 +168,14 @@ public class AssertProviderApplicationContextTests { ...@@ -168,14 +168,14 @@ public class AssertProviderApplicationContextTests {
@Test @Test
public void getStartupFailureWhenContextFailsToStartShouldReturnException() public void getStartupFailureWhenContextFailsToStartShouldReturnException()
throws Exception { throws Exception {
AssertProviderApplicationContext<ApplicationContext> context = get( ApplicationContextAssertProvider<ApplicationContext> context = get(
this.startupFailureSupplier); this.startupFailureSupplier);
assertThat(context.getStartupFailure()).isEqualTo(this.startupFailure); assertThat(context.getStartupFailure()).isEqualTo(this.startupFailure);
} }
@Test @Test
public void assertThatWhenContextStartsShouldReturnAssertions() throws Exception { public void assertThatWhenContextStartsShouldReturnAssertions() throws Exception {
AssertProviderApplicationContext<ApplicationContext> context = get( ApplicationContextAssertProvider<ApplicationContext> context = get(
this.mockContextSupplier); this.mockContextSupplier);
ApplicationContextAssert<ApplicationContext> contextAssert = assertThat(context); ApplicationContextAssert<ApplicationContext> contextAssert = assertThat(context);
assertThat(contextAssert.getApplicationContext()).isSameAs(context); assertThat(contextAssert.getApplicationContext()).isSameAs(context);
...@@ -184,7 +184,7 @@ public class AssertProviderApplicationContextTests { ...@@ -184,7 +184,7 @@ public class AssertProviderApplicationContextTests {
@Test @Test
public void assertThatWhenContextFailsShouldReturnAssertions() throws Exception { public void assertThatWhenContextFailsShouldReturnAssertions() throws Exception {
AssertProviderApplicationContext<ApplicationContext> context = get( ApplicationContextAssertProvider<ApplicationContext> context = get(
this.startupFailureSupplier); this.startupFailureSupplier);
ApplicationContextAssert<ApplicationContext> contextAssert = assertThat(context); ApplicationContextAssert<ApplicationContext> contextAssert = assertThat(context);
assertThat(contextAssert.getApplicationContext()).isSameAs(context); assertThat(contextAssert.getApplicationContext()).isSameAs(context);
...@@ -193,7 +193,7 @@ public class AssertProviderApplicationContextTests { ...@@ -193,7 +193,7 @@ public class AssertProviderApplicationContextTests {
@Test @Test
public void toStringWhenContextStartsShouldReturnSimpleString() throws Exception { public void toStringWhenContextStartsShouldReturnSimpleString() throws Exception {
AssertProviderApplicationContext<ApplicationContext> context = get( ApplicationContextAssertProvider<ApplicationContext> context = get(
this.mockContextSupplier); this.mockContextSupplier);
assertThat(context.toString()) assertThat(context.toString())
.startsWith( .startsWith(
...@@ -204,7 +204,7 @@ public class AssertProviderApplicationContextTests { ...@@ -204,7 +204,7 @@ public class AssertProviderApplicationContextTests {
@Test @Test
public void toStringWhenContextFailsToStartShouldReturnSimpleString() public void toStringWhenContextFailsToStartShouldReturnSimpleString()
throws Exception { throws Exception {
AssertProviderApplicationContext<ApplicationContext> context = get( ApplicationContextAssertProvider<ApplicationContext> context = get(
this.startupFailureSupplier); this.startupFailureSupplier);
assertThat(context.toString()).isEqualTo("Unstarted application context " assertThat(context.toString()).isEqualTo("Unstarted application context "
+ "org.springframework.context.ApplicationContext" + "org.springframework.context.ApplicationContext"
...@@ -213,7 +213,7 @@ public class AssertProviderApplicationContextTests { ...@@ -213,7 +213,7 @@ public class AssertProviderApplicationContextTests {
@Test @Test
public void closeShouldCloseContext() throws Exception { public void closeShouldCloseContext() throws Exception {
AssertProviderApplicationContext<ApplicationContext> context = get( ApplicationContextAssertProvider<ApplicationContext> context = get(
this.mockContextSupplier); this.mockContextSupplier);
context.close(); context.close();
verify(this.mockContext).close(); verify(this.mockContext).close();
...@@ -225,15 +225,15 @@ public class AssertProviderApplicationContextTests { ...@@ -225,15 +225,15 @@ public class AssertProviderApplicationContextTests {
this.thrown.expectCause(equalTo(this.startupFailure)); this.thrown.expectCause(equalTo(this.startupFailure));
} }
private AssertProviderApplicationContext<ApplicationContext> get( private ApplicationContextAssertProvider<ApplicationContext> get(
Supplier<ApplicationContext> contextSupplier) { Supplier<ApplicationContext> contextSupplier) {
return AssertProviderApplicationContext.get( return ApplicationContextAssertProvider.get(
TestAssertProviderApplicationContext.class, ApplicationContext.class, TestAssertProviderApplicationContext.class, ApplicationContext.class,
contextSupplier); contextSupplier);
} }
private interface TestAssertProviderApplicationContext private interface TestAssertProviderApplicationContext
extends AssertProviderApplicationContext<ApplicationContext> { extends ApplicationContextAssertProvider<ApplicationContext> {
} }
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.test.context; package org.springframework.boot.test.context.assertj;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.test.context; package org.springframework.boot.test.context.assertj;
import org.junit.Test; import org.junit.Test;
...@@ -27,7 +27,7 @@ import static org.mockito.Mockito.mock; ...@@ -27,7 +27,7 @@ import static org.mockito.Mockito.mock;
* Tests for {@link AssertableApplicationContext}. * Tests for {@link AssertableApplicationContext}.
* *
* @author Phillip Webb * @author Phillip Webb
* @see AssertProviderApplicationContextTests * @see ApplicationContextAssertProviderTests
*/ */
public class AssertableApplicationContextTests { public class AssertableApplicationContextTests {
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.test.context; package org.springframework.boot.test.context.assertj;
import org.junit.Test; import org.junit.Test;
...@@ -27,7 +27,7 @@ import static org.mockito.Mockito.mock; ...@@ -27,7 +27,7 @@ import static org.mockito.Mockito.mock;
* Tests for {@link AssertableReactiveWebApplicationContext}. * Tests for {@link AssertableReactiveWebApplicationContext}.
* *
* @author Phillip Webb * @author Phillip Webb
* @see AssertProviderApplicationContextTests * @see ApplicationContextAssertProviderTests
*/ */
public class AssertableReactiveWebApplicationContextTests { public class AssertableReactiveWebApplicationContextTests {
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.test.context; package org.springframework.boot.test.context.assertj;
import org.junit.Test; import org.junit.Test;
...@@ -27,7 +27,7 @@ import static org.mockito.Mockito.mock; ...@@ -27,7 +27,7 @@ import static org.mockito.Mockito.mock;
* Tests for {@link AssertableWebApplicationContext}. * Tests for {@link AssertableWebApplicationContext}.
* *
* @author Phillip Webb * @author Phillip Webb
* @see AssertProviderApplicationContextTests * @see ApplicationContextAssertProviderTests
*/ */
public class AssertableWebApplicationContextTests { public class AssertableWebApplicationContextTests {
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.test.context; package org.springframework.boot.test.context.runner;
import java.util.UUID; import java.util.UUID;
...@@ -24,6 +24,8 @@ import org.junit.Test; ...@@ -24,6 +24,8 @@ import org.junit.Test;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;
import org.springframework.boot.context.annotation.UserConfigurations; import org.springframework.boot.context.annotation.UserConfigurations;
import org.springframework.boot.test.context.HidePackagesClassLoader;
import org.springframework.boot.test.context.assertj.ApplicationContextAssertProvider;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -34,18 +36,18 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -34,18 +36,18 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail; import static org.assertj.core.api.Assertions.fail;
/** /**
* Abstract tests for {@link AbstractApplicationContextTester} implementations. * Abstract tests for {@link AbstractApplicationContextRunner} implementations.
* *
* @param <T> The tester type * @param <T> The runner type
* @param <C> the context type * @param <C> the context type
* @param <A> the assertable context type * @param <A> the assertable context type
* @author Stephane Nicoll * @author Stephane Nicoll
* @author Phillip Webb * @author Phillip Webb
*/ */
public abstract class AbstractApplicationContextTesterTests<T extends AbstractApplicationContextTester<T, C, A>, C extends ConfigurableApplicationContext, A extends AssertProviderApplicationContext<C>> { public abstract class AbstractApplicationContextRunnerTests<T extends AbstractApplicationContextRunner<T, C, A>, C extends ConfigurableApplicationContext, A extends ApplicationContextAssertProvider<C>> {
@Rule @Rule
public final ExpectedException thrown = ExpectedException.none(); public ExpectedException thrown = ExpectedException.none();
@Test @Test
public void runWithSystemPropertiesShouldSetAndRemoveProperties() { public void runWithSystemPropertiesShouldSetAndRemoveProperties() {
...@@ -93,7 +95,7 @@ public abstract class AbstractApplicationContextTesterTests<T extends AbstractAp ...@@ -93,7 +95,7 @@ public abstract class AbstractApplicationContextTesterTests<T extends AbstractAp
System.setProperty(key, "value"); System.setProperty(key, "value");
try { try {
assertThat(System.getProperties().getProperty(key)).isEqualTo("value"); assertThat(System.getProperties().getProperty(key)).isEqualTo("value");
get().withSystemProperty(key, null).run((loaded) -> { get().withSystemProperties(key + "=").run((loaded) -> {
assertThat(System.getProperties()).doesNotContainKey(key); assertThat(System.getProperties()).doesNotContainKey(key);
}); });
assertThat(System.getProperties().getProperty(key)).isEqualTo("value"); assertThat(System.getProperties().getProperty(key)).isEqualTo("value");
......
...@@ -14,22 +14,23 @@ ...@@ -14,22 +14,23 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.test.context; package org.springframework.boot.test.context.runner;
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
/** /**
* Tests for {@link ApplicationContextTester}. * Tests for {@link ApplicationContextRunner}.
* *
* @author Stephane Nicoll * @author Stephane Nicoll
* @author Phillip Webb * @author Phillip Webb
*/ */
public class ApplicationContextTesterTests extends public class ApplicationContextRunnerTests extends
AbstractApplicationContextTesterTests<ApplicationContextTester, ConfigurableApplicationContext, AssertableApplicationContext> { AbstractApplicationContextRunnerTests<ApplicationContextRunner, ConfigurableApplicationContext, AssertableApplicationContext> {
@Override @Override
protected ApplicationContextTester get() { protected ApplicationContextRunner get() {
return new ApplicationContextTester(); return new ApplicationContextRunner();
} }
} }
...@@ -14,22 +14,23 @@ ...@@ -14,22 +14,23 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.test.context; package org.springframework.boot.test.context.runner;
import org.springframework.boot.test.context.assertj.AssertableReactiveWebApplicationContext;
import org.springframework.boot.web.reactive.context.ConfigurableReactiveWebApplicationContext; import org.springframework.boot.web.reactive.context.ConfigurableReactiveWebApplicationContext;
/** /**
* Tests for {@link ReactiveWebApplicationContextTester}. * Tests for {@link ReactiveWebApplicationContextRunner}.
* *
* @author Stephane Nicoll * @author Stephane Nicoll
* @author Phillip Webb * @author Phillip Webb
*/ */
public class ReactiveWebApplicationContextTesterTests extends public class ReactiveWebApplicationContextRunnerTests extends
AbstractApplicationContextTesterTests<ReactiveWebApplicationContextTester, ConfigurableReactiveWebApplicationContext, AssertableReactiveWebApplicationContext> { AbstractApplicationContextRunnerTests<ReactiveWebApplicationContextRunner, ConfigurableReactiveWebApplicationContext, AssertableReactiveWebApplicationContext> {
@Override @Override
protected ReactiveWebApplicationContextTester get() { protected ReactiveWebApplicationContextRunner get() {
return new ReactiveWebApplicationContextTester(); return new ReactiveWebApplicationContextRunner();
} }
} }
...@@ -14,23 +14,24 @@ ...@@ -14,23 +14,24 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.test.context; package org.springframework.boot.test.context.runner;
import org.junit.Test; import org.junit.Test;
import org.springframework.boot.test.context.assertj.AssertableWebApplicationContext;
import org.springframework.mock.web.MockServletContext; import org.springframework.mock.web.MockServletContext;
import org.springframework.web.context.ConfigurableWebApplicationContext; import org.springframework.web.context.ConfigurableWebApplicationContext;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Tests for {@link WebApplicationContextTester}. * Tests for {@link WebApplicationContextRunner}.
* *
* @author Stephane Nicoll * @author Stephane Nicoll
* @author Phillip Webb * @author Phillip Webb
*/ */
public class WebApplicationContextTesterTests extends public class WebApplicationContextRunnerTests extends
AbstractApplicationContextTesterTests<WebApplicationContextTester, ConfigurableWebApplicationContext, AssertableWebApplicationContext> { AbstractApplicationContextRunnerTests<WebApplicationContextRunner, ConfigurableWebApplicationContext, AssertableWebApplicationContext> {
@Test @Test
public void contextShouldHaveMockServletContext() throws Exception { public void contextShouldHaveMockServletContext() throws Exception {
...@@ -39,8 +40,8 @@ public class WebApplicationContextTesterTests extends ...@@ -39,8 +40,8 @@ public class WebApplicationContextTesterTests extends
} }
@Override @Override
protected WebApplicationContextTester get() { protected WebApplicationContextRunner get() {
return new WebApplicationContextTester(); return new WebApplicationContextRunner();
} }
} }
...@@ -89,8 +89,8 @@ public class TestPropertyValuesTests { ...@@ -89,8 +89,8 @@ public class TestPropertyValuesTests {
@Test @Test
public void andShouldChainAndAddSingleKeyValue() throws Exception { public void andShouldChainAndAddSingleKeyValue() throws Exception {
TestPropertyValues.of("foo.bar=baz").and("hello.world", "hi") TestPropertyValues.of("foo.bar=baz").and("hello.world=hi").and("bling.blah=bing")
.and("bling.blah", "bing").applyTo(this.environment, Type.MAP); .applyTo(this.environment, Type.MAP);
assertThat(this.environment.getProperty("foo.bar")).isEqualTo("baz"); assertThat(this.environment.getProperty("foo.bar")).isEqualTo("baz");
assertThat(this.environment.getProperty("hello.world")).isEqualTo("hi"); assertThat(this.environment.getProperty("hello.world")).isEqualTo("hi");
assertThat(this.environment.getProperty("bling.blah")).isEqualTo("bing"); assertThat(this.environment.getProperty("bling.blah")).isEqualTo("bing");
...@@ -127,7 +127,7 @@ public class TestPropertyValuesTests { ...@@ -127,7 +127,7 @@ public class TestPropertyValuesTests {
throws Exception { throws Exception {
System.setProperty("foo", "bar1"); System.setProperty("foo", "bar1");
try { try {
TestPropertyValues.ofPair("foo", null).applyToSystemProperties(() -> { TestPropertyValues.of("foo").applyToSystemProperties(() -> {
assertThat(System.getProperties()).doesNotContainKey("foo"); assertThat(System.getProperties()).doesNotContainKey("foo");
return null; return null;
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment