Rename ApplicationContextTester -> Runner
Rename `ApplicationContextTester` and related classes to `ApplicationContextRunner` and refactor existing tests to use correctly named variables. See gh-9875
This commit is contained in:
@@ -34,13 +34,13 @@ import org.springframework.util.Assert;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
/**
|
||||
* Tester utility design to manage the lifecycle of an {@link ApplicationContext} and
|
||||
* provide AssertJ style assertions. The test is best used as a field of a test class,
|
||||
* describing the shared configuration required for the test:
|
||||
* Utility design to run and an {@link ApplicationContext} and provide AssertJ style
|
||||
* assertions. The test is best used as a field of a test class, describing the shared
|
||||
* configuration required for the test:
|
||||
*
|
||||
* <pre class="code">
|
||||
* public class MyContextTests {
|
||||
* private final ApplicationContextTester context = new ApplicationContextTester()
|
||||
* private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
* .withPropertyValues("spring.foo=bar")
|
||||
* .withUserConfiguration(MyConfiguration.class);
|
||||
* }</pre>
|
||||
@@ -55,8 +55,8 @@ import org.springframework.util.ReflectionUtils;
|
||||
* <pre class="code">
|
||||
* @Test
|
||||
* public someTest() {
|
||||
* this.context.withPropertyValues("spring.foo=biz").run((loaded) -> {
|
||||
* assertThat(loaded).containsSingleBean(MyBean.class);
|
||||
* this.contextRunner.withPropertyValues("spring.foo=biz").run((context) -> {
|
||||
* assertThat(context).containsSingleBean(MyBean.class);
|
||||
* // other assertions
|
||||
* });
|
||||
* }</pre>
|
||||
@@ -80,19 +80,19 @@ import org.springframework.util.ReflectionUtils;
|
||||
* }</pre>
|
||||
* <p>
|
||||
*
|
||||
* @param <SELF> The "self" type for this tester
|
||||
* @param <SELF> The "self" type for this runner
|
||||
* @param <C> The context type
|
||||
* @param <A> The application context assertion provider
|
||||
* @author Stephane Nicoll
|
||||
* @author Andy Wilkinson
|
||||
* @author Phillip Webb
|
||||
* @since 2.0.0
|
||||
* @see ApplicationContextTester
|
||||
* @see WebApplicationContextTester
|
||||
* @see ReactiveWebApplicationContextTester
|
||||
* @see ApplicationContextRunner
|
||||
* @see WebApplicationContextRunner
|
||||
* @see ReactiveWebApplicationContextRunner
|
||||
* @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;
|
||||
|
||||
@@ -107,10 +107,10 @@ abstract class AbstractApplicationContextTester<SELF extends AbstractApplication
|
||||
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
|
||||
*/
|
||||
protected AbstractApplicationContextTester(Supplier<C> contextFactory) {
|
||||
protected AbstractApplicationContextRunner(Supplier<C> contextFactory) {
|
||||
Assert.notNull(contextFactory, "ContextFactory must not be null");
|
||||
this.contextFactory = contextFactory;
|
||||
this.environmentProperties = TestPropertyValues.empty();
|
||||
@@ -243,7 +243,7 @@ abstract class AbstractApplicationContextTester<SELF extends AbstractApplication
|
||||
@SuppressWarnings("unchecked")
|
||||
private A createAssertableContext() {
|
||||
ResolvableType resolvableType = ResolvableType
|
||||
.forClass(AbstractApplicationContextTester.class, getClass());
|
||||
.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,
|
||||
@@ -37,7 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @param <C> The application context type
|
||||
* @author Phillip Webb
|
||||
* @since 2.0.0
|
||||
* @see ApplicationContextTester
|
||||
* @see ApplicationContextRunner
|
||||
* @see AssertableApplicationContext
|
||||
*/
|
||||
public class ApplicationContextAssert<C extends ApplicationContext>
|
||||
|
||||
@@ -22,33 +22,33 @@ import org.springframework.context.ConfigurableApplicationContext;
|
||||
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}.
|
||||
* <p>
|
||||
* See {@link AbstractApplicationContextTester} for details.
|
||||
* See {@link AbstractApplicationContextRunner} for details.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @author Andy Wilkinson
|
||||
* @author Phillip Webb
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public class ApplicationContextTester extends
|
||||
AbstractApplicationContextTester<ApplicationContextTester, ConfigurableApplicationContext, AssertableApplicationContext> {
|
||||
public class ApplicationContextRunner extends
|
||||
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.
|
||||
*/
|
||||
public ApplicationContextTester() {
|
||||
public ApplicationContextRunner() {
|
||||
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.
|
||||
* @param contextFactory a supplier that returns a new instance on each call
|
||||
*/
|
||||
public ApplicationContextTester(
|
||||
public ApplicationContextRunner(
|
||||
Supplier<ConfigurableApplicationContext> contextFactory) {
|
||||
super(contextFactory);
|
||||
}
|
||||
@@ -30,7 +30,7 @@ import org.springframework.context.ConfigurableApplicationContext;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @since 2.0.0
|
||||
* @see ApplicationContextTester
|
||||
* @see ApplicationContextRunner
|
||||
* @see ApplicationContext
|
||||
*/
|
||||
public interface AssertableApplicationContext
|
||||
|
||||
@@ -30,7 +30,7 @@ import org.springframework.web.context.WebApplicationContext;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @since 2.0.0
|
||||
* @see WebApplicationContextTester
|
||||
* @see WebApplicationContextRunner
|
||||
* @see WebApplicationContext
|
||||
*/
|
||||
public interface AssertableWebApplicationContext
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.springframework.context.ApplicationContext;
|
||||
* @author Andy Wilkinson
|
||||
* @param <C> The application context type
|
||||
* @since 2.0.0
|
||||
* @see AbstractApplicationContextTester
|
||||
* @see AbstractApplicationContextRunner
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface ContextConsumer<C extends ApplicationContext> {
|
||||
|
||||
@@ -22,33 +22,33 @@ import org.springframework.boot.web.reactive.context.ConfigurableReactiveWebAppl
|
||||
import org.springframework.boot.web.reactive.context.GenericReactiveWebApplicationContext;
|
||||
|
||||
/**
|
||||
* A {@link AbstractApplicationContextTester ApplicationContext tester} for a
|
||||
* A {@link AbstractApplicationContextRunner ApplicationContext runner} for a
|
||||
* {@link ConfigurableReactiveWebApplicationContext}.
|
||||
* <p>
|
||||
* See {@link AbstractApplicationContextTester} for details.
|
||||
* See {@link AbstractApplicationContextRunner} for details.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
* @author Stephane Nicoll
|
||||
* @author Phillip Webb
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public final class ReactiveWebApplicationContextTester extends
|
||||
AbstractApplicationContextTester<ReactiveWebApplicationContextTester, ConfigurableReactiveWebApplicationContext, AssertableReactiveWebApplicationContext> {
|
||||
public final class ReactiveWebApplicationContextRunner extends
|
||||
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.
|
||||
*/
|
||||
public ReactiveWebApplicationContextTester() {
|
||||
public ReactiveWebApplicationContextRunner() {
|
||||
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.
|
||||
* @param contextFactory a supplier that returns a new instance on each call
|
||||
*/
|
||||
public ReactiveWebApplicationContextTester(
|
||||
public ReactiveWebApplicationContextRunner(
|
||||
Supplier<ConfigurableReactiveWebApplicationContext> contextFactory) {
|
||||
super(contextFactory);
|
||||
}
|
||||
@@ -24,35 +24,35 @@ import org.springframework.web.context.WebApplicationContext;
|
||||
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}.
|
||||
* <p>
|
||||
* See {@link AbstractApplicationContextTester} for details.
|
||||
* See {@link AbstractApplicationContextRunner} for details.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
* @author Stephane Nicoll
|
||||
* @author Phillip Webb
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public final class WebApplicationContextTester extends
|
||||
AbstractApplicationContextTester<WebApplicationContextTester, ConfigurableWebApplicationContext, AssertableWebApplicationContext> {
|
||||
public final class WebApplicationContextRunner extends
|
||||
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
|
||||
* the underlying source.
|
||||
* @see #withMockServletContext(Supplier)
|
||||
*/
|
||||
public WebApplicationContextTester() {
|
||||
public WebApplicationContextRunner() {
|
||||
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.
|
||||
* @param contextFactory a supplier that returns a new instance on each call
|
||||
*/
|
||||
public WebApplicationContextTester(
|
||||
public WebApplicationContextRunner(
|
||||
Supplier<ConfigurableWebApplicationContext> contextFactory) {
|
||||
super(contextFactory);
|
||||
}
|
||||
@@ -34,15 +34,15 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
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 <A> the assertable context type
|
||||
* @author Stephane Nicoll
|
||||
* @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
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
@@ -19,17 +19,17 @@ package org.springframework.boot.test.context;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
|
||||
/**
|
||||
* Tests for {@link ApplicationContextTester}.
|
||||
* Tests for {@link ApplicationContextRunner}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class ApplicationContextTesterTests extends
|
||||
AbstractApplicationContextTesterTests<ApplicationContextTester, ConfigurableApplicationContext, AssertableApplicationContext> {
|
||||
public class ApplicationContextRunnerTests extends
|
||||
AbstractApplicationContextRunnerTests<ApplicationContextRunner, ConfigurableApplicationContext, AssertableApplicationContext> {
|
||||
|
||||
@Override
|
||||
protected ApplicationContextTester get() {
|
||||
return new ApplicationContextTester();
|
||||
protected ApplicationContextRunner get() {
|
||||
return new ApplicationContextRunner();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,17 +19,17 @@ package org.springframework.boot.test.context;
|
||||
import org.springframework.boot.web.reactive.context.ConfigurableReactiveWebApplicationContext;
|
||||
|
||||
/**
|
||||
* Tests for {@link ReactiveWebApplicationContextTester}.
|
||||
* Tests for {@link ReactiveWebApplicationContextRunner}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class ReactiveWebApplicationContextTesterTests extends
|
||||
AbstractApplicationContextTesterTests<ReactiveWebApplicationContextTester, ConfigurableReactiveWebApplicationContext, AssertableReactiveWebApplicationContext> {
|
||||
public class ReactiveWebApplicationContextRunnerTests extends
|
||||
AbstractApplicationContextRunnerTests<ReactiveWebApplicationContextRunner, ConfigurableReactiveWebApplicationContext, AssertableReactiveWebApplicationContext> {
|
||||
|
||||
@Override
|
||||
protected ReactiveWebApplicationContextTester get() {
|
||||
return new ReactiveWebApplicationContextTester();
|
||||
protected ReactiveWebApplicationContextRunner get() {
|
||||
return new ReactiveWebApplicationContextRunner();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,13 +24,13 @@ import org.springframework.web.context.ConfigurableWebApplicationContext;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link WebApplicationContextTester}.
|
||||
* Tests for {@link WebApplicationContextRunner}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class WebApplicationContextTesterTests extends
|
||||
AbstractApplicationContextTesterTests<WebApplicationContextTester, ConfigurableWebApplicationContext, AssertableWebApplicationContext> {
|
||||
public class WebApplicationContextRunnerTests extends
|
||||
AbstractApplicationContextRunnerTests<WebApplicationContextRunner, ConfigurableWebApplicationContext, AssertableWebApplicationContext> {
|
||||
|
||||
@Test
|
||||
public void contextShouldHaveMockServletContext() throws Exception {
|
||||
@@ -39,8 +39,8 @@ public class WebApplicationContextTesterTests extends
|
||||
}
|
||||
|
||||
@Override
|
||||
protected WebApplicationContextTester get() {
|
||||
return new WebApplicationContextTester();
|
||||
protected WebApplicationContextRunner get() {
|
||||
return new WebApplicationContextRunner();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user