Move `Assume` to spring-boot-test-support

Fixes gh-10866
pull/10906/merge
Phillip Webb 7 years ago
parent 427d262297
commit b6166dc12a

@ -25,9 +25,9 @@ import org.junit.Test;
import org.springframework.boot.autoconfigure.condition.ConditionalOnJava.Range; import org.springframework.boot.autoconfigure.condition.ConditionalOnJava.Range;
import org.springframework.boot.system.JavaVersion; import org.springframework.boot.system.JavaVersion;
import org.springframework.boot.test.Assume;
import org.springframework.boot.test.context.HideClassesClassLoader; import org.springframework.boot.test.context.HideClassesClassLoader;
import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.boot.testsupport.Assume;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.util.ReflectionUtils; import org.springframework.util.ReflectionUtils;
@ -48,7 +48,7 @@ public class ConditionalOnJavaTests {
@Test @Test
public void doesNotMatchIfBetterVersionIsRequired() { public void doesNotMatchIfBetterVersionIsRequired() {
Assume.javaVersion(JavaVersion.EIGHT); Assume.javaEight();
this.contextRunner.withUserConfiguration(Java9Required.class) this.contextRunner.withUserConfiguration(Java9Required.class)
.run((context) -> assertThat(context).doesNotHaveBean(String.class)); .run((context) -> assertThat(context).doesNotHaveBean(String.class));
} }
@ -93,13 +93,13 @@ public class ConditionalOnJavaTests {
@Test @Test
public void java8IsDetected() throws Exception { public void java8IsDetected() throws Exception {
Assume.javaVersion(JavaVersion.EIGHT); Assume.javaEight();
assertThat(getJavaVersion()).isEqualTo("1.8"); assertThat(getJavaVersion()).isEqualTo("1.8");
} }
@Test @Test
public void java8IsTheFallback() throws Exception { public void java8IsTheFallback() throws Exception {
Assume.javaVersion(JavaVersion.EIGHT); Assume.javaEight();
assertThat(getJavaVersion(Function.class, Files.class, ServiceLoader.class)) assertThat(getJavaVersion(Function.class, Files.class, ServiceLoader.class))
.isEqualTo("1.8"); .isEqualTo("1.8");
} }

@ -36,12 +36,11 @@ import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfigurati
import org.springframework.boot.jdbc.DataSourceBuilder; import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.boot.liquibase.CommonsLoggingLiquibaseLogger; import org.springframework.boot.liquibase.CommonsLoggingLiquibaseLogger;
import org.springframework.boot.liquibase.LiquibaseServiceLocatorApplicationListener; import org.springframework.boot.liquibase.LiquibaseServiceLocatorApplicationListener;
import org.springframework.boot.system.JavaVersion;
import org.springframework.boot.test.Assume;
import org.springframework.boot.test.context.assertj.AssertableApplicationContext; import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.boot.test.context.runner.ContextConsumer; import org.springframework.boot.test.context.runner.ContextConsumer;
import org.springframework.boot.test.rule.OutputCapture; import org.springframework.boot.test.rule.OutputCapture;
import org.springframework.boot.testsupport.Assume;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary; import org.springframework.context.annotation.Primary;
@ -114,7 +113,7 @@ public class LiquibaseAutoConfigurationTests {
@Test @Test
public void changelogSql() { public void changelogSql() {
Assume.javaVersion(JavaVersion.EIGHT); Assume.javaEight();
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
.withPropertyValues( .withPropertyValues(
"spring.liquibase.change-log:classpath:/db/changelog/db.changelog-override.sql") "spring.liquibase.change-log:classpath:/db/changelog/db.changelog-override.sql")

@ -14,11 +14,11 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.test; package org.springframework.boot.testsupport;
import org.junit.AssumptionViolatedException; import org.junit.AssumptionViolatedException;
import org.springframework.boot.system.JavaVersion; import org.springframework.util.ClassUtils;
/** /**
* Provides utility methods that allow JUnit tests to {@link org.junit.Assume} certain * Provides utility methods that allow JUnit tests to {@link org.junit.Assume} certain
@ -26,20 +26,13 @@ import org.springframework.boot.system.JavaVersion;
* skipped. * skipped.
* *
* @author Stephane Nicoll * @author Stephane Nicoll
* @since 2.0.0
*/ */
public abstract class Assume { public abstract class Assume {
/** public static void javaEight() {
* Assume that the specified {@link JavaVersion} is the one currently available. if (ClassUtils.isPresent("java.security.cert.URICertStoreParameters", null)) {
* @param version the expected Java version throw new AssumptionViolatedException("Assumed Java 8 but got Java 9");
* @throws AssumptionViolatedException if the assumption fails }
*/
public static void javaVersion(JavaVersion version) {
JavaVersion current = JavaVersion.getJavaVersion();
org.junit.Assume.assumeTrue(
String.format("This test should run on %s (got %s)", version, current),
current == version);
} }
} }
Loading…
Cancel
Save