Beispiel #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));
 }
Beispiel #2
0
 @Test
 public void testRootCause1() {
   // インスタンス化の検査
   assertThat(RootCause.rootCause(Throwable.class), instanceOf(RootCause.class));
   assertThat(RootCause.rootCause(Exception.class, "message"), instanceOf(RootCause.class));
   assertThat(RootCause.rootCause(RuntimeException.class, null), instanceOf(RootCause.class));
   assertThat(RootCause.rootCause("message"), instanceOf(RootCause.class));
   assertThat(RootCause.rootCause((String) null), instanceOf(RootCause.class));
   assertThat(RootCause.rootCause(new TestMatcher()), instanceOf(RootCause.class));
 }
Beispiel #3
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")));
  }
Beispiel #4
0
 @Test(expected = NullPointerException.class)
 public void testRootCause4() {
   RootCause.rootCause((Matcher<Throwable>) null);
 }
Beispiel #5
0
 @Test(expected = NullPointerException.class)
 public void testRootCause3() {
   RootCause.rootCause(null, "message");
 }
Beispiel #6
0
 @Test(expected = NullPointerException.class)
 public void testRootCause2() {
   RootCause.rootCause((Class<? extends Throwable>) null);
 }