diff --git a/spring-boot-test/src/main/java/org/springframework/boot/test/context/runner/AbstractApplicationContextRunner.java b/spring-boot-test/src/main/java/org/springframework/boot/test/context/runner/AbstractApplicationContextRunner.java index 37d54d125c..4462d80742 100644 --- a/spring-boot-test/src/main/java/org/springframework/boot/test/context/runner/AbstractApplicationContextRunner.java +++ b/spring-boot-test/src/main/java/org/springframework/boot/test/context/runner/AbstractApplicationContextRunner.java @@ -34,7 +34,6 @@ import org.springframework.core.ResolvableType; import org.springframework.core.env.Environment; import org.springframework.core.io.DefaultResourceLoader; import org.springframework.util.Assert; -import org.springframework.util.ReflectionUtils; /** * Utility design to run and an {@link ApplicationContext} and provide AssertJ style @@ -293,7 +292,19 @@ abstract class AbstractApplicationContextRunner void throwAny(Throwable e) throws E { + throw (E) e; } } diff --git a/spring-boot-test/src/main/java/org/springframework/boot/test/util/TestPropertyValues.java b/spring-boot-test/src/main/java/org/springframework/boot/test/util/TestPropertyValues.java index ec3cdd8a10..ddce95144d 100644 --- a/spring-boot-test/src/main/java/org/springframework/boot/test/util/TestPropertyValues.java +++ b/spring-boot-test/src/main/java/org/springframework/boot/test/util/TestPropertyValues.java @@ -45,6 +45,7 @@ import org.springframework.util.StringUtils; * * @author Madhura Bhave * @author Phillip Webb + * @author Stephane Nicoll * @since 2.0.0 */ public final class TestPropertyValues { @@ -128,11 +129,9 @@ public final class TestPropertyValues { try (SystemPropertiesHandler handler = new SystemPropertiesHandler()) { return call.call(); } - catch (RuntimeException ex) { - throw ex; - } catch (Exception ex) { - throw new IllegalStateException(ex); + AnyThrow.throwUnchecked(ex); + return null; // never reached } } @@ -311,4 +310,16 @@ public final class TestPropertyValues { } + private static class AnyThrow { + + static void throwUnchecked(Throwable e) { + AnyThrow.throwAny(e); + } + + @SuppressWarnings("unchecked") + private static void throwAny(Throwable e) throws E { + throw (E) e; + } + } + } diff --git a/spring-boot-test/src/test/java/org/springframework/boot/test/context/runner/AbstractApplicationContextRunnerTests.java b/spring-boot-test/src/test/java/org/springframework/boot/test/context/runner/AbstractApplicationContextRunnerTests.java index ce0d95e36f..15bc03d3fa 100644 --- a/spring-boot-test/src/test/java/org/springframework/boot/test/context/runner/AbstractApplicationContextRunnerTests.java +++ b/spring-boot-test/src/test/java/org/springframework/boot/test/context/runner/AbstractApplicationContextRunnerTests.java @@ -16,6 +16,7 @@ package org.springframework.boot.test.context.runner; +import java.io.IOException; import java.util.UUID; import com.google.gson.Gson; @@ -161,8 +162,21 @@ public abstract class AbstractApplicationContextRunnerTests { + this.thrown.expect(IOException.class); + this.thrown.expectMessage("Expected message"); + throwCheckedException("Expected message"); + }); + } + protected abstract T get(); + private static void throwCheckedException(String message) throws IOException { + throw new IOException(message); + } + @Configuration static class FailingConfig {