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 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));
 }
Esempio n. 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")));
  }
Esempio n. 4
0
 @Test(expected = NullPointerException.class)
 public void testRootCause4() {
   RootCause.rootCause((Matcher<Throwable>) null);
 }
Esempio n. 5
0
 @Test(expected = NullPointerException.class)
 public void testRootCause3() {
   RootCause.rootCause(null, "message");
 }
Esempio n. 6
0
 @Test(expected = NullPointerException.class)
 public void testRootCause2() {
   RootCause.rootCause((Class<? extends Throwable>) null);
 }