### Question:
Sneaky { @CheckReturnValue @Nonnull public static DummyException throwAnyway(Throwable t) { if (t instanceof Error) { throw (Error) t; } if (t instanceof RuntimeException) { throw (RuntimeException) t; } if (t instanceof IOException) { throw new UncheckedIOException((IOException) t); } if (t instanceof InterruptedException) { Thread.currentThread().interrupt(); } if (t instanceof InvocationTargetException) { throw throwAnyway(t.getCause()); } throwEvadingChecks(t); return null; } private  Sneaky(); @CheckReturnValue @Nonnull static DummyException throwAnyway(Throwable t);  }### Answer:
@Test public void errorThrownDirectly() { Error error = new OutOfMemoryError(); assertThatThrownBy(() -> Sneaky.throwAnyway(error)) .isSameAs(error); }
@Test public void runtimeExceptionThrownDirectly() { RuntimeException rex = new IllegalArgumentException(); assertThatThrownBy(() -> Sneaky.throwAnyway(rex)) .isSameAs(rex); }
@Test public void ioExceptionProperlyWrapped() { IOException ioex = new IOException(); assertThatThrownBy(() -> Sneaky.throwAnyway(ioex)) .isInstanceOf(UncheckedIOException.class) .hasCause(ioex); }
@Test public void genericCheckedExceptionThrownDirectly() { Exception ex = new WhateverException(); assertThatThrownBy(() -> Sneaky.throwAnyway(ex)) .isSameAs(ex); }
@Test public void invocationTargetExceptionIsUnwrapped() { Throwable cause = new WhateverException(); InvocationTargetException ite = new InvocationTargetException(cause); assertThatThrownBy(() -> Sneaky.throwAnyway(ite)) .isSameAs(cause); }