ThrowableUtils { public static boolean hasCauseMessage(Throwable throwable, String message) { if (throwable.getMessage().contains(message)) { return true; } Throwable cause; while ((cause = throwable.getCause()) != null) { throwable = cause; if (throwable.getMessage().contains(message)) { 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 hasCauseMessageForNullShouldThrowNullPointerException() { Throwable thrown = catchThrowable(() -> hasCauseMessage(null, "message")); assertThat(thrown).isExactlyInstanceOf(NullPointerException.class); }
@Test public void hasCauseMessageOfNullShouldThrowNullPointerException() { Throwable thrown = catchThrowable(() -> hasCauseMessage(new OneException(), null)); assertThat(thrown).isExactlyInstanceOf(NullPointerException.class); }
@Test public void hasCauseMessageForNullMessageShouldThrowNullPointerException() { Throwable thrown = catchThrowable(() -> hasCauseMessage(new OneException((String) null), null)); assertThat(thrown).isExactlyInstanceOf(NullPointerException.class); }
@Test public void hasCauseMessageOfNonMatchingNullMessageShouldThrowNullPointerException() { Throwable thrown = catchThrowable(() -> hasCauseMessage(new OneException("message"), null)); assertThat(thrown).isExactlyInstanceOf(NullPointerException.class); }
@Test public void hasCauseMessageOfEmptyMessageShouldReturnTrue() { assertThat(hasCauseMessage(new OneException(""), "")).isTrue(); }
@Test public void hasCauseMessageOfMatchingMessageShouldReturnTrue() { assertThat(hasCauseMessage(new OneException("message"), "message")).isTrue(); }
@Test public void hasCauseMessageOfNonMatchingMessageShouldReturnFalse() { assertThat(hasCauseMessage(new OneException("non-matching"), "message")).isFalse(); }
@Test public void hasCauseMessageOfContainedMessageShouldReturnTrue() { assertThat(hasCauseMessage(new OneException("this is the message"), "message")).isTrue(); }
@Test public void hasCauseMessageOfPartialMatchingMessageShouldReturnFalse() { assertThat(hasCauseMessage(new OneException("message"), "this is the message")).isFalse(); }