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

@@ -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;