### Question:
ExceptionCause { public RuntimeException unwrapped() { Throwable cause = exception.getCause(); if (cause instanceof RuntimeException) { return (RuntimeException) cause; } if (cause == null) { return new IllegalStateException(exception.getMessage()); } return new IllegalStateException(cause); } protected  ExceptionCause(Throwable exception); static final ExceptionCause of(Throwable exception); RuntimeException unwrapped(); @Override String toString();  }### Answer:
@Test @DisplayName("an existing exception cause should be unwraped") void testShouldUnwrapExistingCause() { exceptionCauseToTest = new ExceptionCause(exceptionWithCause); RuntimeException unwrapped = exceptionCauseToTest.unwrapped(); assertEquals(exceptionWithoutCause, unwrapped); }
@Test @DisplayName("an existing checked exception is unwrapped as cause inside an IllegalStateException") void testShouldUnwrapIllegalStateExceptionWithCheckedExceptionCause() { Throwable checkedExceptionCause = new Exception("TestCheckedException"); Throwable exceptionWithCheckedExceptionCause = new IllegalStateException("CheckedExceptionCause", checkedExceptionCause); exceptionCauseToTest = new ExceptionCause(exceptionWithCheckedExceptionCause); RuntimeException unwrapped = exceptionCauseToTest.unwrapped(); assertEquals(IllegalStateException.class, unwrapped.getClass()); assertEquals(checkedExceptionCause, unwrapped.getCause()); }
@Test @DisplayName("without a cause a new IllegalStateException should be thrown using the original message") void testShouldUnwrapIllegalStateExceptionWithOriginalMessageWithoutCause() { exceptionCauseToTest = new ExceptionCause(exceptionWithoutCause); RuntimeException unwrapped = exceptionCauseToTest.unwrapped(); assertEquals(exceptionWithoutCause.getMessage(), unwrapped.getMessage()); assertEquals(IllegalStateException.class, unwrapped.getClass()); }