ExceptionUtil { public static List<Throwable> getCauses(Throwable throwable) { return getCauses(throwable, false); }  static boolean causedBy(Throwable throwable, Class<? extends Throwable> causeType); static Throwable getRootCause(Throwable throwable); static List<Throwable> getCauses(Throwable throwable); static List<Throwable> getCauses(Throwable throwable, boolean reversed); static RuntimeException toRuntimeException(Exception exception); static RuntimeException toRuntimeException(Exception exception,
            Class<? extends RuntimeException> runtimeExceptionClass); static void throwExceptionOrError(Throwable throwable); static void throwRuntimeExceptionOrError(Throwable throwable); static String getStackTrace(Throwable throwable);  }
@Test public void getCauses() { assertTrue(ExceptionUtil.getCauses(null).isEmpty()); List<Throwable> es = ExceptionUtil.getCauses(new IOException()); assertEquals(1, es.size()); Iterator<Throwable> i = es.iterator(); assertThat(i.next(), instanceOf(IOException.class)); es = ExceptionUtil.getCauses(getException()); assertEquals(3, es.size()); i = es.iterator(); assertThat(i.next(), instanceOf(IOException.class)); assertThat(i.next(), instanceOf(IllegalArgumentException.class)); assertThat(i.next(), instanceOf(IllegalStateException.class)); es = ExceptionUtil.getCauses(getException(), false); assertEquals(3, es.size()); i = es.iterator(); assertThat(i.next(), instanceOf(IOException.class)); assertThat(i.next(), instanceOf(IllegalArgumentException.class)); assertThat(i.next(), instanceOf(IllegalStateException.class)); }
@Test public void getCauses_reversed() { List<Throwable> es = ExceptionUtil.getCauses(getException(), true); assertEquals(3, es.size()); Iterator<Throwable> i = es.iterator(); assertThat(i.next(), instanceOf(IllegalStateException.class)); assertThat(i.next(), instanceOf(IllegalArgumentException.class)); assertThat(i.next(), instanceOf(IOException.class)); }