From 742c41a568eac35b41b4d15913dda244bf2bb1d4 Mon Sep 17 00:00:00 2001 From: Sam Brannen <104798+sbrannen@users.noreply.github.com> Date: Fri, 31 May 2024 16:18:31 +0200 Subject: [PATCH] Polishing --- .../test/context/junit/EngineTestKitUtils.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/spring-test/src/test/java/org/springframework/test/context/junit/EngineTestKitUtils.java b/spring-test/src/test/java/org/springframework/test/context/junit/EngineTestKitUtils.java index f66ed13aa37..06150380dc4 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit/EngineTestKitUtils.java +++ b/spring-test/src/test/java/org/springframework/test/context/junit/EngineTestKitUtils.java @@ -24,6 +24,8 @@ import org.assertj.core.api.Condition; import org.junit.platform.testkit.engine.EngineTestKit; import org.junit.platform.testkit.engine.Events; +import org.springframework.core.NestedExceptionUtils; + import static java.util.stream.Collectors.toList; import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass; @@ -42,6 +44,11 @@ public class EngineTestKitUtils { .testEvents(); } + /** + * Create a new {@link Condition} that matches if and only if a + * {@link Throwable}'s root {@linkplain Throwable#getCause() cause} matches + * all supplied conditions. + */ @SafeVarargs @SuppressWarnings("varargs") public static Condition rootCause(Condition... conditions) { @@ -53,16 +60,8 @@ public class EngineTestKitUtils { } private static Condition rootCause(Condition condition) { - return new Condition<>(throwable -> condition.matches(getRootCause(throwable)), + return new Condition<>(throwable -> condition.matches(NestedExceptionUtils.getRootCause(throwable)), "throwable root cause matches %s", condition); } - private static Throwable getRootCause(Throwable throwable) { - Throwable cause = throwable.getCause(); - if (cause == null) { - return throwable; - } - return getRootCause(cause); - } - }