diff --git a/pom.xml b/pom.xml index cb1bd68809..798fd20499 100644 --- a/pom.xml +++ b/pom.xml @@ -82,6 +82,7 @@ spring-boot-parent spring-boot-tools spring-boot + spring-boot-test spring-boot-autoconfigure spring-boot-actuator spring-boot-devtools diff --git a/spring-boot-actuator-docs/pom.xml b/spring-boot-actuator-docs/pom.xml index cf6c40c23f..2fdd0c8c13 100644 --- a/spring-boot-actuator-docs/pom.xml +++ b/spring-boot-actuator-docs/pom.xml @@ -21,12 +21,17 @@ org.springframework.boot - spring-boot-starter-web + spring-boot-actuator provided org.springframework.boot - spring-boot-actuator + spring-boot-test + provided + + + ch.qos.logback + logback-classic provided @@ -73,6 +78,11 @@ spring-restdocs-mockmvc provided + + org.yaml + snakeyaml + provided + diff --git a/spring-boot-actuator/pom.xml b/spring-boot-actuator/pom.xml index b3020634f6..eb23009a85 100644 --- a/spring-boot-actuator/pom.xml +++ b/spring-boot-actuator/pom.xml @@ -271,6 +271,17 @@ test-jar test + + org.springframework.boot + spring-boot-test + test + + + org.springframework.boot + spring-boot-test + test-jar + test + ch.qos.logback logback-classic diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfigurationTests.java index 18be090dc9..9a07e9f98a 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfigurationTests.java @@ -60,7 +60,7 @@ import org.springframework.boot.context.embedded.EmbeddedServletContainerExcepti import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent; import org.springframework.boot.context.web.ServerPortInfoApplicationContextInitializer; import org.springframework.boot.test.EnvironmentTestUtils; -import org.springframework.boot.test.assertj.Matched; +import org.springframework.boot.testutil.Matched; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationListener; import org.springframework.context.annotation.Bean; diff --git a/spring-boot-autoconfigure/pom.xml b/spring-boot-autoconfigure/pom.xml index 95a8622bef..03d51889d8 100755 --- a/spring-boot-autoconfigure/pom.xml +++ b/spring-boot-autoconfigure/pom.xml @@ -569,6 +569,17 @@ test-jar test + + org.springframework.boot + spring-boot-test + test + + + org.springframework.boot + spring-boot-test + test-jar + test + ch.qos.logback logback-classic diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionEvaluationReportTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionEvaluationReportTests.java index 039734e7c5..9f30e4d988 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionEvaluationReportTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionEvaluationReportTests.java @@ -33,7 +33,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionEvaluationRepor import org.springframework.boot.autoconfigure.web.MultipartAutoConfiguration; import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration; import org.springframework.boot.test.EnvironmentTestUtils; -import org.springframework.boot.test.assertj.Matched; +import org.springframework.boot.testutil.Matched; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Condition; diff --git a/spring-boot-cli/pom.xml b/spring-boot-cli/pom.xml index e7ee726736..e3085d280e 100644 --- a/spring-boot-cli/pom.xml +++ b/spring-boot-cli/pom.xml @@ -142,6 +142,18 @@ junit provided + + + org.springframework.boot + spring-boot + test-jar + test + + + org.springframework.boot + spring-boot-test + test + diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/CliTester.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/CliTester.java index 68f90d6eec..384f2f005a 100644 --- a/spring-boot-cli/src/test/java/org/springframework/boot/cli/CliTester.java +++ b/spring-boot-cli/src/test/java/org/springframework/boot/cli/CliTester.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2016 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. @@ -41,7 +41,7 @@ import org.springframework.boot.cli.command.archive.JarCommand; import org.springframework.boot.cli.command.grab.GrabCommand; import org.springframework.boot.cli.command.run.RunCommand; import org.springframework.boot.cli.command.test.TestCommand; -import org.springframework.boot.cli.util.OutputCapture; +import org.springframework.boot.test.OutputCapture; import org.springframework.util.SocketUtils; /** diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/CommandRunnerIntegrationTests.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/CommandRunnerIntegrationTests.java index ccdd31bf85..de5f7c9a6e 100644 --- a/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/CommandRunnerIntegrationTests.java +++ b/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/CommandRunnerIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2016 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. @@ -20,7 +20,7 @@ import org.junit.Rule; import org.junit.Test; import org.springframework.boot.cli.command.run.RunCommand; -import org.springframework.boot.cli.util.OutputCapture; +import org.springframework.boot.test.OutputCapture; import static org.assertj.core.api.Assertions.assertThat; diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/install/GroovyGrabDependencyResolverTests.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/install/GroovyGrabDependencyResolverTests.java index ae2d1d5845..524f24dfb8 100644 --- a/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/install/GroovyGrabDependencyResolverTests.java +++ b/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/install/GroovyGrabDependencyResolverTests.java @@ -31,7 +31,7 @@ import org.springframework.boot.cli.compiler.GroovyCompilerConfiguration; import org.springframework.boot.cli.compiler.GroovyCompilerScope; import org.springframework.boot.cli.compiler.RepositoryConfigurationFactory; import org.springframework.boot.cli.compiler.grape.RepositoryConfiguration; -import org.springframework.boot.test.assertj.Matched; +import org.springframework.boot.testutil.Matched; import static org.assertj.core.api.Assertions.assertThat; import static org.hamcrest.Matchers.hasItems; diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/RepositoryConfigurationFactoryTests.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/RepositoryConfigurationFactoryTests.java index f8b570dc14..de4193d7c3 100644 --- a/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/RepositoryConfigurationFactoryTests.java +++ b/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/RepositoryConfigurationFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 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. @@ -23,7 +23,7 @@ import java.util.Set; import org.junit.Test; import org.springframework.boot.cli.compiler.grape.RepositoryConfiguration; -import org.springframework.boot.cli.util.SystemProperties; +import org.springframework.boot.cli.testutil.SystemProperties; import static org.assertj.core.api.Assertions.assertThat; diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/SettingsXmlRepositorySystemSessionAutoConfigurationTests.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/SettingsXmlRepositorySystemSessionAutoConfigurationTests.java index 91bced894f..536b0caa1f 100644 --- a/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/SettingsXmlRepositorySystemSessionAutoConfigurationTests.java +++ b/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/SettingsXmlRepositorySystemSessionAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 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. @@ -38,7 +38,7 @@ import org.mockito.invocation.InvocationOnMock; import org.mockito.runners.MockitoJUnitRunner; import org.mockito.stubbing.Answer; -import org.springframework.boot.cli.util.SystemProperties; +import org.springframework.boot.cli.testutil.SystemProperties; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/util/SystemProperties.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/testutil/SystemProperties.java similarity index 94% rename from spring-boot-cli/src/test/java/org/springframework/boot/cli/util/SystemProperties.java rename to spring-boot-cli/src/test/java/org/springframework/boot/cli/testutil/SystemProperties.java index 48c3c10cfe..962a329ad7 100644 --- a/spring-boot-cli/src/test/java/org/springframework/boot/cli/util/SystemProperties.java +++ b/spring-boot-cli/src/test/java/org/springframework/boot/cli/testutil/SystemProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.cli.util; +package org.springframework.boot.cli.testutil; import java.util.HashMap; import java.util.Map; diff --git a/spring-boot-dependencies/pom.xml b/spring-boot-dependencies/pom.xml index 3ba67eabbe..669aa71edc 100644 --- a/spring-boot-dependencies/pom.xml +++ b/spring-boot-dependencies/pom.xml @@ -183,6 +183,17 @@ test-jar 1.4.0.BUILD-SNAPSHOT + + org.springframework.boot + spring-boot-test + 1.4.0.BUILD-SNAPSHOT + + + org.springframework.boot + spring-boot-test + test-jar + 1.4.0.BUILD-SNAPSHOT + org.springframework.boot spring-boot-actuator @@ -2272,4 +2283,4 @@ integration-test - + \ No newline at end of file diff --git a/spring-boot-deployment-tests/spring-boot-deployment-test-glassfish/pom.xml b/spring-boot-deployment-tests/spring-boot-deployment-test-glassfish/pom.xml index 296b7326ff..da0f1dd1d4 100644 --- a/spring-boot-deployment-tests/spring-boot-deployment-test-glassfish/pom.xml +++ b/spring-boot-deployment-tests/spring-boot-deployment-test-glassfish/pom.xml @@ -37,6 +37,11 @@ javax.servlet-api provided + + org.springframework.boot + spring-boot-starter-test + test + diff --git a/spring-boot-deployment-tests/spring-boot-deployment-test-tomcat/pom.xml b/spring-boot-deployment-tests/spring-boot-deployment-test-tomcat/pom.xml index b924dc0dcc..1a1fbe1d40 100644 --- a/spring-boot-deployment-tests/spring-boot-deployment-test-tomcat/pom.xml +++ b/spring-boot-deployment-tests/spring-boot-deployment-test-tomcat/pom.xml @@ -38,6 +38,11 @@ javax.servlet-api provided + + org.springframework.boot + spring-boot-starter-test + test + diff --git a/spring-boot-deployment-tests/spring-boot-deployment-test-tomee/pom.xml b/spring-boot-deployment-tests/spring-boot-deployment-test-tomee/pom.xml index aaf04ba31a..8965279c43 100644 --- a/spring-boot-deployment-tests/spring-boot-deployment-test-tomee/pom.xml +++ b/spring-boot-deployment-tests/spring-boot-deployment-test-tomee/pom.xml @@ -43,6 +43,11 @@ javax.servlet-api provided + + org.springframework.boot + spring-boot-starter-test + test + diff --git a/spring-boot-deployment-tests/spring-boot-deployment-test-wildfly/pom.xml b/spring-boot-deployment-tests/spring-boot-deployment-test-wildfly/pom.xml index a379191504..657b6869ee 100644 --- a/spring-boot-deployment-tests/spring-boot-deployment-test-wildfly/pom.xml +++ b/spring-boot-deployment-tests/spring-boot-deployment-test-wildfly/pom.xml @@ -42,6 +42,11 @@ javax.servlet-api provided + + org.springframework.boot + spring-boot-starter-test + test + diff --git a/spring-boot-devtools/pom.xml b/spring-boot-devtools/pom.xml index 329bad0121..0a98a1bc00 100644 --- a/spring-boot-devtools/pom.xml +++ b/spring-boot-devtools/pom.xml @@ -76,6 +76,16 @@ true + + org.springframework.boot + spring-boot-test + test + + + ch.qos.logback + logback-classic + test + com.h2database h2 @@ -107,8 +117,18 @@ test - org.springframework.boot - spring-boot-starter-thymeleaf + org.thymeleaf + thymeleaf + test + + + org.thymeleaf + thymeleaf-spring4 + test + + + nz.net.ultraq.thymeleaf + thymeleaf-layout-dialect test diff --git a/spring-boot-full-build/pom.xml b/spring-boot-full-build/pom.xml index 8b78fa1667..eb02ebd957 100644 --- a/spring-boot-full-build/pom.xml +++ b/spring-boot-full-build/pom.xml @@ -49,6 +49,7 @@ ../spring-boot-parent ../spring-boot-tools ../spring-boot + ../spring-boot-test ../spring-boot-autoconfigure ../spring-boot-actuator ../spring-boot-actuator-docs diff --git a/spring-boot-integration-tests/spring-boot-gradle-tests/pom.xml b/spring-boot-integration-tests/spring-boot-gradle-tests/pom.xml index b03e299b01..50371e25cd 100644 --- a/spring-boot-integration-tests/spring-boot-gradle-tests/pom.xml +++ b/spring-boot-integration-tests/spring-boot-gradle-tests/pom.xml @@ -36,6 +36,11 @@ 3.2.1 test + + org.springframework.boot + spring-boot-starter-test + test + diff --git a/spring-boot-integration-tests/spring-boot-launch-script-tests/pom.xml b/spring-boot-integration-tests/spring-boot-launch-script-tests/pom.xml index e3fcc0e99e..77b6d76698 100644 --- a/spring-boot-integration-tests/spring-boot-launch-script-tests/pom.xml +++ b/spring-boot-integration-tests/spring-boot-launch-script-tests/pom.xml @@ -39,6 +39,12 @@ 2.1.4 test + + org.springframework.boot + spring-boot + test-jar + test + org.springframework.boot spring-boot-starter-test diff --git a/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/java/org/springframework/boot/launchscript/SysVinitLaunchScriptIT.java b/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/java/org/springframework/boot/launchscript/SysVinitLaunchScriptIT.java index e4d3fcbf93..3960d575b5 100644 --- a/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/java/org/springframework/boot/launchscript/SysVinitLaunchScriptIT.java +++ b/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/java/org/springframework/boot/launchscript/SysVinitLaunchScriptIT.java @@ -48,7 +48,7 @@ import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; import org.springframework.boot.ansi.AnsiColor; -import org.springframework.boot.test.assertj.Matched; +import org.springframework.boot.testutil.Matched; import static org.assertj.core.api.Assertions.assertThat; import static org.hamcrest.Matchers.containsString; diff --git a/spring-boot-integration-tests/spring-boot-security-tests/spring-boot-security-test-web-helloworld/pom.xml b/spring-boot-integration-tests/spring-boot-security-tests/spring-boot-security-test-web-helloworld/pom.xml index f4cf053386..7c1fc949cf 100644 --- a/spring-boot-integration-tests/spring-boot-security-tests/spring-boot-security-test-web-helloworld/pom.xml +++ b/spring-boot-integration-tests/spring-boot-security-tests/spring-boot-security-test-web-helloworld/pom.xml @@ -31,5 +31,10 @@ org.springframework.boot spring-boot-starter-security + + org.springframework.boot + spring-boot-starter-test + test + diff --git a/spring-boot-samples/spring-boot-sample-testng/pom.xml b/spring-boot-samples/spring-boot-sample-testng/pom.xml index 5a19a3def2..a09f707c09 100644 --- a/spring-boot-samples/spring-boot-sample-testng/pom.xml +++ b/spring-boot-samples/spring-boot-sample-testng/pom.xml @@ -31,18 +31,27 @@ org.springframework spring-webmvc + org.springframework spring-test + test + + + org.springframework.boot + spring-boot-test + test org.testng testng 6.8.13 + test org.assertj assertj-core + test diff --git a/spring-boot-starters/spring-boot-starter-test/pom.xml b/spring-boot-starters/spring-boot-starter-test/pom.xml index d7ca69b320..432c59b413 100644 --- a/spring-boot-starters/spring-boot-starter-test/pom.xml +++ b/spring-boot-starters/spring-boot-starter-test/pom.xml @@ -18,6 +18,10 @@ ${basedir}/../.. + + org.springframework.boot + spring-boot-test + junit junit diff --git a/spring-boot-test/pom.xml b/spring-boot-test/pom.xml new file mode 100644 index 0000000000..cff23bbcc8 --- /dev/null +++ b/spring-boot-test/pom.xml @@ -0,0 +1,111 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-parent + 1.4.0.BUILD-SNAPSHOT + ../spring-boot-parent + + spring-boot-test + Spring Boot Test + Spring Boot Test + http://projects.spring.io/spring-boot/ + + Pivotal Software, Inc. + http://www.spring.io + + + ${basedir}/.. + + + + + org.springframework.boot + spring-boot + + + + javax.servlet + javax.servlet-api + true + + + org.apache.httpcomponents + httpclient + true + + + org.assertj + assertj-core + true + + + org.hamcrest + hamcrest-core + true + + + org.hamcrest + hamcrest-library + true + + + org.springframework + spring-test + true + + + org.springframework + spring-web + true + + + junit + junit + true + + + + org.apache.tomcat.embed + tomcat-embed-core + test + + + org.apache.tomcat.embed + tomcat-embed-logging-juli + test + + + org.springframework + spring-webmvc + test + + + org.codehaus.groovy + groovy + test + + + org.codehaus.groovy + groovy-xml + true + test + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + test-jar + + + + + + + diff --git a/spring-boot/src/test/java/org/springframework/boot/test/ApplicationContextTestUtils.java b/spring-boot-test/src/main/java/org/springframework/boot/test/ApplicationContextTestUtils.java similarity index 86% rename from spring-boot/src/test/java/org/springframework/boot/test/ApplicationContextTestUtils.java rename to spring-boot-test/src/main/java/org/springframework/boot/test/ApplicationContextTestUtils.java index f44bca266b..820d7538e2 100644 --- a/spring-boot/src/test/java/org/springframework/boot/test/ApplicationContextTestUtils.java +++ b/spring-boot-test/src/main/java/org/springframework/boot/test/ApplicationContextTestUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2016 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. @@ -20,9 +20,10 @@ import org.springframework.context.ApplicationContext; import org.springframework.context.ConfigurableApplicationContext; /** - * Internal application context related test utilities. + * Application context related test utilities. * * @author Stephane Nicoll + * @since 1.4.0 */ public abstract class ApplicationContextTestUtils { @@ -32,11 +33,10 @@ public abstract class ApplicationContextTestUtils { */ public static void closeAll(ApplicationContext context) { if (context != null) { - ApplicationContext parent = context.getParent(); if (context instanceof ConfigurableApplicationContext) { ((ConfigurableApplicationContext) context).close(); } - closeAll(parent); + closeAll(context.getParent()); } } diff --git a/spring-boot/src/main/java/org/springframework/boot/test/ConfigFileApplicationContextInitializer.java b/spring-boot-test/src/main/java/org/springframework/boot/test/ConfigFileApplicationContextInitializer.java similarity index 96% rename from spring-boot/src/main/java/org/springframework/boot/test/ConfigFileApplicationContextInitializer.java rename to spring-boot-test/src/main/java/org/springframework/boot/test/ConfigFileApplicationContextInitializer.java index 5c0e3fdc08..395d4bac71 100644 --- a/spring-boot/src/main/java/org/springframework/boot/test/ConfigFileApplicationContextInitializer.java +++ b/spring-boot-test/src/main/java/org/springframework/boot/test/ConfigFileApplicationContextInitializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2016 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. diff --git a/spring-boot/src/main/java/org/springframework/boot/test/EnvironmentTestUtils.java b/spring-boot-test/src/main/java/org/springframework/boot/test/EnvironmentTestUtils.java similarity index 86% rename from spring-boot/src/main/java/org/springframework/boot/test/EnvironmentTestUtils.java rename to spring-boot-test/src/main/java/org/springframework/boot/test/EnvironmentTestUtils.java index a5004fc235..269e86ff51 100644 --- a/spring-boot/src/main/java/org/springframework/boot/test/EnvironmentTestUtils.java +++ b/spring-boot-test/src/main/java/org/springframework/boot/test/EnvironmentTestUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 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. @@ -67,18 +67,7 @@ public abstract class EnvironmentTestUtils { public static void addEnvironment(String name, ConfigurableEnvironment environment, String... pairs) { MutablePropertySources sources = environment.getPropertySources(); - Map map; - if (!sources.contains(name)) { - map = new HashMap(); - MapPropertySource source = new MapPropertySource(name, map); - sources.addFirst(source); - } - else { - @SuppressWarnings("unchecked") - Map value = (Map) sources.get(name) - .getSource(); - map = value; - } + Map map = getOrAdd(sources, name); for (String pair : pairs) { int index = getSeparatorIndex(pair); String key = pair.substring(0, index > 0 ? index : pair.length()); @@ -87,6 +76,17 @@ public abstract class EnvironmentTestUtils { } } + @SuppressWarnings("unchecked") + private static Map getOrAdd(MutablePropertySources sources, + String name) { + if (sources.contains(name)) { + return (Map) sources.get(name).getSource(); + } + Map map = new HashMap(); + sources.addFirst(new MapPropertySource(name, map)); + return map; + } + private static int getSeparatorIndex(String pair) { int colonIndex = pair.indexOf(":"); int equalIndex = pair.indexOf("="); diff --git a/spring-boot/src/main/java/org/springframework/boot/test/IntegrationTest.java b/spring-boot-test/src/main/java/org/springframework/boot/test/IntegrationTest.java similarity index 97% rename from spring-boot/src/main/java/org/springframework/boot/test/IntegrationTest.java rename to spring-boot-test/src/main/java/org/springframework/boot/test/IntegrationTest.java index d1cf9fe002..dbd1f9c515 100644 --- a/spring-boot/src/main/java/org/springframework/boot/test/IntegrationTest.java +++ b/spring-boot-test/src/main/java/org/springframework/boot/test/IntegrationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 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. diff --git a/spring-boot/src/main/java/org/springframework/boot/test/IntegrationTestPropertiesListener.java b/spring-boot-test/src/main/java/org/springframework/boot/test/IntegrationTestPropertiesListener.java similarity index 97% rename from spring-boot/src/main/java/org/springframework/boot/test/IntegrationTestPropertiesListener.java rename to spring-boot-test/src/main/java/org/springframework/boot/test/IntegrationTestPropertiesListener.java index 9ce9354b34..0ac0fdf145 100644 --- a/spring-boot/src/main/java/org/springframework/boot/test/IntegrationTestPropertiesListener.java +++ b/spring-boot-test/src/main/java/org/springframework/boot/test/IntegrationTestPropertiesListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2015 the original author or authors. + * Copyright 2013-2016 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. diff --git a/spring-boot/src/main/java/org/springframework/boot/test/MergedContextConfigurationProperties.java b/spring-boot-test/src/main/java/org/springframework/boot/test/MergedContextConfigurationProperties.java similarity index 97% rename from spring-boot/src/main/java/org/springframework/boot/test/MergedContextConfigurationProperties.java rename to spring-boot-test/src/main/java/org/springframework/boot/test/MergedContextConfigurationProperties.java index b86768b208..8898e7b173 100644 --- a/spring-boot/src/main/java/org/springframework/boot/test/MergedContextConfigurationProperties.java +++ b/spring-boot-test/src/main/java/org/springframework/boot/test/MergedContextConfigurationProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 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. diff --git a/spring-boot/src/main/java/org/springframework/boot/test/OutputCapture.java b/spring-boot-test/src/main/java/org/springframework/boot/test/OutputCapture.java similarity index 100% rename from spring-boot/src/main/java/org/springframework/boot/test/OutputCapture.java rename to spring-boot-test/src/main/java/org/springframework/boot/test/OutputCapture.java diff --git a/spring-boot/src/main/java/org/springframework/boot/test/SpringApplicationConfiguration.java b/spring-boot-test/src/main/java/org/springframework/boot/test/SpringApplicationConfiguration.java similarity index 98% rename from spring-boot/src/main/java/org/springframework/boot/test/SpringApplicationConfiguration.java rename to spring-boot-test/src/main/java/org/springframework/boot/test/SpringApplicationConfiguration.java index 61730c84ce..ff29565ada 100644 --- a/spring-boot/src/main/java/org/springframework/boot/test/SpringApplicationConfiguration.java +++ b/spring-boot-test/src/main/java/org/springframework/boot/test/SpringApplicationConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 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. diff --git a/spring-boot/src/main/java/org/springframework/boot/test/SpringApplicationContextLoader.java b/spring-boot-test/src/main/java/org/springframework/boot/test/SpringApplicationContextLoader.java similarity index 99% rename from spring-boot/src/main/java/org/springframework/boot/test/SpringApplicationContextLoader.java rename to spring-boot-test/src/main/java/org/springframework/boot/test/SpringApplicationContextLoader.java index 64b7cbd422..70234b9f29 100644 --- a/spring-boot/src/main/java/org/springframework/boot/test/SpringApplicationContextLoader.java +++ b/spring-boot-test/src/main/java/org/springframework/boot/test/SpringApplicationContextLoader.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 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. diff --git a/spring-boot/src/main/java/org/springframework/boot/test/SpringBootMockServletContext.java b/spring-boot-test/src/main/java/org/springframework/boot/test/SpringBootMockServletContext.java similarity index 98% rename from spring-boot/src/main/java/org/springframework/boot/test/SpringBootMockServletContext.java rename to spring-boot-test/src/main/java/org/springframework/boot/test/SpringBootMockServletContext.java index 75f81c3f64..3d79f4bb0e 100644 --- a/spring-boot/src/main/java/org/springframework/boot/test/SpringBootMockServletContext.java +++ b/spring-boot-test/src/main/java/org/springframework/boot/test/SpringBootMockServletContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 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. diff --git a/spring-boot/src/main/java/org/springframework/boot/test/TestRestTemplate.java b/spring-boot-test/src/main/java/org/springframework/boot/test/TestRestTemplate.java similarity index 99% rename from spring-boot/src/main/java/org/springframework/boot/test/TestRestTemplate.java rename to spring-boot-test/src/main/java/org/springframework/boot/test/TestRestTemplate.java index 22faefa9cd..c262ab7925 100644 --- a/spring-boot/src/main/java/org/springframework/boot/test/TestRestTemplate.java +++ b/spring-boot-test/src/main/java/org/springframework/boot/test/TestRestTemplate.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 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. diff --git a/spring-boot/src/main/java/org/springframework/boot/test/WebAppIntegrationTestContextBootstrapper.java b/spring-boot-test/src/main/java/org/springframework/boot/test/WebAppIntegrationTestContextBootstrapper.java similarity index 97% rename from spring-boot/src/main/java/org/springframework/boot/test/WebAppIntegrationTestContextBootstrapper.java rename to spring-boot-test/src/main/java/org/springframework/boot/test/WebAppIntegrationTestContextBootstrapper.java index e68842baac..badc7288e8 100644 --- a/spring-boot/src/main/java/org/springframework/boot/test/WebAppIntegrationTestContextBootstrapper.java +++ b/spring-boot-test/src/main/java/org/springframework/boot/test/WebAppIntegrationTestContextBootstrapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 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. diff --git a/spring-boot/src/main/java/org/springframework/boot/test/WebIntegrationTest.java b/spring-boot-test/src/main/java/org/springframework/boot/test/WebIntegrationTest.java similarity index 97% rename from spring-boot/src/main/java/org/springframework/boot/test/WebIntegrationTest.java rename to spring-boot-test/src/main/java/org/springframework/boot/test/WebIntegrationTest.java index 2231079425..278580ebf6 100644 --- a/spring-boot/src/main/java/org/springframework/boot/test/WebIntegrationTest.java +++ b/spring-boot-test/src/main/java/org/springframework/boot/test/WebIntegrationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 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. diff --git a/spring-boot/src/main/java/org/springframework/boot/test/package-info.java b/spring-boot-test/src/main/java/org/springframework/boot/test/package-info.java similarity index 93% rename from spring-boot/src/main/java/org/springframework/boot/test/package-info.java rename to spring-boot-test/src/main/java/org/springframework/boot/test/package-info.java index 65b537e382..3e2b2ee93b 100644 --- a/spring-boot/src/main/java/org/springframework/boot/test/package-info.java +++ b/spring-boot-test/src/main/java/org/springframework/boot/test/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2016 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. diff --git a/spring-boot/src/test/java/org/springframework/boot/test/AbstractConfigurationClassTests.java b/spring-boot-test/src/test/java/org/springframework/boot/test/AbstractConfigurationClassTests.java similarity index 98% rename from spring-boot/src/test/java/org/springframework/boot/test/AbstractConfigurationClassTests.java rename to spring-boot-test/src/test/java/org/springframework/boot/test/AbstractConfigurationClassTests.java index 706df04b83..0e6d04aaa8 100644 --- a/spring-boot/src/test/java/org/springframework/boot/test/AbstractConfigurationClassTests.java +++ b/spring-boot-test/src/test/java/org/springframework/boot/test/AbstractConfigurationClassTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 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. diff --git a/spring-boot/src/test/java/org/springframework/boot/test/ApplicationContextTestUtilsTests.java b/spring-boot-test/src/test/java/org/springframework/boot/test/ApplicationContextTestUtilsTests.java similarity index 96% rename from spring-boot/src/test/java/org/springframework/boot/test/ApplicationContextTestUtilsTests.java rename to spring-boot-test/src/test/java/org/springframework/boot/test/ApplicationContextTestUtilsTests.java index b2db9d2947..c54e5bff59 100644 --- a/spring-boot/src/test/java/org/springframework/boot/test/ApplicationContextTestUtilsTests.java +++ b/spring-boot-test/src/test/java/org/springframework/boot/test/ApplicationContextTestUtilsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2016 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. @@ -56,4 +56,5 @@ public class ApplicationContextTestUtilsTests { verify(parent).getParent(); verify(parent).close(); } + } diff --git a/spring-boot/src/test/java/org/springframework/boot/test/ConfigFileApplicationContextInitializerTests.java b/spring-boot-test/src/test/java/org/springframework/boot/test/ConfigFileApplicationContextInitializerTests.java similarity index 100% rename from spring-boot/src/test/java/org/springframework/boot/test/ConfigFileApplicationContextInitializerTests.java rename to spring-boot-test/src/test/java/org/springframework/boot/test/ConfigFileApplicationContextInitializerTests.java diff --git a/spring-boot/src/test/java/org/springframework/boot/test/EnvironmentTestUtilsTests.java b/spring-boot-test/src/test/java/org/springframework/boot/test/EnvironmentTestUtilsTests.java similarity index 98% rename from spring-boot/src/test/java/org/springframework/boot/test/EnvironmentTestUtilsTests.java rename to spring-boot-test/src/test/java/org/springframework/boot/test/EnvironmentTestUtilsTests.java index fe9f330444..28a8b23ac5 100644 --- a/spring-boot/src/test/java/org/springframework/boot/test/EnvironmentTestUtilsTests.java +++ b/spring-boot-test/src/test/java/org/springframework/boot/test/EnvironmentTestUtilsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 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. diff --git a/spring-boot/src/test/java/org/springframework/boot/test/SpringApplicationConfigurationActiveProfileTests.java b/spring-boot-test/src/test/java/org/springframework/boot/test/SpringApplicationConfigurationActiveProfileTests.java similarity index 100% rename from spring-boot/src/test/java/org/springframework/boot/test/SpringApplicationConfigurationActiveProfileTests.java rename to spring-boot-test/src/test/java/org/springframework/boot/test/SpringApplicationConfigurationActiveProfileTests.java diff --git a/spring-boot/src/test/java/org/springframework/boot/test/SpringApplicationConfigurationDefaultConfigurationTests.java b/spring-boot-test/src/test/java/org/springframework/boot/test/SpringApplicationConfigurationDefaultConfigurationTests.java similarity index 100% rename from spring-boot/src/test/java/org/springframework/boot/test/SpringApplicationConfigurationDefaultConfigurationTests.java rename to spring-boot-test/src/test/java/org/springframework/boot/test/SpringApplicationConfigurationDefaultConfigurationTests.java diff --git a/spring-boot/src/test/java/org/springframework/boot/test/SpringApplicationConfigurationGroovyConfigurationTests.java b/spring-boot-test/src/test/java/org/springframework/boot/test/SpringApplicationConfigurationGroovyConfigurationTests.java similarity index 100% rename from spring-boot/src/test/java/org/springframework/boot/test/SpringApplicationConfigurationGroovyConfigurationTests.java rename to spring-boot-test/src/test/java/org/springframework/boot/test/SpringApplicationConfigurationGroovyConfigurationTests.java diff --git a/spring-boot/src/test/java/org/springframework/boot/test/SpringApplicationConfigurationGroovyConventionConfigurationTests.java b/spring-boot-test/src/test/java/org/springframework/boot/test/SpringApplicationConfigurationGroovyConventionConfigurationTests.java similarity index 100% rename from spring-boot/src/test/java/org/springframework/boot/test/SpringApplicationConfigurationGroovyConventionConfigurationTests.java rename to spring-boot-test/src/test/java/org/springframework/boot/test/SpringApplicationConfigurationGroovyConventionConfigurationTests.java diff --git a/spring-boot/src/test/java/org/springframework/boot/test/SpringApplicationConfigurationJmxTests.java b/spring-boot-test/src/test/java/org/springframework/boot/test/SpringApplicationConfigurationJmxTests.java similarity index 100% rename from spring-boot/src/test/java/org/springframework/boot/test/SpringApplicationConfigurationJmxTests.java rename to spring-boot-test/src/test/java/org/springframework/boot/test/SpringApplicationConfigurationJmxTests.java diff --git a/spring-boot/src/test/java/org/springframework/boot/test/SpringApplicationConfigurationMixedConfigurationTests.java b/spring-boot-test/src/test/java/org/springframework/boot/test/SpringApplicationConfigurationMixedConfigurationTests.java similarity index 100% rename from spring-boot/src/test/java/org/springframework/boot/test/SpringApplicationConfigurationMixedConfigurationTests.java rename to spring-boot-test/src/test/java/org/springframework/boot/test/SpringApplicationConfigurationMixedConfigurationTests.java diff --git a/spring-boot/src/test/java/org/springframework/boot/test/SpringApplicationConfigurationXmlConventionConfigurationTests.java b/spring-boot-test/src/test/java/org/springframework/boot/test/SpringApplicationConfigurationXmlConventionConfigurationTests.java similarity index 100% rename from spring-boot/src/test/java/org/springframework/boot/test/SpringApplicationConfigurationXmlConventionConfigurationTests.java rename to spring-boot-test/src/test/java/org/springframework/boot/test/SpringApplicationConfigurationXmlConventionConfigurationTests.java diff --git a/spring-boot/src/test/java/org/springframework/boot/test/SpringApplicationContextLoaderTests.java b/spring-boot-test/src/test/java/org/springframework/boot/test/SpringApplicationContextLoaderTests.java similarity index 89% rename from spring-boot/src/test/java/org/springframework/boot/test/SpringApplicationContextLoaderTests.java rename to spring-boot-test/src/test/java/org/springframework/boot/test/SpringApplicationContextLoaderTests.java index 90f5c15c61..56959c25fa 100644 --- a/spring-boot/src/test/java/org/springframework/boot/test/SpringApplicationContextLoaderTests.java +++ b/spring-boot-test/src/test/java/org/springframework/boot/test/SpringApplicationContextLoaderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2016 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. @@ -21,6 +21,8 @@ import java.util.Map; import org.junit.Ignore; import org.junit.Test; +import org.springframework.context.annotation.Configuration; +import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.MergedContextConfiguration; import org.springframework.test.context.TestContext; import org.springframework.test.context.TestContextManager; @@ -97,27 +99,44 @@ public class SpringApplicationContextLoaderTests { } @IntegrationTest({ "key=myValue", "anotherKey:anotherValue" }) + @ContextConfiguration(classes = Config.class) static class SimpleConfig { + } @IntegrationTest({ "server.port=2345" }) + @ContextConfiguration(classes = Config.class) static class OverrideConfig { + } @IntegrationTest({ "key=myValue", "otherKey=otherValue" }) + @ContextConfiguration(classes = Config.class) static class AppendConfig { + } @IntegrationTest({ "key=my=Value", "anotherKey:another:Value" }) + @ContextConfiguration(classes = Config.class) static class SameSeparatorInValue { + } @IntegrationTest({ "key=my:Value", "anotherKey:another=Value" }) + @ContextConfiguration(classes = Config.class) static class AnotherSeparatorInValue { + } @IntegrationTest({ "key=myValue", "variables=foo=FOO\n bar=BAR" }) + @ContextConfiguration(classes = Config.class) static class NewLineInValue { + + } + + @Configuration + static class Config { + } /** diff --git a/spring-boot/src/test/java/org/springframework/boot/test/SpringApplicationIntegrationTestPropertyLocationTests.java b/spring-boot-test/src/test/java/org/springframework/boot/test/SpringApplicationIntegrationTestPropertyLocationTests.java similarity index 100% rename from spring-boot/src/test/java/org/springframework/boot/test/SpringApplicationIntegrationTestPropertyLocationTests.java rename to spring-boot-test/src/test/java/org/springframework/boot/test/SpringApplicationIntegrationTestPropertyLocationTests.java diff --git a/spring-boot/src/test/java/org/springframework/boot/test/SpringApplicationIntegrationTestTests.java b/spring-boot-test/src/test/java/org/springframework/boot/test/SpringApplicationIntegrationTestTests.java similarity index 100% rename from spring-boot/src/test/java/org/springframework/boot/test/SpringApplicationIntegrationTestTests.java rename to spring-boot-test/src/test/java/org/springframework/boot/test/SpringApplicationIntegrationTestTests.java diff --git a/spring-boot/src/test/java/org/springframework/boot/test/SpringApplicationMockMvcTests.java b/spring-boot-test/src/test/java/org/springframework/boot/test/SpringApplicationMockMvcTests.java similarity index 100% rename from spring-boot/src/test/java/org/springframework/boot/test/SpringApplicationMockMvcTests.java rename to spring-boot-test/src/test/java/org/springframework/boot/test/SpringApplicationMockMvcTests.java diff --git a/spring-boot/src/test/java/org/springframework/boot/test/SpringApplicationWebIntegrationTestTests.java b/spring-boot-test/src/test/java/org/springframework/boot/test/SpringApplicationWebIntegrationTestTests.java similarity index 100% rename from spring-boot/src/test/java/org/springframework/boot/test/SpringApplicationWebIntegrationTestTests.java rename to spring-boot-test/src/test/java/org/springframework/boot/test/SpringApplicationWebIntegrationTestTests.java diff --git a/spring-boot/src/test/java/org/springframework/boot/test/SpringBootMockServletContextTests.java b/spring-boot-test/src/test/java/org/springframework/boot/test/SpringBootMockServletContextTests.java similarity index 100% rename from spring-boot/src/test/java/org/springframework/boot/test/SpringBootMockServletContextTests.java rename to spring-boot-test/src/test/java/org/springframework/boot/test/SpringBootMockServletContextTests.java diff --git a/spring-boot/src/test/java/org/springframework/boot/test/TestRestTemplateTests.java b/spring-boot-test/src/test/java/org/springframework/boot/test/TestRestTemplateTests.java similarity index 97% rename from spring-boot/src/test/java/org/springframework/boot/test/TestRestTemplateTests.java rename to spring-boot-test/src/test/java/org/springframework/boot/test/TestRestTemplateTests.java index d0b2041ab6..47cc610423 100644 --- a/spring-boot/src/test/java/org/springframework/boot/test/TestRestTemplateTests.java +++ b/spring-boot-test/src/test/java/org/springframework/boot/test/TestRestTemplateTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2016 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. diff --git a/spring-boot/src/test/resources/META-INF/resources/inmetainfresources b/spring-boot-test/src/test/resources/META-INF/resources/inmetainfresources similarity index 100% rename from spring-boot/src/test/resources/META-INF/resources/inmetainfresources rename to spring-boot-test/src/test/resources/META-INF/resources/inmetainfresources diff --git a/spring-boot-test/src/test/resources/application.properties b/spring-boot-test/src/test/resources/application.properties new file mode 100644 index 0000000000..2f0172e0f2 --- /dev/null +++ b/spring-boot-test/src/test/resources/application.properties @@ -0,0 +1,5 @@ +foo: bucket +value: 1234 +my.property: fromapplicationproperties +sample.app.test.prop: * +my.placeholder: ${my.fallback} diff --git a/spring-boot/src/test/resources/org/springframework/boot/test/SpringApplicationConfigurationGroovyConventionConfigurationTestsContext.groovy b/spring-boot-test/src/test/resources/org/springframework/boot/test/SpringApplicationConfigurationGroovyConventionConfigurationTestsContext.groovy similarity index 100% rename from spring-boot/src/test/resources/org/springframework/boot/test/SpringApplicationConfigurationGroovyConventionConfigurationTestsContext.groovy rename to spring-boot-test/src/test/resources/org/springframework/boot/test/SpringApplicationConfigurationGroovyConventionConfigurationTestsContext.groovy diff --git a/spring-boot/src/test/resources/org/springframework/boot/test/SpringApplicationConfigurationXmlConventionConfigurationTests-context.xml b/spring-boot-test/src/test/resources/org/springframework/boot/test/SpringApplicationConfigurationXmlConventionConfigurationTests-context.xml similarity index 100% rename from spring-boot/src/test/resources/org/springframework/boot/test/SpringApplicationConfigurationXmlConventionConfigurationTests-context.xml rename to spring-boot-test/src/test/resources/org/springframework/boot/test/SpringApplicationConfigurationXmlConventionConfigurationTests-context.xml diff --git a/spring-boot/src/test/resources/public/inpublic b/spring-boot-test/src/test/resources/public/inpublic similarity index 100% rename from spring-boot/src/test/resources/public/inpublic rename to spring-boot-test/src/test/resources/public/inpublic diff --git a/spring-boot/src/test/resources/resources/inresources b/spring-boot-test/src/test/resources/resources/inresources similarity index 100% rename from spring-boot/src/test/resources/resources/inresources rename to spring-boot-test/src/test/resources/resources/inresources diff --git a/spring-boot/src/test/resources/static/instatic b/spring-boot-test/src/test/resources/static/instatic similarity index 100% rename from spring-boot/src/test/resources/static/instatic rename to spring-boot-test/src/test/resources/static/instatic diff --git a/spring-boot/src/test/resources/test-property-source-annotation.properties b/spring-boot-test/src/test/resources/test-property-source-annotation.properties similarity index 100% rename from spring-boot/src/test/resources/test-property-source-annotation.properties rename to spring-boot-test/src/test/resources/test-property-source-annotation.properties diff --git a/spring-boot/src/test/resources/test.groovy b/spring-boot-test/src/test/resources/test.groovy similarity index 100% rename from spring-boot/src/test/resources/test.groovy rename to spring-boot-test/src/test/resources/test.groovy diff --git a/spring-boot/src/test/webapp/inwebapp b/spring-boot-test/src/test/webapp/inwebapp similarity index 100% rename from spring-boot/src/test/webapp/inwebapp rename to spring-boot-test/src/test/webapp/inwebapp diff --git a/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/OutputCapture.java b/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/OutputCapture.java index 2461318e15..31dd58694e 100644 --- a/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/OutputCapture.java +++ b/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/OutputCapture.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2016 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. @@ -26,7 +26,7 @@ import org.junit.runner.Description; import org.junit.runners.model.Statement; /** - * Capture output from System.out and System.err. + * Internal JUnit {@code @Rule} to capture output from System.out and System.err. * * @author Phillip Webb */ diff --git a/spring-boot/src/test/java/org/springframework/boot/AdhocTestSuite.java b/spring-boot/src/test/java/org/springframework/boot/AdhocTestSuite.java index f6bdbac11f..54d6134ddb 100644 --- a/spring-boot/src/test/java/org/springframework/boot/AdhocTestSuite.java +++ b/spring-boot/src/test/java/org/springframework/boot/AdhocTestSuite.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2016 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. @@ -21,17 +21,13 @@ import org.junit.runner.RunWith; import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; -import org.springframework.boot.test.SpringApplicationConfigurationDefaultConfigurationTests; -import org.springframework.boot.test.SpringApplicationConfigurationJmxTests; - /** * A test suite for probing weird ordering problems in the tests. * * @author Dave Syer */ @RunWith(Suite.class) -@SuiteClasses({ SpringApplicationConfigurationJmxTests.class, - SpringApplicationConfigurationDefaultConfigurationTests.class }) +@SuiteClasses({}) @Ignore public class AdhocTestSuite { diff --git a/spring-boot/src/test/java/org/springframework/boot/BannerTests.java b/spring-boot/src/test/java/org/springframework/boot/BannerTests.java index 86eb658ca3..6a29ab05d3 100644 --- a/spring-boot/src/test/java/org/springframework/boot/BannerTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/BannerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2016 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. @@ -22,7 +22,7 @@ import org.junit.After; import org.junit.Rule; import org.junit.Test; -import org.springframework.boot.test.OutputCapture; +import org.springframework.boot.testutil.OutputCapture; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; diff --git a/spring-boot/src/test/java/org/springframework/boot/SimpleMainTests.java b/spring-boot/src/test/java/org/springframework/boot/SimpleMainTests.java index f942f6b3f7..02458a9eb1 100644 --- a/spring-boot/src/test/java/org/springframework/boot/SimpleMainTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/SimpleMainTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2016 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. @@ -23,7 +23,7 @@ import java.util.List; import org.junit.Rule; import org.junit.Test; -import org.springframework.boot.test.OutputCapture; +import org.springframework.boot.testutil.OutputCapture; import org.springframework.context.annotation.Configuration; import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; diff --git a/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java b/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java index c4bd255537..cfdc19debf 100644 --- a/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java @@ -43,8 +43,8 @@ import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEven import org.springframework.boot.context.event.ApplicationPreparedEvent; import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.boot.context.event.ApplicationStartedEvent; -import org.springframework.boot.test.EnvironmentTestUtils; -import org.springframework.boot.test.OutputCapture; +import org.springframework.boot.testutil.EnvironmentTestUtils; +import org.springframework.boot.testutil.OutputCapture; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.context.ApplicationContextInitializer; diff --git a/spring-boot/src/test/java/org/springframework/boot/bind/ConverterBindingTests.java b/spring-boot/src/test/java/org/springframework/boot/bind/ConverterBindingTests.java index d30cddd80b..0f72abae1c 100644 --- a/spring-boot/src/test/java/org/springframework/boot/bind/ConverterBindingTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/bind/ConverterBindingTests.java @@ -28,8 +28,6 @@ import org.springframework.boot.bind.ConverterBindingTests.TestConfig; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationPropertiesBinding; import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.boot.test.IntegrationTest; -import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; @@ -37,6 +35,8 @@ import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.converter.Converter; import org.springframework.core.convert.converter.GenericConverter; import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -49,8 +49,8 @@ import static org.assertj.core.api.Assertions.assertThat; */ @RunWith(SpringJUnit4ClassRunner.class) @DirtiesContext -@SpringApplicationConfiguration(TestConfig.class) -@IntegrationTest({ "foo=one", "bar=two" }) +@ContextConfiguration(classes = TestConfig.class, loader = SpringApplicationBindContextLoader.class) +@TestPropertySource(properties = { "foo=one", "bar=two" }) public class ConverterBindingTests { @Value("${foo:}") diff --git a/spring-boot/src/test/java/org/springframework/boot/bind/PropertiesConfigurationFactoryPerformanceTests.java b/spring-boot/src/test/java/org/springframework/boot/bind/PropertiesConfigurationFactoryPerformanceTests.java index d227ea2686..4638441ce6 100644 --- a/spring-boot/src/test/java/org/springframework/boot/bind/PropertiesConfigurationFactoryPerformanceTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/bind/PropertiesConfigurationFactoryPerformanceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 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. @@ -26,7 +26,7 @@ import org.junit.experimental.theories.Theories; import org.junit.experimental.theories.Theory; import org.junit.runner.RunWith; -import org.springframework.boot.test.EnvironmentTestUtils; +import org.springframework.boot.testutil.EnvironmentTestUtils; import org.springframework.context.support.StaticMessageSource; import org.springframework.core.env.StandardEnvironment; import org.springframework.validation.Validator; diff --git a/spring-boot/src/test/java/org/springframework/boot/bind/PropertySourcesBindingTests.java b/spring-boot/src/test/java/org/springframework/boot/bind/PropertySourcesBindingTests.java index 87e7fe88b7..6a72dacb3f 100644 --- a/spring-boot/src/test/java/org/springframework/boot/bind/PropertySourcesBindingTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/bind/PropertySourcesBindingTests.java @@ -24,8 +24,6 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.bind.PropertySourcesBindingTests.TestConfig; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.boot.test.IntegrationTest; -import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; @@ -33,6 +31,7 @@ import org.springframework.context.annotation.PropertySource; import org.springframework.context.annotation.PropertySources; import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -44,8 +43,7 @@ import static org.assertj.core.api.Assertions.assertThat; */ @RunWith(SpringJUnit4ClassRunner.class) @DirtiesContext -@SpringApplicationConfiguration(TestConfig.class) -@IntegrationTest +@ContextConfiguration(classes = TestConfig.class, loader = SpringApplicationBindContextLoader.class) public class PropertySourcesBindingTests { @Value("${foo:}") diff --git a/spring-boot/src/test/java/org/springframework/boot/bind/SimplerPropertySourcesBindingTests.java b/spring-boot/src/test/java/org/springframework/boot/bind/SimplerPropertySourcesBindingTests.java index 1d4d4abeca..0e9c8b5f4f 100644 --- a/spring-boot/src/test/java/org/springframework/boot/bind/SimplerPropertySourcesBindingTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/bind/SimplerPropertySourcesBindingTests.java @@ -24,14 +24,13 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.bind.SimplerPropertySourcesBindingTests.TestConfig; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.boot.test.IntegrationTest; -import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; import org.springframework.context.annotation.PropertySources; import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -43,8 +42,7 @@ import static org.assertj.core.api.Assertions.assertThat; */ @RunWith(SpringJUnit4ClassRunner.class) @DirtiesContext -@SpringApplicationConfiguration(TestConfig.class) -@IntegrationTest +@ContextConfiguration(classes = TestConfig.class, loader = SpringApplicationBindContextLoader.class) public class SimplerPropertySourcesBindingTests { @Value("${foo:}") @@ -73,6 +71,7 @@ public class SimplerPropertySourcesBindingTests { @ConfigurationProperties public static class Wrapper { + private String foo; public String getFoo() { @@ -82,6 +81,7 @@ public class SimplerPropertySourcesBindingTests { public void setFoo(String foo) { this.foo = foo; } + } } diff --git a/spring-boot/src/test/java/org/springframework/boot/bind/SpringApplicationBindContextLoader.java b/spring-boot/src/test/java/org/springframework/boot/bind/SpringApplicationBindContextLoader.java new file mode 100644 index 0000000000..2afa948977 --- /dev/null +++ b/spring-boot/src/test/java/org/springframework/boot/bind/SpringApplicationBindContextLoader.java @@ -0,0 +1,78 @@ +/* + * Copyright 2012-2016 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. + */ + +package org.springframework.boot.bind; + +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.Map; + +import org.springframework.boot.SpringApplication; +import org.springframework.context.ApplicationContext; +import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.core.env.MapPropertySource; +import org.springframework.core.env.StandardEnvironment; +import org.springframework.test.context.ContextLoader; +import org.springframework.test.context.MergedContextConfiguration; +import org.springframework.test.context.support.AbstractContextLoader; +import org.springframework.test.context.support.TestPropertySourceUtils; + +/** + * {@link ContextLoader} used with binding tests. + * + * @author Phillip Webb + */ +class SpringApplicationBindContextLoader extends AbstractContextLoader { + + private static final String[] NO_SUFFIXES = new String[] {}; + + @Override + public ApplicationContext loadContext(MergedContextConfiguration config) + throws Exception { + SpringApplication application = new SpringApplication(); + application.setMainApplicationClass(config.getTestClass()); + application.setWebEnvironment(false); + application.setSources( + new LinkedHashSet(Arrays.asList(config.getClasses()))); + ConfigurableEnvironment environment = new StandardEnvironment(); + Map properties = new LinkedHashMap(); + properties.put("spring.jmx.enabled", "false"); + properties.putAll(TestPropertySourceUtils + .convertInlinedPropertiesToMap(config.getPropertySourceProperties())); + environment.getPropertySources().addAfter( + StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, + new MapPropertySource("integrationTest", properties)); + application.setEnvironment(environment); + return application.run(); + } + + @Override + public ApplicationContext loadContext(String... locations) throws Exception { + throw new UnsupportedOperationException(); + } + + @Override + protected String[] getResourceSuffixes() { + return NO_SUFFIXES; + } + + @Override + protected String getResourceSuffix() { + throw new UnsupportedOperationException(); + } + +} diff --git a/spring-boot/src/test/java/org/springframework/boot/builder/SpringApplicationBuilderTests.java b/spring-boot/src/test/java/org/springframework/boot/builder/SpringApplicationBuilderTests.java index 0de9954149..2aa5f7f9ac 100644 --- a/spring-boot/src/test/java/org/springframework/boot/builder/SpringApplicationBuilderTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/builder/SpringApplicationBuilderTests.java @@ -24,7 +24,6 @@ import org.junit.After; import org.junit.Test; import org.springframework.boot.ApplicationArguments; -import org.springframework.boot.test.ApplicationContextTestUtils; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.ConfigurableApplicationContext; @@ -52,7 +51,16 @@ public class SpringApplicationBuilderTests { @After public void close() { - ApplicationContextTestUtils.closeAll(this.context); + close(this.context); + } + + private void close(ApplicationContext context) { + if (context != null) { + if (context instanceof ConfigurableApplicationContext) { + ((ConfigurableApplicationContext) context).close(); + } + close(context.getParent()); + } } @Test diff --git a/spring-boot/src/test/java/org/springframework/boot/cloud/cloudfoundry/CloudFoundryVcapEnvironmentPostProcessorTests.java b/spring-boot/src/test/java/org/springframework/boot/cloud/cloudfoundry/CloudFoundryVcapEnvironmentPostProcessorTests.java index 714162bb62..50b89d43ac 100644 --- a/spring-boot/src/test/java/org/springframework/boot/cloud/cloudfoundry/CloudFoundryVcapEnvironmentPostProcessorTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/cloud/cloudfoundry/CloudFoundryVcapEnvironmentPostProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 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. @@ -19,7 +19,7 @@ package org.springframework.boot.cloud.cloudfoundry; import org.junit.Test; import org.springframework.boot.cloud.CloudFoundryVcapEnvironmentPostProcessor; -import org.springframework.boot.test.EnvironmentTestUtils; +import org.springframework.boot.testutil.EnvironmentTestUtils; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; diff --git a/spring-boot/src/test/java/org/springframework/boot/context/ConfigurationWarningsApplicationContextInitializerTests.java b/spring-boot/src/test/java/org/springframework/boot/context/ConfigurationWarningsApplicationContextInitializerTests.java index 76636c69a4..6d9128ae50 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/ConfigurationWarningsApplicationContextInitializerTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/ConfigurationWarningsApplicationContextInitializerTests.java @@ -33,7 +33,7 @@ import org.springframework.boot.context.configwarnings.dflt.InDefaultPackageWith import org.springframework.boot.context.configwarnings.orgspring.InOrgSpringPackageConfiguration; import org.springframework.boot.context.configwarnings.real.InRealButScanningProblemPackages; import org.springframework.boot.context.configwarnings.real.InRealPackageConfiguration; -import org.springframework.boot.test.OutputCapture; +import org.springframework.boot.testutil.OutputCapture; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import static org.assertj.core.api.Assertions.assertThat; diff --git a/spring-boot/src/test/java/org/springframework/boot/context/ContextIdApplicationContextInitializerTests.java b/spring-boot/src/test/java/org/springframework/boot/context/ContextIdApplicationContextInitializerTests.java index e1720f2558..411f0bf26b 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/ContextIdApplicationContextInitializerTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/ContextIdApplicationContextInitializerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2016 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. @@ -18,7 +18,7 @@ package org.springframework.boot.context; import org.junit.Test; -import org.springframework.boot.test.EnvironmentTestUtils; +import org.springframework.boot.testutil.EnvironmentTestUtils; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; diff --git a/spring-boot/src/test/java/org/springframework/boot/context/FileEncodingApplicationListenerTests.java b/spring-boot/src/test/java/org/springframework/boot/context/FileEncodingApplicationListenerTests.java index a549f054b5..9af89e0f5a 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/FileEncodingApplicationListenerTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/FileEncodingApplicationListenerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2016 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. @@ -21,7 +21,7 @@ import org.junit.Test; import org.springframework.boot.SpringApplication; import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent; -import org.springframework.boot.test.EnvironmentTestUtils; +import org.springframework.boot.testutil.EnvironmentTestUtils; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.StandardEnvironment; diff --git a/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java b/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java index e1d28a8d92..5ecc1d6017 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 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. @@ -46,8 +46,8 @@ import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEven import org.springframework.boot.context.event.ApplicationPreparedEvent; import org.springframework.boot.env.EnumerableCompositePropertySource; import org.springframework.boot.env.EnvironmentPostProcessor; -import org.springframework.boot.test.EnvironmentTestUtils; -import org.springframework.boot.test.OutputCapture; +import org.springframework.boot.testutil.EnvironmentTestUtils; +import org.springframework.boot.testutil.OutputCapture; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Configuration; diff --git a/spring-boot/src/test/java/org/springframework/boot/context/config/DelegatingApplicationContextInitializerTests.java b/spring-boot/src/test/java/org/springframework/boot/context/config/DelegatingApplicationContextInitializerTests.java index 9f7dc82ee8..db63e1a71c 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/config/DelegatingApplicationContextInitializerTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/config/DelegatingApplicationContextInitializerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2016 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. @@ -20,7 +20,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.springframework.boot.test.EnvironmentTestUtils; +import org.springframework.boot.testutil.EnvironmentTestUtils; import org.springframework.context.ApplicationContextException; import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.ConfigurableApplicationContext; diff --git a/spring-boot/src/test/java/org/springframework/boot/context/config/DelegatingApplicationListenerTests.java b/spring-boot/src/test/java/org/springframework/boot/context/config/DelegatingApplicationListenerTests.java index beccb15b31..5cdb95e577 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/config/DelegatingApplicationListenerTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/config/DelegatingApplicationListenerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2016 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. @@ -23,7 +23,7 @@ import org.junit.rules.ExpectedException; import org.springframework.boot.SpringApplication; import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent; -import org.springframework.boot.test.EnvironmentTestUtils; +import org.springframework.boot.testutil.EnvironmentTestUtils; import org.springframework.context.ApplicationListener; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.event.ContextRefreshedEvent; diff --git a/spring-boot/src/test/java/org/springframework/boot/context/embedded/config/AnsiOutputApplicationListenerTests.java b/spring-boot/src/test/java/org/springframework/boot/context/embedded/config/AnsiOutputApplicationListenerTests.java index 31a92890af..5a68074c8f 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/embedded/config/AnsiOutputApplicationListenerTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/embedded/config/AnsiOutputApplicationListenerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 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. @@ -28,7 +28,7 @@ import org.springframework.boot.ansi.AnsiOutput; import org.springframework.boot.ansi.AnsiOutput.Enabled; import org.springframework.boot.ansi.AnsiOutputEnabledValue; import org.springframework.boot.context.config.AnsiOutputApplicationListener; -import org.springframework.boot.test.EnvironmentTestUtils; +import org.springframework.boot.testutil.EnvironmentTestUtils; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.ConfigurableEnvironment; diff --git a/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessorTests.java b/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessorTests.java index cc6e73ca36..fa6ea0375b 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessorTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 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. @@ -34,7 +34,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.support.AbstractBeanDefinition; import org.springframework.beans.factory.support.GenericBeanDefinition; import org.springframework.boot.bind.RelaxedBindingNotWritablePropertyException; -import org.springframework.boot.test.EnvironmentTestUtils; +import org.springframework.boot.testutil.EnvironmentTestUtils; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/spring-boot/src/test/java/org/springframework/boot/context/properties/EnableConfigurationPropertiesTests.java b/spring-boot/src/test/java/org/springframework/boot/context/properties/EnableConfigurationPropertiesTests.java index 55a7cdbc56..febe7a0849 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/properties/EnableConfigurationPropertiesTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/properties/EnableConfigurationPropertiesTests.java @@ -30,7 +30,7 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.EnvironmentTestUtils; +import org.springframework.boot.testutil.EnvironmentTestUtils; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/spring-boot/src/test/java/org/springframework/boot/context/web/ErrorPageFilterIntegrationTests.java b/spring-boot/src/test/java/org/springframework/boot/context/web/ErrorPageFilterIntegrationTests.java index 867b158567..8c4455dad5 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/web/ErrorPageFilterIntegrationTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/web/ErrorPageFilterIntegrationTests.java @@ -26,26 +26,29 @@ import javax.servlet.http.HttpServletResponse; import org.junit.After; import org.junit.Test; import org.junit.runner.RunWith; +import org.xnio.channels.UnsupportedOptionException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; +import org.springframework.boot.context.web.ErrorPageFilterIntegrationTests.EmbeddedWebContextLoader; import org.springframework.boot.context.web.ErrorPageFilterIntegrationTests.TomcatConfig; -import org.springframework.boot.test.IntegrationTest; -import org.springframework.boot.test.SpringApplicationConfiguration; -import org.springframework.boot.test.TestRestTemplate; +import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.MergedContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.test.context.support.AbstractContextLoader; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.client.RestTemplate; import org.springframework.web.servlet.DispatcherServlet; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.config.annotation.EnableWebMvc; @@ -59,12 +62,11 @@ import static org.assertj.core.api.Assertions.assertThat; * Integration tests for {@link ErrorPageFilter}. * * @author Dave Syer + * @author Phillip Webb */ @RunWith(SpringJUnit4ClassRunner.class) @DirtiesContext -@SpringApplicationConfiguration(TomcatConfig.class) -@IntegrationTest -@WebAppConfiguration +@ContextConfiguration(classes = TomcatConfig.class, loader = EmbeddedWebContextLoader.class) public class ErrorPageFilterIntegrationTests { @Autowired @@ -93,7 +95,7 @@ public class ErrorPageFilterIntegrationTests { private void doTest(AnnotationConfigEmbeddedWebApplicationContext context, String resourcePath, HttpStatus status) throws Exception { int port = context.getEmbeddedServletContainer().getPort(); - TestRestTemplate template = new TestRestTemplate(); + RestTemplate template = new RestTemplate(); ResponseEntity entity = template.getForEntity( new URI("http://localhost:" + port + resourcePath), String.class); assertThat(entity.getBody()).isEqualTo("Hello World"); @@ -176,4 +178,34 @@ public class ErrorPageFilterIntegrationTests { } + static class EmbeddedWebContextLoader extends AbstractContextLoader { + + private static final String[] EMPTY_RESOURCE_SUFFIXES = {}; + + @Override + public ApplicationContext loadContext(MergedContextConfiguration config) + throws Exception { + AnnotationConfigEmbeddedWebApplicationContext context = new AnnotationConfigEmbeddedWebApplicationContext( + config.getClasses()); + context.registerShutdownHook(); + return context; + } + + @Override + public ApplicationContext loadContext(String... locations) throws Exception { + throw new UnsupportedOptionException(); + } + + @Override + protected String[] getResourceSuffixes() { + return EMPTY_RESOURCE_SUFFIXES; + } + + @Override + protected String getResourceSuffix() { + throw new UnsupportedOptionException(); + } + + } + } diff --git a/spring-boot/src/test/java/org/springframework/boot/context/web/ErrorPageFilterTests.java b/spring-boot/src/test/java/org/springframework/boot/context/web/ErrorPageFilterTests.java index c2b358e93c..8d02080a79 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/web/ErrorPageFilterTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/web/ErrorPageFilterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 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. @@ -29,7 +29,7 @@ import org.junit.Rule; import org.junit.Test; import org.springframework.boot.context.embedded.ErrorPage; -import org.springframework.boot.test.OutputCapture; +import org.springframework.boot.testutil.OutputCapture; import org.springframework.http.HttpStatus; import org.springframework.mock.web.MockFilterChain; import org.springframework.mock.web.MockFilterConfig; diff --git a/spring-boot/src/test/java/org/springframework/boot/env/SpringApplicationJsonEnvironmentPostProcessorTests.java b/spring-boot/src/test/java/org/springframework/boot/env/SpringApplicationJsonEnvironmentPostProcessorTests.java index 281b740777..9c8936e49d 100644 --- a/spring-boot/src/test/java/org/springframework/boot/env/SpringApplicationJsonEnvironmentPostProcessorTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/env/SpringApplicationJsonEnvironmentPostProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 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. @@ -18,7 +18,7 @@ package org.springframework.boot.env; import org.junit.Test; -import org.springframework.boot.test.EnvironmentTestUtils; +import org.springframework.boot.testutil.EnvironmentTestUtils; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.StandardEnvironment; diff --git a/spring-boot/src/test/java/org/springframework/boot/logging/LoggingApplicationListenerTests.java b/spring-boot/src/test/java/org/springframework/boot/logging/LoggingApplicationListenerTests.java index dc627a2045..4b3868c398 100644 --- a/spring-boot/src/test/java/org/springframework/boot/logging/LoggingApplicationListenerTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/logging/LoggingApplicationListenerTests.java @@ -38,8 +38,8 @@ import org.slf4j.bridge.SLF4JBridgeHandler; import org.springframework.boot.SpringApplication; import org.springframework.boot.context.event.ApplicationStartedEvent; import org.springframework.boot.logging.java.JavaLoggingSystem; -import org.springframework.boot.test.EnvironmentTestUtils; -import org.springframework.boot.test.OutputCapture; +import org.springframework.boot.testutil.EnvironmentTestUtils; +import org.springframework.boot.testutil.OutputCapture; import org.springframework.context.event.ContextClosedEvent; import org.springframework.context.support.GenericApplicationContext; import org.springframework.test.util.ReflectionTestUtils; diff --git a/spring-boot/src/test/java/org/springframework/boot/logging/java/JavaLoggingSystemTests.java b/spring-boot/src/test/java/org/springframework/boot/logging/java/JavaLoggingSystemTests.java index f9a1af5941..a8a76eb0c1 100644 --- a/spring-boot/src/test/java/org/springframework/boot/logging/java/JavaLoggingSystemTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/logging/java/JavaLoggingSystemTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2016 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. @@ -29,7 +29,7 @@ import org.junit.Test; import org.springframework.boot.logging.AbstractLoggingSystemTests; import org.springframework.boot.logging.LogLevel; -import org.springframework.boot.test.OutputCapture; +import org.springframework.boot.testutil.OutputCapture; import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; diff --git a/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystemTests.java b/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystemTests.java index 969769461a..5c06cc9b8e 100644 --- a/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystemTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystemTests.java @@ -36,8 +36,8 @@ import org.junit.Test; import org.springframework.boot.logging.AbstractLoggingSystemTests; import org.springframework.boot.logging.LogLevel; -import org.springframework.boot.test.OutputCapture; -import org.springframework.boot.test.assertj.Matched; +import org.springframework.boot.testutil.Matched; +import org.springframework.boot.testutil.OutputCapture; import org.springframework.util.FileCopyUtils; import org.springframework.util.StringUtils; diff --git a/spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackLoggingSystemTests.java b/spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackLoggingSystemTests.java index 34ed791f28..9924d6e436 100644 --- a/spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackLoggingSystemTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackLoggingSystemTests.java @@ -39,8 +39,8 @@ import org.springframework.boot.logging.AbstractLoggingSystemTests; import org.springframework.boot.logging.LogFile; import org.springframework.boot.logging.LogLevel; import org.springframework.boot.logging.LoggingInitializationContext; -import org.springframework.boot.test.OutputCapture; -import org.springframework.boot.test.assertj.Matched; +import org.springframework.boot.testutil.Matched; +import org.springframework.boot.testutil.OutputCapture; import org.springframework.mock.env.MockEnvironment; import org.springframework.util.FileCopyUtils; import org.springframework.util.StringUtils; diff --git a/spring-boot/src/test/java/org/springframework/boot/logging/logback/SpringBootJoranConfiguratorTests.java b/spring-boot/src/test/java/org/springframework/boot/logging/logback/SpringBootJoranConfiguratorTests.java index fd390b7f7c..db5a5a9640 100644 --- a/spring-boot/src/test/java/org/springframework/boot/logging/logback/SpringBootJoranConfiguratorTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/logging/logback/SpringBootJoranConfiguratorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 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. @@ -28,8 +28,8 @@ import org.slf4j.Logger; import org.slf4j.impl.StaticLoggerBinder; import org.springframework.boot.logging.LoggingInitializationContext; -import org.springframework.boot.test.EnvironmentTestUtils; -import org.springframework.boot.test.OutputCapture; +import org.springframework.boot.testutil.EnvironmentTestUtils; +import org.springframework.boot.testutil.OutputCapture; import org.springframework.mock.env.MockEnvironment; import static org.assertj.core.api.Assertions.assertThat; diff --git a/spring-boot/src/test/java/org/springframework/boot/testutil/EnvironmentTestUtils.java b/spring-boot/src/test/java/org/springframework/boot/testutil/EnvironmentTestUtils.java new file mode 100644 index 0000000000..a1aa1eb680 --- /dev/null +++ b/spring-boot/src/test/java/org/springframework/boot/testutil/EnvironmentTestUtils.java @@ -0,0 +1,74 @@ +/* + * Copyright 2012-2016 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. + */ + +package org.springframework.boot.testutil; + +import java.util.HashMap; +import java.util.Map; + +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.core.env.MapPropertySource; +import org.springframework.core.env.MutablePropertySources; + +/** + * Internal test utilities for setting environment values. + * + * @author Dave Syer + * @author Stephane Nicoll + */ +public abstract class EnvironmentTestUtils { + + public static void addEnvironment(ConfigurableApplicationContext context, + String... pairs) { + addEnvironment(context.getEnvironment(), pairs); + } + + public static void addEnvironment(ConfigurableEnvironment environment, + String... pairs) { + MutablePropertySources sources = environment.getPropertySources(); + Map map = getOrAdd(sources); + for (String pair : pairs) { + int index = getSeparatorIndex(pair); + String key = pair.substring(0, index > 0 ? index : pair.length()); + String value = index > 0 ? pair.substring(index + 1) : ""; + map.put(key.trim(), value.trim()); + } + } + + @SuppressWarnings("unchecked") + private static Map getOrAdd(MutablePropertySources sources) { + if (sources.contains("test")) { + return (Map) sources.get("test").getSource(); + } + Map map = new HashMap(); + sources.addFirst(new MapPropertySource("test", map)); + return map; + } + + private static int getSeparatorIndex(String pair) { + int colonIndex = pair.indexOf(":"); + int equalIndex = pair.indexOf("="); + if (colonIndex == -1) { + return equalIndex; + } + if (equalIndex == -1) { + return colonIndex; + } + return Math.min(colonIndex, equalIndex); + } + +} diff --git a/spring-boot/src/main/java/org/springframework/boot/test/assertj/Matched.java b/spring-boot/src/test/java/org/springframework/boot/testutil/Matched.java similarity index 84% rename from spring-boot/src/main/java/org/springframework/boot/test/assertj/Matched.java rename to spring-boot/src/test/java/org/springframework/boot/testutil/Matched.java index 525ec20083..4ab4ee81b8 100644 --- a/spring-boot/src/main/java/org/springframework/boot/test/assertj/Matched.java +++ b/spring-boot/src/test/java/org/springframework/boot/testutil/Matched.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.test.assertj; +package org.springframework.boot.testutil; import org.assertj.core.api.Condition; import org.hamcrest.Matcher; @@ -25,16 +25,9 @@ import org.springframework.util.Assert; /** * Adapter class allowing a Hamcrest {@link Matcher} to be used as an AssertJ * {@link Condition}. - *

- * Usually used with the {@code is} method of {@code assertThat}, for example: - * - *

- * assertThat("1234").is(Matched.when(startsWith("12")));
- * 
* * @param The type of object that the condition accepts * @author Phillip Webb - * @since 1.4 */ public final class Matched extends Condition { diff --git a/spring-boot/src/test/java/org/springframework/boot/test/assertj/MatchedTests.java b/spring-boot/src/test/java/org/springframework/boot/testutil/MatchedTests.java similarity index 93% rename from spring-boot/src/test/java/org/springframework/boot/test/assertj/MatchedTests.java rename to spring-boot/src/test/java/org/springframework/boot/testutil/MatchedTests.java index a07a7501d5..bb1cc2306c 100644 --- a/spring-boot/src/test/java/org/springframework/boot/test/assertj/MatchedTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/testutil/MatchedTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.test.assertj; +package org.springframework.boot.testutil; import org.junit.Rule; import org.junit.Test; diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/util/OutputCapture.java b/spring-boot/src/test/java/org/springframework/boot/testutil/OutputCapture.java similarity index 70% rename from spring-boot-cli/src/test/java/org/springframework/boot/cli/util/OutputCapture.java rename to spring-boot/src/test/java/org/springframework/boot/testutil/OutputCapture.java index 41f19e2c18..89b1faf5b0 100644 --- a/spring-boot-cli/src/test/java/org/springframework/boot/cli/util/OutputCapture.java +++ b/spring-boot/src/test/java/org/springframework/boot/testutil/OutputCapture.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2016 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. @@ -14,21 +14,31 @@ * limitations under the License. */ -package org.springframework.boot.cli.util; +package org.springframework.boot.testutil; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; import java.io.PrintStream; +import java.util.ArrayList; +import java.util.List; +import org.hamcrest.Matcher; +import org.junit.Assert; import org.junit.rules.TestRule; import org.junit.runner.Description; import org.junit.runners.model.Statement; +import org.springframework.boot.ansi.AnsiOutput; +import org.springframework.boot.ansi.AnsiOutput.Enabled; + +import static org.hamcrest.Matchers.allOf; + /** - * Capture output from System.out and System.err. + * Internal JUnit {@code @Rule} to capture output from System.out and System.err. * * @author Phillip Webb + * @author Andy Wilkinson */ public class OutputCapture implements TestRule { @@ -38,6 +48,8 @@ public class OutputCapture implements TestRule { private ByteArrayOutputStream copy; + private List> matchers = new ArrayList>(); + @Override public Statement apply(final Statement base, Description description) { return new Statement() { @@ -48,13 +60,22 @@ public class OutputCapture implements TestRule { base.evaluate(); } finally { - releaseOutput(); + try { + if (!OutputCapture.this.matchers.isEmpty()) { + String output = OutputCapture.this.toString(); + Assert.assertThat(output, allOf(OutputCapture.this.matchers)); + } + } + finally { + releaseOutput(); + } } } }; } protected void captureOutput() { + AnsiOutput.setEnabled(Enabled.NEVER); this.copy = new ByteArrayOutputStream(); this.captureOut = new CaptureOutputStream(System.out, this.copy); this.captureErr = new CaptureOutputStream(System.err, this.copy); @@ -63,6 +84,7 @@ public class OutputCapture implements TestRule { } protected void releaseOutput() { + AnsiOutput.setEnabled(Enabled.DETECT); System.setOut(this.captureOut.getOriginal()); System.setErr(this.captureErr.getOriginal()); this.copy = null; @@ -84,6 +106,15 @@ public class OutputCapture implements TestRule { return this.copy.toString(); } + /** + * Verify that the output is matched by the supplied {@code matcher}. Verification is + * performed after the test method has executed. + * @param matcher the matcher + */ + public void expect(Matcher matcher) { + this.matchers.add(matcher); + } + private static class CaptureOutputStream extends OutputStream { private final PrintStream original; @@ -122,6 +153,7 @@ public class OutputCapture implements TestRule { this.copy.flush(); this.original.flush(); } + } }