### Question:
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);  }### Answer:
@Test public void testNullInput() { assertNull("For null input it shall return with null", ThrowableUtil.getSpecificCauseRecursively(null, ConstraintViolationException.class)); }
@Test public void testNullCause() { RuntimeException t = new RuntimeException(); assertNull("If no cause found it should return with null", ThrowableUtil.getSpecificCauseRecursively(t, ConstraintViolationException.class)); }
@Test public void testExceptionIsTheRootCause() { ConstraintViolationException t = new ConstraintViolationException(null, null, null); assertEquals("It should return with the same object if the root cause is the exception itself", t, ThrowableUtil.getSpecificCauseRecursively(t, ConstraintViolationException.class)); }
@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)); }