Esempio n. 1
0
 @Test
 public void testMatchesSafely1() {
   // サブクラスも合格と判定する。
   assertThat(
       Testee.of(
           () -> {
             throw new Exception();
           }),
       not(RootCause.rootCause(RuntimeException.class)));
   assertThat(
       Testee.of(
           () -> {
             throw new RuntimeException();
           }),
       RootCause.rootCause(RuntimeException.class));
   assertThat(
       Testee.of(
           () -> {
             throw new NullPointerException();
           }),
       RootCause.rootCause(RuntimeException.class));
 }
Esempio n. 2
0
  @Test
  public void testMatchesSafely2() {
    // 型は考慮せずメッセージのみに基づいて判定する
    assertThat(
        Testee.of(
            () -> {
              throw new Throwable("msg");
            }),
        RootCause.rootCause("msg"));
    assertThat(
        Testee.of(
            () -> {
              throw new Error("msg");
            }),
        RootCause.rootCause("msg"));
    assertThat(
        Testee.of(
            () -> {
              throw new Exception("msg");
            }),
        RootCause.rootCause("msg"));
    assertThat(
        Testee.of(
            () -> {
              throw new RuntimeException("msg");
            }),
        RootCause.rootCause("msg"));

    assertThat(
        Testee.of(
            () -> {
              throw new Throwable((String) null);
            }),
        RootCause.rootCause((String) null));

    assertThat(
        Testee.of(
            () -> {
              throw new Throwable("diff");
            }),
        not(RootCause.rootCause("msg")));
  }