Add IORunnable#asRunnable()
MODIFY
src/main/java/org/apache/commons/io/function/IORunnable.java
src/main/java/org/apache/commons/io/function/IORunnable.java
package org.apache.commons.io.function;
import java.io.IOException;
+import java.io.UncheckedIOException;
/**
* Like {@link Runnable} but throws {@link IOException}.
@FunctionalInterface
public interface IORunnable {
+ /**
+ * Creates a {@link Runnable} for this instance that throws {@link UncheckedIOException} instead of {@link IOException}.
+ *
+ * @return an unchecked Predicate.
+ */
+ default Runnable asRunnable() {
+ return () -> Uncheck.run(this);
+ }
+
/**
* Like {@link Runnable#run()} but throws {@link IOException}.
*

MODIFY
src/test/java/org/apache/commons/io/function/IORunnableTest.java
src/test/java/org/apache/commons/io/function/IORunnableTest.java
package org.apache.commons.io.function;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.nio.file.Files;
+import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicReference;
+import org.apache.commons.io.file.PathUtils;
import org.junit.jupiter.api.Test;
/**
@@ -42,4 +48,11 @@ public void testAccept() throws IOException {
assertEquals("A1", ref.get());
}
+ @Test
+ public void testAsRunnable() throws Exception {
+ assertThrows(UncheckedIOException.class, () -> Executors.callable(TestConstants.THROWING_IO_RUNNABLE.asRunnable()).call());
+ final IORunnable runnable = () -> Files.size(PathUtils.current());
+ assertNull(Executors.callable(runnable.asRunnable()).call());
+ }
+
}

Add IORunnable#asRunnable()