|
21 | 21 | import java.time.Duration;
|
22 | 22 | import java.util.List;
|
23 | 23 | import java.util.concurrent.atomic.AtomicInteger;
|
| 24 | +import java.util.function.Consumer; |
24 | 25 |
|
| 26 | +import org.assertj.core.api.ThrowingConsumer; |
25 | 27 | import org.junit.jupiter.api.BeforeEach;
|
26 | 28 | import org.junit.jupiter.api.Test;
|
27 | 29 | import org.junit.jupiter.params.ParameterizedTest;
|
|
32 | 34 |
|
33 | 35 | import static org.assertj.core.api.Assertions.assertThat;
|
34 | 36 | import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
35 |
| -import static org.assertj.core.api.InstanceOfAssertFactories.array; |
36 | 37 | import static org.junit.jupiter.params.provider.Arguments.argumentSet;
|
37 | 38 |
|
38 | 39 | /**
|
@@ -176,11 +177,10 @@ public String getName() {
|
176 | 177 | .isThrownBy(() -> retryTemplate.execute(retryable))
|
177 | 178 | .withMessage("Retry policy for operation 'test' exhausted; aborting execution")
|
178 | 179 | .withCauseExactlyInstanceOf(IllegalStateException.class)
|
179 |
| - .extracting(Throwable::getSuppressed, array(Throwable[].class)) |
180 |
| - .satisfiesExactly( |
| 180 | + .satisfies(hasSuppressedExceptionsSatisfyingExactly( |
181 | 181 | suppressed1 -> assertThat(suppressed1).isExactlyInstanceOf(IOException.class),
|
182 | 182 | suppressed2 -> assertThat(suppressed2).isExactlyInstanceOf(FileNotFoundException.class)
|
183 |
| - ); |
| 183 | + )); |
184 | 184 | // 3 = 1 initial invocation + 2 retry attempts
|
185 | 185 | assertThat(invocationCount).hasValue(3);
|
186 | 186 | }
|
@@ -228,16 +228,22 @@ public String getName() {
|
228 | 228 | .isThrownBy(() -> retryTemplate.execute(retryable))
|
229 | 229 | .withMessage("Retry policy for operation 'test' exhausted; aborting execution")
|
230 | 230 | .withCauseExactlyInstanceOf(CustomFileNotFoundException.class)
|
231 |
| - .extracting(Throwable::getSuppressed, array(Throwable[].class)) |
232 |
| - .satisfiesExactly( |
| 231 | + .satisfies(hasSuppressedExceptionsSatisfyingExactly( |
233 | 232 | suppressed1 -> assertThat(suppressed1).isExactlyInstanceOf(IOException.class),
|
234 | 233 | suppressed2 -> assertThat(suppressed2).isExactlyInstanceOf(IOException.class)
|
235 |
| - ); |
| 234 | + )); |
236 | 235 | // 3 = 1 initial invocation + 2 retry attempts
|
237 | 236 | assertThat(invocationCount).hasValue(3);
|
238 | 237 | }
|
239 | 238 |
|
240 | 239 |
|
| 240 | + @SafeVarargs |
| 241 | + private static final Consumer<Throwable> hasSuppressedExceptionsSatisfyingExactly( |
| 242 | + ThrowingConsumer<? super Throwable>... requirements) { |
| 243 | + return throwable -> assertThat(throwable.getSuppressed()).satisfiesExactly(requirements); |
| 244 | + } |
| 245 | + |
| 246 | + |
241 | 247 | @SuppressWarnings("serial")
|
242 | 248 | private static class CustomFileNotFoundException extends FileNotFoundException {
|
243 | 249 | }
|
|
0 commit comments