Commit 497457c3 authored by Phillip Webb's avatar Phillip Webb

Rename ApplicationContextTester -> Runner

Rename `ApplicationContextTester` and related classes to
`ApplicationContextRunner` and refactor existing tests to use correctly
named variables.

See gh-9875
parent 56169156
...@@ -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.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.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.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.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,7 +25,7 @@ import retrofit2.Retrofit; ...@@ -25,7 +25,7 @@ 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.ApplicationContextRunner;
import org.springframework.boot.test.context.AssertableApplicationContext; import org.springframework.boot.test.context.AssertableApplicationContext;
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,7 +39,7 @@ import org.springframework.beans.factory.BeanCreationException; ...@@ -39,7 +39,7 @@ 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.ApplicationContextRunner;
import org.springframework.boot.test.context.AssertableApplicationContext; import org.springframework.boot.test.context.AssertableApplicationContext;
import org.springframework.boot.test.context.HidePackagesClassLoader; import org.springframework.boot.test.context.HidePackagesClassLoader;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
...@@ -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));
}); });
......
...@@ -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.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();
}); });
} }
......
...@@ -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.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.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.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,24 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -38,24 +38,24 @@ 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.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.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"));
}); });
} }
......
...@@ -34,13 +34,13 @@ import org.springframework.util.Assert; ...@@ -34,13 +34,13 @@ import org.springframework.util.Assert;
import org.springframework.util.ReflectionUtils; import org.springframework.util.ReflectionUtils;
/** /**
* Tester utility design to manage the lifecycle of an {@link ApplicationContext} and * Utility design to run and an {@link ApplicationContext} and provide AssertJ style
* provide AssertJ style assertions. The test is best used as a field of a test class, * assertions. The test is best used as a field of a test class, describing the shared
* describing the shared configuration required for the test: * configuration required for the test:
* *
* <pre class="code"> * <pre class="code">
* public class MyContextTests { * public class MyContextTests {
* private final ApplicationContextTester context = new ApplicationContextTester() * private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
* .withPropertyValues("spring.foo=bar") * .withPropertyValues("spring.foo=bar")
* .withUserConfiguration(MyConfiguration.class); * .withUserConfiguration(MyConfiguration.class);
* }</pre> * }</pre>
...@@ -55,8 +55,8 @@ import org.springframework.util.ReflectionUtils; ...@@ -55,8 +55,8 @@ import org.springframework.util.ReflectionUtils;
* <pre class="code"> * <pre class="code">
* &#064;Test * &#064;Test
* public someTest() { * public someTest() {
* this.context.withPropertyValues("spring.foo=biz").run((loaded) -&gt; { * this.contextRunner.withPropertyValues("spring.foo=biz").run((context) -&gt; {
* assertThat(loaded).containsSingleBean(MyBean.class); * assertThat(context).containsSingleBean(MyBean.class);
* // other assertions * // other assertions
* }); * });
* }</pre> * }</pre>
...@@ -80,19 +80,19 @@ import org.springframework.util.ReflectionUtils; ...@@ -80,19 +80,19 @@ import org.springframework.util.ReflectionUtils;
* }</pre> * }</pre>
* <p> * <p>
* *
* @param <SELF> The "self" type for this tester * @param <SELF> The "self" type for this runner
* @param <C> The context type * @param <C> The context type
* @param <A> The application context assertion provider * @param <A> The application context assertion provider
* @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
* @see ApplicationContextTester * @see ApplicationContextRunner
* @see WebApplicationContextTester * @see WebApplicationContextRunner
* @see ReactiveWebApplicationContextTester * @see ReactiveWebApplicationContextRunner
* @see ApplicationContextAssert * @see ApplicationContextAssert
*/ */
abstract class AbstractApplicationContextTester<SELF extends AbstractApplicationContextTester<SELF, C, A>, C extends ConfigurableApplicationContext, A extends AssertProviderApplicationContext<C>> { abstract class AbstractApplicationContextRunner<SELF extends AbstractApplicationContextRunner<SELF, C, A>, C extends ConfigurableApplicationContext, A extends AssertProviderApplicationContext<C>> {
private final Supplier<C> contextFactory; private final Supplier<C> contextFactory;
...@@ -107,10 +107,10 @@ abstract class AbstractApplicationContextTester<SELF extends AbstractApplication ...@@ -107,10 +107,10 @@ abstract class AbstractApplicationContextTester<SELF extends AbstractApplication
private final List<Configurations> configurations = new ArrayList<>(); private final List<Configurations> configurations = new ArrayList<>();
/** /**
* Create a new {@link AbstractApplicationContextTester} instance. * Create a new {@link AbstractApplicationContextRunner} instance.
* @param contextFactory the factory used to create the actual context * @param contextFactory the factory used to create the actual context
*/ */
protected AbstractApplicationContextTester(Supplier<C> contextFactory) { protected AbstractApplicationContextRunner(Supplier<C> contextFactory) {
Assert.notNull(contextFactory, "ContextFactory must not be null"); Assert.notNull(contextFactory, "ContextFactory must not be null");
this.contextFactory = contextFactory; this.contextFactory = contextFactory;
this.environmentProperties = TestPropertyValues.empty(); this.environmentProperties = TestPropertyValues.empty();
...@@ -243,7 +243,7 @@ abstract class AbstractApplicationContextTester<SELF extends AbstractApplication ...@@ -243,7 +243,7 @@ abstract class AbstractApplicationContextTester<SELF extends AbstractApplication
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private A createAssertableContext() { private A createAssertableContext() {
ResolvableType resolvableType = ResolvableType ResolvableType resolvableType = ResolvableType
.forClass(AbstractApplicationContextTester.class, getClass()); .forClass(AbstractApplicationContextRunner.class, getClass());
Class<A> assertType = (Class<A>) resolvableType.resolveGeneric(1); Class<A> assertType = (Class<A>) resolvableType.resolveGeneric(1);
Class<C> contextType = (Class<C>) resolvableType.resolveGeneric(2); Class<C> contextType = (Class<C>) resolvableType.resolveGeneric(2);
return AssertProviderApplicationContext.get(assertType, contextType, return AssertProviderApplicationContext.get(assertType, contextType,
......
...@@ -37,7 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -37,7 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @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>
......
...@@ -22,33 +22,33 @@ import org.springframework.context.ConfigurableApplicationContext; ...@@ -22,33 +22,33 @@ 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);
} }
......
...@@ -30,7 +30,7 @@ import org.springframework.context.ConfigurableApplicationContext; ...@@ -30,7 +30,7 @@ import org.springframework.context.ConfigurableApplicationContext;
* *
* @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
......
...@@ -30,7 +30,7 @@ import org.springframework.web.context.WebApplicationContext; ...@@ -30,7 +30,7 @@ import org.springframework.web.context.WebApplicationContext;
* *
* @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
......
...@@ -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> {
......
...@@ -22,33 +22,33 @@ import org.springframework.boot.web.reactive.context.ConfigurableReactiveWebAppl ...@@ -22,33 +22,33 @@ import org.springframework.boot.web.reactive.context.ConfigurableReactiveWebAppl
import org.springframework.boot.web.reactive.context.GenericReactiveWebApplicationContext; import org.springframework.boot.web.reactive.context.GenericReactiveWebApplicationContext;
/** /**
* 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);
} }
......
...@@ -24,35 +24,35 @@ import org.springframework.web.context.WebApplicationContext; ...@@ -24,35 +24,35 @@ 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);
} }
......
...@@ -34,15 +34,15 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -34,15 +34,15 @@ 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 AssertProviderApplicationContext<C>> {
@Rule @Rule
public final ExpectedException thrown = ExpectedException.none(); public final ExpectedException thrown = ExpectedException.none();
......
...@@ -19,17 +19,17 @@ package org.springframework.boot.test.context; ...@@ -19,17 +19,17 @@ package org.springframework.boot.test.context;
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();
} }
} }
...@@ -19,17 +19,17 @@ package org.springframework.boot.test.context; ...@@ -19,17 +19,17 @@ package org.springframework.boot.test.context;
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();
} }
} }
...@@ -24,13 +24,13 @@ import org.springframework.web.context.ConfigurableWebApplicationContext; ...@@ -24,13 +24,13 @@ 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 +39,8 @@ public class WebApplicationContextTesterTests extends ...@@ -39,8 +39,8 @@ public class WebApplicationContextTesterTests extends
} }
@Override @Override
protected WebApplicationContextTester get() { protected WebApplicationContextRunner get() {
return new WebApplicationContextTester(); return new WebApplicationContextRunner();
} }
} }
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