### Question:
Exceptions { public static RuntimeException tryGetCassandraExceptionCause(RuntimeException exception) { Throwable cause = exception.getCause(); if (cause instanceof CassandraException) { cause.addSuppressed(exception); return (CassandraException) cause; } else if (cause instanceof RuntimeException) { RuntimeException causeOfCause = tryGetCassandraExceptionCause((RuntimeException) cause); if (causeOfCause == cause) { return exception; } causeOfCause.addSuppressed(exception); return causeOfCause; } else { return exception; } } private  Exceptions(); static RuntimeException tryGetCassandraExceptionCause(RuntimeException exception); static T appendCause(T exception, Throwable cause);  }### Answer:
@Test public void testSimpleRuntimeExceptionIsSame() { RuntimeException expectedException = new RuntimeException(); RuntimeException actualCause = Exceptions.tryGetCassandraExceptionCause(expectedException); assertThat(actualCause).isSameAs(expectedException); assertThat(actualCause.getSuppressed()).isEmpty(); }
@Test public void testSimpleCassandraExceptionIsSame() { RuntimeException expectedException = new ReadTimeoutException(ConsistencyLevel.QUORUM, 1, 1, false); RuntimeException actualCause = Exceptions.tryGetCassandraExceptionCause(expectedException); assertThat(actualCause).isSameAs(expectedException); assertThat(actualCause.getSuppressed()).isEmpty(); }
@Test public void testWrappedRuntimeExceptionIsSame() { RuntimeException exception = new RuntimeException(); RuntimeException expectedException = new RuntimeException(exception); RuntimeException actualCause = Exceptions.tryGetCassandraExceptionCause(expectedException); assertThat(actualCause).isSameAs(expectedException); assertThat(actualCause.getSuppressed()).isEmpty(); assertThat(exception.getSuppressed()).isEmpty(); }
@Test public void testWrappedCassandraExceptionIsUnwrapped() { RuntimeException expectedException = new ReadTimeoutException(ConsistencyLevel.QUORUM, 1, 1, false); RuntimeException exception = new RuntimeException(expectedException); RuntimeException actualCause = Exceptions.tryGetCassandraExceptionCause(exception); assertThat(actualCause).isSameAs(expectedException); assertThat(actualCause.getSuppressed()).contains(exception); assertThat(exception.getSuppressed()).isEmpty(); }
@Test public void testMultiWrappedCassandraExceptionIsUnwrapped() { RuntimeException expectedException = new ReadTimeoutException(ConsistencyLevel.QUORUM, 1, 1, false); RuntimeException exception = new RuntimeException(expectedException); exception = new RuntimeException(exception); RuntimeException actualCause = Exceptions.tryGetCassandraExceptionCause(exception); assertThat(actualCause).isSameAs(expectedException); assertThat(actualCause.getSuppressed()).contains(exception); assertThat(exception.getSuppressed()).isEmpty(); }