private void test(String useCase, Class<?> testClass, Callback callback) throws Exception { TestContextManager testContextManager = new TestContextManager(testClass); assertEquals("Registered TestExecutionListeners", 2, testContextManager.getTestExecutionListeners().size()); try { Method testMethod = getClass().getMethod("toString"); callback.invoke(testContextManager, testClass, testMethod); fail("should have thrown an AssertionError"); } catch (AssertionError err) { // 'after' callbacks are reversed, so 2 comes before 1. assertEquals(useCase + "-2", err.getMessage()); Throwable[] suppressed = err.getSuppressed(); assertEquals(1, suppressed.length); assertEquals(useCase + "-1", suppressed[0].getMessage()); } }
@Test public void consumeWhileErrorIsSuppressed() { assertThatExceptionOfType(AssertionError.class) .isThrownBy(() -> StepVerifier.create(Flux.just("foo", "bar", "foobar") .map(r -> { if (r.length() > 3) throw new ArrayIndexOutOfBoundsException(); return r;})) .thenConsumeWhile(s -> s.length() <= 3) //doesn't fail by itself... .verifyComplete()) //...so this will fail .satisfies(error -> { assertThat(error) .hasMessageStartingWith("expectation \"expectComplete\" failed") .hasMessageContaining("actual: onError(java.lang.ArrayIndexOutOfBoundsException)"); assertThat(error.getSuppressed()) .hasSize(1) .allMatch(spr -> spr instanceof ArrayIndexOutOfBoundsException); }); }
@Test public void consumeNextErrorIsSuppressed() { assertThatExceptionOfType(AssertionError.class) .isThrownBy(() -> StepVerifier.create(Flux.just("foo") .flatMap(r -> { throw new ArrayIndexOutOfBoundsException();})) .consumeNextWith(v -> assertThat(v).isNotNull()) .verifyError()) .satisfies(error -> { assertThat(error) .hasMessageStartingWith("expectation \"consumeNextWith\" failed") .hasMessageContaining("actual: onError(java.lang.ArrayIndexOutOfBoundsException)"); assertThat(error.getSuppressed()) .hasSize(1) .allMatch(spr -> spr instanceof ArrayIndexOutOfBoundsException); }); }
@Test public void expectNextSequenceErrorIsSuppressed() { assertThatExceptionOfType(AssertionError.class) .isThrownBy(() -> StepVerifier.create(Flux.just("foo") .flatMap(r -> { throw new ArrayIndexOutOfBoundsException();})) .expectNextSequence(Arrays.asList("foo")) .verifyError()) .satisfies(error -> { assertThat(error) .hasMessageStartingWith("expectation \"expectNextSequence\" failed") .hasMessageContaining("actual signal: onError(java.lang.ArrayIndexOutOfBoundsException)"); assertThat(error.getSuppressed()) .hasSize(1) .allMatch(spr -> spr instanceof ArrayIndexOutOfBoundsException); }); }
@Test public void expectNextErrorIsSuppressed() { assertThatExceptionOfType(AssertionError.class) .isThrownBy(() -> StepVerifier.create(Flux.just("foo") .flatMap(r -> { throw new ArrayIndexOutOfBoundsException();})) .expectNext("foo") .verifyError()) .satisfies(error -> { assertThat(error) .hasMessageStartingWith("expectation \"expectNext(foo)\" failed") .hasMessageContaining("actual: onError(java.lang.ArrayIndexOutOfBoundsException)"); assertThat(error.getSuppressed()) .hasSize(1) .allMatch(spr -> spr instanceof ArrayIndexOutOfBoundsException); }); }
@Test public void expectNextCountErrorIsSuppressed() { assertThatExceptionOfType(AssertionError.class) .isThrownBy(() -> StepVerifier.create(Flux.just("foo") .flatMap(r -> { throw new ArrayIndexOutOfBoundsException();})) .expectNextCount(1) .verifyError()) .satisfies(error -> { assertThat(error) .hasMessageStartingWith("expectation \"expectNextCount(1)\" failed") .hasMessageContaining("signal: onError(java.lang.ArrayIndexOutOfBoundsException)"); assertThat(error.getSuppressed()) .hasSize(1) .allMatch(spr -> spr instanceof ArrayIndexOutOfBoundsException); }); }
protected void apply(Iterable<Holder> holders, Callable callable) { AssertionError errors = new AssertionError("invoke on features error " + holders); for (Holder each : holders) { try { callable.call(each); } catch (AssumptionViolatedException cause) { throw cause; } catch (Throwable cause) { errors.addSuppressed(cause); if (cause instanceof InterruptedException) { Thread.currentThread().interrupt(); throw new AssertionError("Interrupted on invoke features", errors); } } } if (errors.getSuppressed().length > 0) { throw errors; } }
if (errors.getSuppressed().length > 0) { throw errors;