### Question:
StacktraceUtil { public static Throwable findRootCause(Throwable throwable) { if (throwable == null) { return null; } Throwable rootCause = throwable; while (rootCause.getCause() != null && rootCause.getCause() != rootCause) { rootCause = rootCause.getCause(); } return rootCause; }  static Throwable findRootCause(Throwable throwable); static String createDescription(Throwable throwable);  }### Answer:
@Test public void runtime_exception_containing_a_HttpClientErrorException_find_root_HttpClientErrorException() { Throwable wantedrootCause = new HttpClientErrorException(HttpStatus.BAD_REQUEST); RuntimeException e = new RuntimeException("test", wantedrootCause); Throwable rootCause = StacktraceUtil.findRootCause(e); assertEquals(wantedrootCause,rootCause); }
@Test public void runtime_exception_containing_no_cause_returns_runtime_exception() { RuntimeException e = new RuntimeException("test"); Throwable rootCause = StacktraceUtil.findRootCause(e); assertEquals(e,rootCause); }
@Test public void null_given_returns_null() { Throwable rootCause = StacktraceUtil.findRootCause(null); assertEquals(null,rootCause); }