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