@Test public void testExpectedExceptionIsOneLevelDeep() { ConstraintViolationException t = new ConstraintViolationException(null, null, null); RuntimeException rt = new RuntimeException("RT", t); assertEquals("Should find the desired exception if cause s set", t, ThrowableUtil.getSpecificCauseRecursively(rt, ConstraintViolationException.class)); }
public static <T> T getSpecificCauseRecursively(Throwable t, Class<T> causeType) { if (causeType.isInstance(t)) { return causeType.cast(t); } else if (t == null) { return null; } return getSpecificCauseRecursively(t.getCause(), causeType); }
ThrowableUtil { public static <T> T getSpecificCauseRecursively(Throwable t, Class<T> causeType) { if (causeType.isInstance(t)) { return causeType.cast(t); } else if (t == null) { return null; } return getSpecificCauseRecursively(t.getCause(), causeType); } }
ThrowableUtil { public static <T> T getSpecificCauseRecursively(Throwable t, Class<T> causeType) { if (causeType.isInstance(t)) { return causeType.cast(t); } else if (t == null) { return null; } return getSpecificCauseRecursively(t.getCause(), causeType); } private  ThrowableUtil(); }
ThrowableUtil { public static <T> T getSpecificCauseRecursively(Throwable t, Class<T> causeType) { if (causeType.isInstance(t)) { return causeType.cast(t); } else if (t == null) { return null; } return getSpecificCauseRecursively(t.getCause(), causeType); } private  ThrowableUtil(); static T getSpecificCauseRecursively(Throwable t, Class<T> causeType); }
ThrowableUtil { public static <T> T getSpecificCauseRecursively(Throwable t, Class<T> causeType) { if (causeType.isInstance(t)) { return causeType.cast(t); } else if (t == null) { return null; } return getSpecificCauseRecursively(t.getCause(), causeType); } private  ThrowableUtil(); static T getSpecificCauseRecursively(Throwable t, Class<T> causeType);  }