From b6166dc12a273d8babcd44defbe07c9ebdb12264 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Fri, 3 Nov 2017 14:08:39 -0700 Subject: [PATCH] Move `Assume` to spring-boot-test-support Fixes gh-10866 --- .../condition/ConditionalOnJavaTests.java | 8 ++++---- .../LiquibaseAutoConfigurationTests.java | 5 ++--- .../boot/testsupport}/Assume.java | 19 ++++++------------- 3 files changed, 12 insertions(+), 20 deletions(-) rename spring-boot-project/{spring-boot-test/src/main/java/org/springframework/boot/test => spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport}/Assume.java (62%) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnJavaTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnJavaTests.java index 1dafd14291..34e3f00baf 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnJavaTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnJavaTests.java @@ -25,9 +25,9 @@ import org.junit.Test; import org.springframework.boot.autoconfigure.condition.ConditionalOnJava.Range; 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.runner.ApplicationContextRunner; +import org.springframework.boot.testsupport.Assume; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.util.ReflectionUtils; @@ -48,7 +48,7 @@ public class ConditionalOnJavaTests { @Test public void doesNotMatchIfBetterVersionIsRequired() { - Assume.javaVersion(JavaVersion.EIGHT); + Assume.javaEight(); this.contextRunner.withUserConfiguration(Java9Required.class) .run((context) -> assertThat(context).doesNotHaveBean(String.class)); } @@ -93,13 +93,13 @@ public class ConditionalOnJavaTests { @Test public void java8IsDetected() throws Exception { - Assume.javaVersion(JavaVersion.EIGHT); + Assume.javaEight(); assertThat(getJavaVersion()).isEqualTo("1.8"); } @Test public void java8IsTheFallback() throws Exception { - Assume.javaVersion(JavaVersion.EIGHT); + Assume.javaEight(); assertThat(getJavaVersion(Function.class, Files.class, ServiceLoader.class)) .isEqualTo("1.8"); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfigurationTests.java index 8450d5f9ca..4144316b2c 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfigurationTests.java @@ -36,12 +36,11 @@ import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfigurati import org.springframework.boot.jdbc.DataSourceBuilder; import org.springframework.boot.liquibase.CommonsLoggingLiquibaseLogger; 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.runner.ApplicationContextRunner; import org.springframework.boot.test.context.runner.ContextConsumer; import org.springframework.boot.test.rule.OutputCapture; +import org.springframework.boot.testsupport.Assume; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; @@ -114,7 +113,7 @@ public class LiquibaseAutoConfigurationTests { @Test public void changelogSql() { - Assume.javaVersion(JavaVersion.EIGHT); + Assume.javaEight(); this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) .withPropertyValues( "spring.liquibase.change-log:classpath:/db/changelog/db.changelog-override.sql") diff --git a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/Assume.java b/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/Assume.java similarity index 62% rename from spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/Assume.java rename to spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/Assume.java index e2cc962faf..0af4815bcf 100644 --- a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/Assume.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/Assume.java @@ -14,11 +14,11 @@ * limitations under the License. */ -package org.springframework.boot.test; +package org.springframework.boot.testsupport; 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 @@ -26,20 +26,13 @@ import org.springframework.boot.system.JavaVersion; * skipped. * * @author Stephane Nicoll - * @since 2.0.0 */ public abstract class Assume { - /** - * Assume that the specified {@link JavaVersion} is the one currently available. - * @param version the expected Java version - * @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); + public static void javaEight() { + if (ClassUtils.isPresent("java.security.cert.URICertStoreParameters", null)) { + throw new AssumptionViolatedException("Assumed Java 8 but got Java 9"); + } } }