public static Throwable getRootCause(Throwable throwable) {
    if (throwable == null) {
      return null;
    }
    Throwable rootCause = throwable;
    // this is to avoid infinite loops for recursive cases
    final Set<Throwable> seenThrowables = new HashSet<>();
    seenThrowables.add(rootCause);
    while ((rootCause.getCause() != null && !seenThrowables.contains(rootCause.getCause()))) {
      seenThrowables.add(rootCause.getCause());
      rootCause = rootCause.getCause();
    }
    return rootCause;
  }
@Test
  void rootCauseIsSelf() {
    Throwable e = new Exception();
    Throwable rootCause = ExceptionUtils.getRootCause(e);
    assertThat(rootCause).isSameAs(e);
  }