ThrowableUtils { public static boolean hasCauseType(Throwable throwable, Class<? extends Throwable> causeClass) { if (causeClass.isInstance(throwable)) { return true; } Throwable cause; while ((cause = throwable.getCause()) != null) { throwable = cause; if (causeClass.isInstance(throwable)) { return true; } } return false; }  static Throwable getRootCause(Throwable throwable); static boolean hasCauseType(Throwable throwable, Class<? extends Throwable> causeClass); static boolean hasCauseMessage(Throwable throwable, String message); static void setRootCause(Throwable exception, Throwable newRootCause);  }
@Test public void hasCauseTypeOfNullClassShouldThrowNullPointerException() { Throwable thrown = catchThrowable(() -> hasCauseType(new Exception(), null)); assertThat(thrown).isExactlyInstanceOf(NullPointerException.class); }
@Test public void hasCauseTypeOfNullThrowableShouldThrowNullPointerException() { Throwable thrown = catchThrowable(() -> hasCauseType(null, Exception.class)); assertThat(thrown).isExactlyInstanceOf(NullPointerException.class); }
@Test public void hasCauseTypeOfNonMatchingShouldReturnFalse() { assertThat(hasCauseType(new OneException(), OtherException.class)).isFalse(); }
@Test public void hasCauseTypeOfSameClassShouldReturnTrue() { assertThat(hasCauseType(new OneException(), OneException.class)).isTrue(); }
@Test public void hasCauseTypeOfSuperClassShouldReturnFalse() { assertThat(hasCauseType(new OneException(), SubException.class)).isFalse(); }
@Test public void hasCauseTypeOfSubClassShouldReturnTrue() { assertThat(hasCauseType(new SubException(), OneException.class)).isTrue(); }
@Test public void hasCauseTypeOfWrappedClassShouldReturnTrue() { assertThat(hasCauseType(new OneException(new TwoException()), TwoException.class)).isTrue(); }
@Test public void hasCauseTypeOfWrappingClassShouldReturnTrue() { assertThat(hasCauseType(new OneException(new TwoException()), OneException.class)).isTrue(); }
@Test public void hasCauseTypeOfNestedClassShouldReturnTrue() { assertThat(hasCauseType(new OneException(new TwoException(new OtherException())), OtherException.class)).isTrue(); }