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