Skip to content

Commit 742c41a

Browse files
committed
Polishing
1 parent 3a44870 commit 742c41a

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

spring-test/src/test/java/org/springframework/test/context/junit/EngineTestKitUtils.java

+8-9
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import org.junit.platform.testkit.engine.EngineTestKit;
2525
import org.junit.platform.testkit.engine.Events;
2626

27+
import org.springframework.core.NestedExceptionUtils;
28+
2729
import static java.util.stream.Collectors.toList;
2830
import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass;
2931

@@ -42,6 +44,11 @@ public static Events executeTestsForClass(Class<?> testClass) {
4244
.testEvents();
4345
}
4446

47+
/**
48+
* Create a new {@link Condition} that matches if and only if a
49+
* {@link Throwable}'s root {@linkplain Throwable#getCause() cause} matches
50+
* all supplied conditions.
51+
*/
4552
@SafeVarargs
4653
@SuppressWarnings("varargs")
4754
public static Condition<Throwable> rootCause(Condition<Throwable>... conditions) {
@@ -53,16 +60,8 @@ public static Condition<Throwable> rootCause(Condition<Throwable>... conditions)
5360
}
5461

5562
private static Condition<Throwable> rootCause(Condition<Throwable> condition) {
56-
return new Condition<>(throwable -> condition.matches(getRootCause(throwable)),
63+
return new Condition<>(throwable -> condition.matches(NestedExceptionUtils.getRootCause(throwable)),
5764
"throwable root cause matches %s", condition);
5865
}
5966

60-
private static Throwable getRootCause(Throwable throwable) {
61-
Throwable cause = throwable.getCause();
62-
if (cause == null) {
63-
return throwable;
64-
}
65-
return getRootCause(cause);
66-
}
67-
6867
}

0 commit comments

Comments
 (0)