ExceptionUtil { public static boolean causedBy(Throwable throwable, Class<? extends Throwable> causeType) { assertNotNull(causeType, "causeType"); Set<Throwable> causes = CollectionUtil.createHashSet(); for (; throwable != null && !causeType.isInstance(throwable) && !causes.contains(throwable); throwable = throwable.getCause()) { causes.add(throwable); } return throwable != null && causeType.isInstance(throwable); }  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(expected = IllegalArgumentException.class) public void causedBy_causeTypeIsNull() { ExceptionUtil.causedBy(new Exception(), null); }
@Test public void causedBy() { assertFalse(ExceptionUtil.causedBy(null, Exception.class)); assertTrue(ExceptionUtil.causedBy(new IOException(), IOException.class)); assertTrue(ExceptionUtil.causedBy(new IOException(), Exception.class)); assertTrue(ExceptionUtil.causedBy(getException(), IOException.class)); assertTrue(ExceptionUtil.causedBy(getException(), IllegalArgumentException.class)); assertTrue(ExceptionUtil.causedBy(getException(), IllegalStateException.class)); assertTrue(ExceptionUtil.causedBy(getException(), RuntimeException.class)); assertTrue(ExceptionUtil.causedBy(getException(), Exception.class)); assertFalse(ExceptionUtil.causedBy(getException(), IllegalAccessException.class)); }