Restructure boot.test.context package

Split up `org.springframework.boot.test.context` into distinct packages
for `runner` and `assertj`.

See gh-9875
This commit is contained in:
Phillip Webb
2017-07-26 13:49:54 -07:00
parent 497457c397
commit 07556cda51
38 changed files with 145 additions and 91 deletions

View File

@@ -60,9 +60,9 @@ import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
import org.springframework.boot.autoconfigure.solr.SolrAutoConfiguration;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.context.ApplicationContextRunner;
import org.springframework.boot.test.context.AssertableApplicationContext;
import org.springframework.boot.test.context.ContextConsumer;
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.boot.test.context.runner.ContextConsumer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.cassandra.core.CassandraOperations;

View File

@@ -54,9 +54,9 @@ import org.springframework.beans.factory.BeanCreationException;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.cache.support.MockCachingProvider;
import org.springframework.boot.autoconfigure.hazelcast.HazelcastAutoConfiguration;
import org.springframework.boot.test.context.ApplicationContextRunner;
import org.springframework.boot.test.context.AssertableApplicationContext;
import org.springframework.boot.test.context.ContextConsumer;
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.boot.test.context.runner.ContextConsumer;
import org.springframework.boot.testsupport.runner.classpath.ClassPathExclusions;
import org.springframework.boot.testsupport.runner.classpath.ModifiedClassPathRunner;
import org.springframework.cache.Cache;

View File

@@ -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.domain.EntityScan;
import org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration;
import org.springframework.boot.test.context.WebApplicationContextRunner;
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

View File

@@ -30,7 +30,7 @@ import org.junit.Test;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.ApplicationContextRunner;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

View File

@@ -28,7 +28,7 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.ApplicationContextRunner;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.boot.testsupport.runner.classpath.ClassPathExclusions;
import org.springframework.boot.testsupport.runner.classpath.ModifiedClassPathRunner;
import org.springframework.context.annotation.Bean;

View File

@@ -23,7 +23,7 @@ import com.hazelcast.core.HazelcastInstance;
import org.junit.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.ApplicationContextRunner;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.core.io.ClassPathResource;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -25,8 +25,8 @@ import retrofit2.Retrofit;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.ApplicationContextRunner;
import org.springframework.boot.test.context.AssertableApplicationContext;
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.Configuration;

View File

@@ -39,9 +39,9 @@ import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.jdbc.DatabaseDriver;
import org.springframework.boot.test.context.ApplicationContextRunner;
import org.springframework.boot.test.context.AssertableApplicationContext;
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.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;

View File

@@ -28,8 +28,8 @@ import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.jms.activemq.ActiveMQAutoConfiguration;
import org.springframework.boot.test.context.ApplicationContextRunner;
import org.springframework.boot.test.context.AssertableApplicationContext;
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.Configuration;
import org.springframework.context.annotation.Primary;

View File

@@ -25,7 +25,7 @@ import org.junit.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration;
import org.springframework.boot.test.context.ApplicationContextRunner;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

View File

@@ -42,7 +42,7 @@ import org.junit.rules.TemporaryFolder;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration;
import org.springframework.boot.test.context.ApplicationContextRunner;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

View File

@@ -19,7 +19,7 @@ package org.springframework.boot.autoconfigure.web.reactive;
import org.junit.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.ReactiveWebApplicationContextRunner;
import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.server.reactive.HttpHandler;

View File

@@ -38,9 +38,9 @@ import org.springframework.boot.autoconfigure.validation.ValidationAutoConfigura
import org.springframework.boot.autoconfigure.validation.ValidatorAdapter;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration.WelcomePageHandlerMapping;
import org.springframework.boot.test.context.AssertableWebApplicationContext;
import org.springframework.boot.test.context.ContextConsumer;
import org.springframework.boot.test.context.WebApplicationContextRunner;
import org.springframework.boot.test.context.assertj.AssertableWebApplicationContext;
import org.springframework.boot.test.context.runner.ContextConsumer;
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
import org.springframework.boot.web.server.WebServerFactoryCustomizerBeanPostProcessor;
import org.springframework.boot.web.servlet.filter.OrderedHttpPutFormContentFilter;
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;

View File

@@ -24,7 +24,7 @@ import org.junit.rules.ExpectedException;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.WebApplicationContextRunner;
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.ApplicationContext;
import org.springframework.test.util.ReflectionTestUtils;

View File

@@ -21,7 +21,7 @@ import javax.sql.DataSource;
import org.junit.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.ApplicationContextRunner;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;

View File

@@ -24,7 +24,7 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfiguration;
import org.springframework.boot.test.context.ApplicationContextRunner;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.boot.testsupport.runner.classpath.ClassPathExclusions;
import org.springframework.boot.testsupport.runner.classpath.ModifiedClassPathRunner;
import org.springframework.context.annotation.Bean;

View File

@@ -14,7 +14,7 @@
* 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.AbstractObjectArrayAssert;
@@ -25,13 +25,14 @@ import org.assertj.core.api.MapAssert;
import org.assertj.core.error.BasicErrorMessageFactory;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.ApplicationContext;
import org.springframework.util.Assert;
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}.
*
* @param <C> The application context type

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.test.context;
package org.springframework.boot.test.context.assertj;
import java.io.Closeable;
import java.lang.reflect.Proxy;
@@ -48,7 +48,7 @@ import org.springframework.util.Assert;
* @see AssertableReactiveWebApplicationContext
* @see ApplicationContextAssert
*/
interface AssertProviderApplicationContext<C extends ApplicationContext> extends
public interface ApplicationContextAssertProvider<C extends ApplicationContext> extends
ApplicationContext, AssertProvider<ApplicationContextAssert<C>>, Closeable {
/**
@@ -88,19 +88,19 @@ interface AssertProviderApplicationContext<C extends ApplicationContext> extends
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 <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)
* @param contextType the type of {@link ApplicationContext} being managed (must be an
* interface)
* @param contextSupplier a supplier that will either return a fully configured
* {@link ApplicationContext} or throw an exception if the context fails to start.
* @return a {@link AssertProviderApplicationContext} instance
* @return a {@link ApplicationContextAssertProvider} instance
*/
@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,
Supplier<? extends C> contextSupplier) {
Assert.notNull(type, "Type must not be null");

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.test.context;
package org.springframework.boot.test.context.assertj;
import java.io.Closeable;
import java.io.IOException;
@@ -31,7 +31,7 @@ import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
/**
* {@link InvocationHandler} used by {@link AssertProviderApplicationContext} generated
* {@link InvocationHandler} used by {@link ApplicationContextAssertProvider} generated
* proxies.
*
* @author Phillip Webb

View File

@@ -14,10 +14,11 @@
* limitations under the License.
*/
package org.springframework.boot.test.context;
package org.springframework.boot.test.context.assertj;
import java.util.function.Supplier;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
@@ -26,7 +27,7 @@ import org.springframework.context.ConfigurableApplicationContext;
* be used to decorate and existing application context or an application context that
* failed to start.
* <p>
* See {@link AssertProviderApplicationContext} for more details.
* See {@link ApplicationContextAssertProvider} for more details.
*
* @author Phillip Webb
* @since 2.0.0
@@ -34,7 +35,7 @@ import org.springframework.context.ConfigurableApplicationContext;
* @see ApplicationContext
*/
public interface AssertableApplicationContext
extends AssertProviderApplicationContext<ConfigurableApplicationContext> {
extends ApplicationContextAssertProvider<ConfigurableApplicationContext> {
/**
* Factory method to create a new {@link AssertableApplicationContext} instance.
@@ -45,7 +46,7 @@ public interface AssertableApplicationContext
*/
static AssertableApplicationContext get(
Supplier<? extends ConfigurableApplicationContext> contextSupplier) {
return AssertProviderApplicationContext.get(AssertableApplicationContext.class,
return ApplicationContextAssertProvider.get(AssertableApplicationContext.class,
ConfigurableApplicationContext.class, contextSupplier);
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.test.context;
package org.springframework.boot.test.context.assertj;
import java.util.function.Supplier;
@@ -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
* application context that failed to start.
* <p>
* See {@link AssertProviderApplicationContext} for more details.
* See {@link ApplicationContextAssertProvider} for more details.
*
* @author Phillip Webb
* @since 2.0.0
@@ -34,7 +34,7 @@ import org.springframework.boot.web.reactive.context.ReactiveWebApplicationConte
* @see ReactiveWebApplicationContext
*/
public interface AssertableReactiveWebApplicationContext extends
AssertProviderApplicationContext<ConfigurableReactiveWebApplicationContext>,
ApplicationContextAssertProvider<ConfigurableReactiveWebApplicationContext>,
ReactiveWebApplicationContext {
/**
@@ -47,7 +47,7 @@ public interface AssertableReactiveWebApplicationContext extends
*/
static AssertableReactiveWebApplicationContext get(
Supplier<? extends ConfigurableReactiveWebApplicationContext> contextSupplier) {
return AssertProviderApplicationContext.get(
return ApplicationContextAssertProvider.get(
AssertableReactiveWebApplicationContext.class,
ConfigurableReactiveWebApplicationContext.class, contextSupplier);
}

View File

@@ -14,10 +14,11 @@
* limitations under the License.
*/
package org.springframework.boot.test.context;
package org.springframework.boot.test.context.assertj;
import java.util.function.Supplier;
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
import org.springframework.web.context.ConfigurableWebApplicationContext;
import org.springframework.web.context.WebApplicationContext;
@@ -26,7 +27,7 @@ import org.springframework.web.context.WebApplicationContext;
* Can be used to decorate and existing servlet web application context or an application
* context that failed to start.
* <p>
* See {@link AssertProviderApplicationContext} for more details.
* See {@link ApplicationContextAssertProvider} for more details.
*
* @author Phillip Webb
* @since 2.0.0
@@ -34,7 +35,7 @@ import org.springframework.web.context.WebApplicationContext;
* @see WebApplicationContext
*/
public interface AssertableWebApplicationContext
extends AssertProviderApplicationContext<ConfigurableWebApplicationContext>,
extends ApplicationContextAssertProvider<ConfigurableWebApplicationContext>,
WebApplicationContext {
/**
@@ -46,7 +47,7 @@ public interface AssertableWebApplicationContext
*/
static AssertableWebApplicationContext get(
Supplier<? extends ConfigurableWebApplicationContext> contextSupplier) {
return AssertProviderApplicationContext.get(AssertableWebApplicationContext.class,
return ApplicationContextAssertProvider.get(AssertableWebApplicationContext.class,
ConfigurableWebApplicationContext.class, contextSupplier);
}

View File

@@ -0,0 +1,20 @@
/*
* 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;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.test.context;
package org.springframework.boot.test.context.runner;
import java.util.ArrayList;
import java.util.Arrays;
@@ -23,6 +23,9 @@ import java.util.function.Supplier;
import org.springframework.boot.context.annotation.Configurations;
import org.springframework.boot.context.annotation.UserConfigurations;
import org.springframework.boot.test.context.HidePackagesClassLoader;
import org.springframework.boot.test.context.assertj.ApplicationContextAssert;
import org.springframework.boot.test.context.assertj.ApplicationContextAssertProvider;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
@@ -92,7 +95,7 @@ import org.springframework.util.ReflectionUtils;
* @see ReactiveWebApplicationContextRunner
* @see ApplicationContextAssert
*/
abstract class AbstractApplicationContextRunner<SELF extends AbstractApplicationContextRunner<SELF, C, A>, C extends ConfigurableApplicationContext, A extends AssertProviderApplicationContext<C>> {
abstract class AbstractApplicationContextRunner<SELF extends AbstractApplicationContextRunner<SELF, C, A>, C extends ConfigurableApplicationContext, A extends ApplicationContextAssertProvider<C>> {
private final Supplier<C> contextFactory;
@@ -246,7 +249,7 @@ abstract class AbstractApplicationContextRunner<SELF extends AbstractApplication
.forClass(AbstractApplicationContextRunner.class, getClass());
Class<A> assertType = (Class<A>) resolvableType.resolveGeneric(1);
Class<C> contextType = (Class<C>) resolvableType.resolveGeneric(2);
return AssertProviderApplicationContext.get(assertType, contextType,
return ApplicationContextAssertProvider.get(assertType, contextType,
this::createAndLoadContext);
}

View File

@@ -14,10 +14,11 @@
* limitations under the License.
*/
package org.springframework.boot.test.context;
package org.springframework.boot.test.context.runner;
import java.util.function.Supplier;
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.test.context;
package org.springframework.boot.test.context.runner;
import org.springframework.context.ApplicationContext;

View File

@@ -14,10 +14,11 @@
* limitations under the License.
*/
package org.springframework.boot.test.context;
package org.springframework.boot.test.context.runner;
import java.util.function.Supplier;
import org.springframework.boot.test.context.assertj.AssertableReactiveWebApplicationContext;
import org.springframework.boot.web.reactive.context.ConfigurableReactiveWebApplicationContext;
import org.springframework.boot.web.reactive.context.GenericReactiveWebApplicationContext;

View File

@@ -14,10 +14,11 @@
* limitations under the License.
*/
package org.springframework.boot.test.context;
package org.springframework.boot.test.context.runner;
import java.util.function.Supplier;
import org.springframework.boot.test.context.assertj.AssertableWebApplicationContext;
import org.springframework.mock.web.MockServletContext;
import org.springframework.web.context.ConfigurableWebApplicationContext;
import org.springframework.web.context.WebApplicationContext;

View File

@@ -0,0 +1,20 @@
/*
* 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;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.test.context;
package org.springframework.boot.test.context.assertj;
import java.util.function.Supplier;
@@ -34,12 +34,12 @@ import static org.hamcrest.Matchers.equalTo;
import static org.mockito.Mockito.verify;
/**
* Tests for {@link AssertProviderApplicationContext} and
* Tests for {@link ApplicationContextAssertProvider} and
* {@link AssertProviderApplicationContextInvocationHandler}.
*
* @author Phillip Webb
*/
public class AssertProviderApplicationContextTests {
public class ApplicationContextAssertProviderTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
@@ -67,7 +67,7 @@ public class AssertProviderApplicationContextTests {
public void getWhenTypeIsNullShouldThrowException() throws Exception {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Type must not be null");
AssertProviderApplicationContext.get(null, ApplicationContext.class,
ApplicationContextAssertProvider.get(null, ApplicationContext.class,
this.mockContextSupplier);
}
@@ -75,7 +75,7 @@ public class AssertProviderApplicationContextTests {
public void getWhenTypeIsClassShouldThrowException() throws Exception {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Type must not be null");
AssertProviderApplicationContext.get(null, ApplicationContext.class,
ApplicationContextAssertProvider.get(null, ApplicationContext.class,
this.mockContextSupplier);
}
@@ -83,7 +83,7 @@ public class AssertProviderApplicationContextTests {
public void getWhenContextTypeIsNullShouldThrowException() throws Exception {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Type must be an interface");
AssertProviderApplicationContext.get(
ApplicationContextAssertProvider.get(
TestAssertProviderApplicationContextClass.class, ApplicationContext.class,
this.mockContextSupplier);
}
@@ -92,7 +92,7 @@ public class AssertProviderApplicationContextTests {
public void getWhenContextTypeIsClassShouldThrowException() throws Exception {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("ContextType must not be null");
AssertProviderApplicationContext.get(TestAssertProviderApplicationContext.class,
ApplicationContextAssertProvider.get(TestAssertProviderApplicationContext.class,
null, this.mockContextSupplier);
}
@@ -100,14 +100,14 @@ public class AssertProviderApplicationContextTests {
public void getWhenSupplierIsNullShouldThrowException() throws Exception {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("ContextType must be an interface");
AssertProviderApplicationContext.get(TestAssertProviderApplicationContext.class,
ApplicationContextAssertProvider.get(TestAssertProviderApplicationContext.class,
StaticApplicationContext.class, this.mockContextSupplier);
}
@Test
public void getWhenContextStartsShouldReturnProxyThatCallsRealMethods()
throws Exception {
AssertProviderApplicationContext<ApplicationContext> context = get(
ApplicationContextAssertProvider<ApplicationContext> context = get(
this.mockContextSupplier);
assertThat((Object) context).isNotNull();
context.getBean("foo");
@@ -117,7 +117,7 @@ public class AssertProviderApplicationContextTests {
@Test
public void getWhenContextFailsShouldReturnProxyThatThrowsExceptions()
throws Exception {
AssertProviderApplicationContext<ApplicationContext> context = get(
ApplicationContextAssertProvider<ApplicationContext> context = get(
this.startupFailureSupplier);
assertThat((Object) context).isNotNull();
expectStartupFailure();
@@ -127,14 +127,14 @@ public class AssertProviderApplicationContextTests {
@Test
public void getSourceContextWhenContextStartsShouldReturnSourceContext()
throws Exception {
AssertProviderApplicationContext<ApplicationContext> context = get(
ApplicationContextAssertProvider<ApplicationContext> context = get(
this.mockContextSupplier);
assertThat(context.getSourceApplicationContext()).isSameAs(this.mockContext);
}
@Test
public void getSourceContextWhenContextFailsShouldThrowException() throws Exception {
AssertProviderApplicationContext<ApplicationContext> context = get(
ApplicationContextAssertProvider<ApplicationContext> context = get(
this.startupFailureSupplier);
expectStartupFailure();
context.getSourceApplicationContext();
@@ -143,7 +143,7 @@ public class AssertProviderApplicationContextTests {
@Test
public void getSourceContextOfTypeWhenContextStartsShouldReturnSourceContext()
throws Exception {
AssertProviderApplicationContext<ApplicationContext> context = get(
ApplicationContextAssertProvider<ApplicationContext> context = get(
this.mockContextSupplier);
assertThat(context.getSourceApplicationContext(ApplicationContext.class))
.isSameAs(this.mockContext);
@@ -152,7 +152,7 @@ public class AssertProviderApplicationContextTests {
@Test
public void getSourceContextOfTypeWhenContextFailsToStartShouldThrowException()
throws Exception {
AssertProviderApplicationContext<ApplicationContext> context = get(
ApplicationContextAssertProvider<ApplicationContext> context = get(
this.startupFailureSupplier);
expectStartupFailure();
context.getSourceApplicationContext(ApplicationContext.class);
@@ -160,7 +160,7 @@ public class AssertProviderApplicationContextTests {
@Test
public void getStartupFailureWhenContextStartsShouldReturnNull() throws Exception {
AssertProviderApplicationContext<ApplicationContext> context = get(
ApplicationContextAssertProvider<ApplicationContext> context = get(
this.mockContextSupplier);
assertThat(context.getStartupFailure()).isNull();
}
@@ -168,14 +168,14 @@ public class AssertProviderApplicationContextTests {
@Test
public void getStartupFailureWhenContextFailsToStartShouldReturnException()
throws Exception {
AssertProviderApplicationContext<ApplicationContext> context = get(
ApplicationContextAssertProvider<ApplicationContext> context = get(
this.startupFailureSupplier);
assertThat(context.getStartupFailure()).isEqualTo(this.startupFailure);
}
@Test
public void assertThatWhenContextStartsShouldReturnAssertions() throws Exception {
AssertProviderApplicationContext<ApplicationContext> context = get(
ApplicationContextAssertProvider<ApplicationContext> context = get(
this.mockContextSupplier);
ApplicationContextAssert<ApplicationContext> contextAssert = assertThat(context);
assertThat(contextAssert.getApplicationContext()).isSameAs(context);
@@ -184,7 +184,7 @@ public class AssertProviderApplicationContextTests {
@Test
public void assertThatWhenContextFailsShouldReturnAssertions() throws Exception {
AssertProviderApplicationContext<ApplicationContext> context = get(
ApplicationContextAssertProvider<ApplicationContext> context = get(
this.startupFailureSupplier);
ApplicationContextAssert<ApplicationContext> contextAssert = assertThat(context);
assertThat(contextAssert.getApplicationContext()).isSameAs(context);
@@ -193,7 +193,7 @@ public class AssertProviderApplicationContextTests {
@Test
public void toStringWhenContextStartsShouldReturnSimpleString() throws Exception {
AssertProviderApplicationContext<ApplicationContext> context = get(
ApplicationContextAssertProvider<ApplicationContext> context = get(
this.mockContextSupplier);
assertThat(context.toString())
.startsWith(
@@ -204,7 +204,7 @@ public class AssertProviderApplicationContextTests {
@Test
public void toStringWhenContextFailsToStartShouldReturnSimpleString()
throws Exception {
AssertProviderApplicationContext<ApplicationContext> context = get(
ApplicationContextAssertProvider<ApplicationContext> context = get(
this.startupFailureSupplier);
assertThat(context.toString()).isEqualTo("Unstarted application context "
+ "org.springframework.context.ApplicationContext"
@@ -213,7 +213,7 @@ public class AssertProviderApplicationContextTests {
@Test
public void closeShouldCloseContext() throws Exception {
AssertProviderApplicationContext<ApplicationContext> context = get(
ApplicationContextAssertProvider<ApplicationContext> context = get(
this.mockContextSupplier);
context.close();
verify(this.mockContext).close();
@@ -225,15 +225,15 @@ public class AssertProviderApplicationContextTests {
this.thrown.expectCause(equalTo(this.startupFailure));
}
private AssertProviderApplicationContext<ApplicationContext> get(
private ApplicationContextAssertProvider<ApplicationContext> get(
Supplier<ApplicationContext> contextSupplier) {
return AssertProviderApplicationContext.get(
return ApplicationContextAssertProvider.get(
TestAssertProviderApplicationContext.class, ApplicationContext.class,
contextSupplier);
}
private interface TestAssertProviderApplicationContext
extends AssertProviderApplicationContext<ApplicationContext> {
extends ApplicationContextAssertProvider<ApplicationContext> {
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.test.context;
package org.springframework.boot.test.context.assertj;
import org.junit.Rule;
import org.junit.Test;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.test.context;
package org.springframework.boot.test.context.assertj;
import org.junit.Test;
@@ -27,7 +27,7 @@ import static org.mockito.Mockito.mock;
* Tests for {@link AssertableApplicationContext}.
*
* @author Phillip Webb
* @see AssertProviderApplicationContextTests
* @see ApplicationContextAssertProviderTests
*/
public class AssertableApplicationContextTests {

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.test.context;
package org.springframework.boot.test.context.assertj;
import org.junit.Test;
@@ -27,7 +27,7 @@ import static org.mockito.Mockito.mock;
* Tests for {@link AssertableReactiveWebApplicationContext}.
*
* @author Phillip Webb
* @see AssertProviderApplicationContextTests
* @see ApplicationContextAssertProviderTests
*/
public class AssertableReactiveWebApplicationContextTests {

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.test.context;
package org.springframework.boot.test.context.assertj;
import org.junit.Test;
@@ -27,7 +27,7 @@ import static org.mockito.Mockito.mock;
* Tests for {@link AssertableWebApplicationContext}.
*
* @author Phillip Webb
* @see AssertProviderApplicationContextTests
* @see ApplicationContextAssertProviderTests
*/
public class AssertableWebApplicationContextTests {

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.test.context;
package org.springframework.boot.test.context.runner;
import java.util.UUID;
@@ -24,6 +24,8 @@ import org.junit.Test;
import org.junit.rules.ExpectedException;
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.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -42,10 +44,10 @@ import static org.assertj.core.api.Assertions.fail;
* @author Stephane Nicoll
* @author Phillip Webb
*/
public abstract class AbstractApplicationContextRunnerTests<T extends AbstractApplicationContextRunner<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
public final ExpectedException thrown = ExpectedException.none();
public ExpectedException thrown = ExpectedException.none();
@Test
public void runWithSystemPropertiesShouldSetAndRemoveProperties() {

View File

@@ -14,8 +14,9 @@
* 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;
/**

View File

@@ -14,8 +14,9 @@
* 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;
/**

View File

@@ -14,10 +14,11 @@
* limitations under the License.
*/
package org.springframework.boot.test.context;
package org.springframework.boot.test.context.runner;
import org.junit.Test;
import org.springframework.boot.test.context.assertj.AssertableWebApplicationContext;
import org.springframework.mock.web.MockServletContext;
import org.springframework.web.context.ConfigurableWebApplicationContext;