### Question:
ExceptionUtils { public static Throwable getRootCause(Throwable ex, Class<? extends Throwable> rootCauseClassIfPresent) { ParamChecker.notNull(ex, "ex"); ParamChecker.notNull(rootCauseClassIfPresent, "rootCauseClassIfPresent"); Throwable rootCause = null; while (rootCause == null) { if (rootCauseClassIfPresent.isInstance(ex)) { rootCause = ex; } else if (ex.getCause() != null) { ex = ex.getCause(); } else { rootCause = ex; } } return rootCause; }  static Throwable getRootCause(Throwable ex,
      Class<? extends Throwable> rootCauseClassIfPresent);  }### Answer:
@Test(expected = IllegalArgumentException.class) public void testNullEx() { Assert.assertNull(ExceptionUtils.getRootCause(null, null)); }
@Test(expected = IllegalArgumentException.class) public void testNullClass() { Assert.assertNull(ExceptionUtils.getRootCause(new Exception(), null)); }
@Test public void testNoRoot() { Exception ex = new Exception(); Assert.assertEquals(ex, ExceptionUtils.getRootCause(ex, RuntimeException .class)); }
@Test public void testExIsRoot() { Exception ex = new Exception(); Assert.assertEquals(ex, ExceptionUtils.getRootCause(ex, Exception.class)); }
@Test public void testCauseIsRoot() { RuntimeException rex = new RuntimeException(); Exception ex = new Exception(rex); Assert.assertEquals(rex, ExceptionUtils.getRootCause(ex, RuntimeException.class)); }