public static RuntimeException wrapIf(boolean condition, Throwable t) {
    if (condition) {
      return wrap(t);
    }

    if (t instanceof RuntimeException) {
      return (RuntimeException) t;
    }

    return new RuntimeException(t);
  }
@Test
  public void testWrapIfOnlyWrapsWhenTrue() {
    IOException cause = new IOException();
    RuntimeException wrapped = UserCodeException.wrapIf(true, cause);

    assertThat(wrapped, is(instanceOf(UserCodeException.class)));
  }