FunctionalUtils { public static <T, E extends Throwable> Consumer<T> unchecked(CheckedConsumer<T, E> consumer) { return t -> { try { consumer.accept(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 unchecked() throws Exception { Consumer<String> consu = FunctionalUtils.unchecked(this::unsafeConsumer); consu.accept("pepe"); }
@Test public void uncheckedFailure() throws Exception { Consumer<String> consu = FunctionalUtils.unchecked(this::unsafeThrowingConsumer); try { consu.accept("pepe"); fail(); } catch (Exception e) { assertThat(e).hasCauseExactlyInstanceOf(IOException.class); } }