FunctionalUtils { public static <T, R, E extends Throwable> Function<T, R> uncheckedFunction(CheckedFunction<T, R, E> function) { return t -> { try { return function.apply(t); } catch (Throwable e) { RuntimeException r; if (e instanceof RuntimeException) { r = (RuntimeException) e; } else { r = new RuntimeException(e); } throw r; } }; }  static Consumer<T> unchecked(CheckedConsumer<T, E> consumer); static Function<T, R> uncheckedFunction(CheckedFunction<T, R, E> function);  }
@Test public void uncheckedFunction() throws Exception { Function<String, String> consu = FunctionalUtils.uncheckedFunction(this::unsafeFunction); String f = consu.apply("pepe"); assertThat(f).isEqualTo("Pronto"); }
@Test public void uncheckedFunctionFailure() throws Exception { Function<String, String> consu = FunctionalUtils.uncheckedFunction(this::unsafeThrowingFunction); try { consu.apply("pepe"); fail(); } catch (Exception e) { assertThat(e).hasCauseExactlyInstanceOf(IOException.class); } }