java.lang.AssertionError.getSuppressed()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(5.0k)|赞(0)|评价(0)|浏览(166)

本文整理了Java中java.lang.AssertionError.getSuppressed()方法的一些代码示例,展示了AssertionError.getSuppressed()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AssertionError.getSuppressed()方法的具体详情如下:
包路径:java.lang.AssertionError
类名称:AssertionError
方法名:getSuppressed

AssertionError.getSuppressed介绍

暂无

代码示例

代码示例来源:origin: spring-projects/spring-framework

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());
  }
}

代码示例来源:origin: reactor/reactor-core

@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);
      });
}

代码示例来源:origin: reactor/reactor-core

@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);
      });
}

代码示例来源:origin: reactor/reactor-core

@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);
      });
}

代码示例来源:origin: reactor/reactor-core

@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);
      });
}

代码示例来源:origin: reactor/reactor-core

@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);
      });
}

代码示例来源:origin: org.nuxeo.runtime/nuxeo-runtime-test

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;
  }
}

代码示例来源:origin: org.nuxeo.runtime/nuxeo-runtime-test

if (errors.getSuppressed().length > 0) {
  throw errors;

相关文章