// Path: core/src/main/java/com/github/phantomthief/util/MoreFunctions.java
// public static <R> R catching(Callable<R> callable) {
//     return catching(callable, e -> logger.error(FAIL_SAFE_MARK, e));
// }
// 
// Path: core/src/main/java/com/github/phantomthief/util/MoreFunctions.java
// public static <K, V> Consumer<Entry<K, V>> consumerKv(BiConsumer<K, V> func) {
//     return entry -> func.accept(entry.getKey(), entry.getValue());
// }
// 
// Path: core/src/main/java/com/github/phantomthief/util/MoreFunctions.java
// public static <K, V> Predicate<Entry<K, V>> filterKv(BiPredicate<K, V> func) {
//     return entry -> func.test(entry.getKey(), entry.getValue());
// }
// 
// Path: core/src/main/java/com/github/phantomthief/util/MoreFunctions.java
// public static <K, V, T> Function<Entry<K, V>, T> mapKv(BiFunction<K, V, T> func) {
//     return entry -> func.apply(entry.getKey(), entry.getValue());
// }
// 
// Path: core/src/main/java/com/github/phantomthief/util/MoreFunctions.java
// public static <X extends Throwable> void runParallel(ForkJoinPool pool,
//         ThrowableRunnable<X> func) throws X {
//     supplyParallel(pool, () -> {
//         func.run();
//         return null;
//     });
// }
// 
// Path: core/src/main/java/com/github/phantomthief/util/MoreFunctions.java
// public static <X extends Throwable> void runWithThreadName(
//         @Nonnull Function<String, String> name, @Nonnull ThrowableRunnable<X> func) throws X {
//     supplyWithThreadName(name, () -> {
//         func.run();
//         return null;
//     });
// }
// 
// Path: core/src/main/java/com/github/phantomthief/util/MoreFunctions.java
// public static <R> R throwing(Callable<R> callable) {
//     return catching(callable, throwable -> {
//         throwIfUnchecked(throwable);
//         throw new RuntimeException(throwable);
//     });
// }


import static com.github.phantomthief.util.MoreFunctions.catching;
import static com.github.phantomthief.util.MoreFunctions.consumerKv;
import static com.github.phantomthief.util.MoreFunctions.filterKv;
import static com.github.phantomthief.util.MoreFunctions.mapKv;
import static com.github.phantomthief.util.MoreFunctions.runParallel;
import static com.github.phantomthief.util.MoreFunctions.runWithThreadName;
import static com.github.phantomthief.util.MoreFunctions.throwing;
import static java.util.stream.Collectors.toList;
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 static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ForkJoinPool;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableMap;
package com.github.phantomthief.test;





/**
 * @author w.vela
 */
class MoreFunctionsTest {

    @Test
    void testTrying() {
        assertNull(catching(i -> function(i, Exception::new), 1));
        assertNull(catching(i -> function(i, IllegalArgumentException::new), 1));
        assertEquals("1", catching(i -> function(i, null), 1));
    }

    @Test
    void testThrowing() {
        assertThrows(IllegalArgumentException.class, () -> throwing(() -> {
            throw new IllegalArgumentException();
        }));
        assertTrue(assertThrows(RuntimeException.class, () -> throwing(() -> {
            throw new IOException();
        })).getCause() instanceof IOException);
    }

    private <X extends Throwable> String function(int i, Supplier<X> exception) throws X {
        if (exception != null) {
            X x = exception.get();
            throw x;
        } else {
            return i + "";
        }
    }

    @Test
// Path: core/src/main/java/com/github/phantomthief/util/MoreFunctions.java
// public static <R> R catching(Callable<R> callable) {
//     return catching(callable, e -> logger.error(FAIL_SAFE_MARK, e));
// }
// 
// Path: core/src/main/java/com/github/phantomthief/util/MoreFunctions.java
// public static <K, V> Consumer<Entry<K, V>> consumerKv(BiConsumer<K, V> func) {
//     return entry -> func.accept(entry.getKey(), entry.getValue());
// }
// 
// Path: core/src/main/java/com/github/phantomthief/util/MoreFunctions.java
// public static <K, V> Predicate<Entry<K, V>> filterKv(BiPredicate<K, V> func) {
//     return entry -> func.test(entry.getKey(), entry.getValue());
// }
// 
// Path: core/src/main/java/com/github/phantomthief/util/MoreFunctions.java
// public static <K, V, T> Function<Entry<K, V>, T> mapKv(BiFunction<K, V, T> func) {
//     return entry -> func.apply(entry.getKey(), entry.getValue());
// }
// 
// Path: core/src/main/java/com/github/phantomthief/util/MoreFunctions.java
// public static <X extends Throwable> void runParallel(ForkJoinPool pool,
//         ThrowableRunnable<X> func) throws X {
//     supplyParallel(pool, () -> {
//         func.run();
//         return null;
//     });
// }
// 
// Path: core/src/main/java/com/github/phantomthief/util/MoreFunctions.java
// public static <X extends Throwable> void runWithThreadName(
//         @Nonnull Function<String, String> name, @Nonnull ThrowableRunnable<X> func) throws X {
//     supplyWithThreadName(name, () -> {
//         func.run();
//         return null;
//     });
// }
// 
// Path: core/src/main/java/com/github/phantomthief/util/MoreFunctions.java
// public static <R> R throwing(Callable<R> callable) {
//     return catching(callable, throwable -> {
//         throwIfUnchecked(throwable);
//         throw new RuntimeException(throwable);
//     });
// }


// Path: core/src/test/java/com/github/phantomthief/test/MoreFunctionsTest.java
import static com.github.phantomthief.util.MoreFunctions.catching;
import static com.github.phantomthief.util.MoreFunctions.consumerKv;
import static com.github.phantomthief.util.MoreFunctions.filterKv;
import static com.github.phantomthief.util.MoreFunctions.mapKv;
import static com.github.phantomthief.util.MoreFunctions.runParallel;
import static com.github.phantomthief.util.MoreFunctions.runWithThreadName;
import static com.github.phantomthief.util.MoreFunctions.throwing;
import static java.util.stream.Collectors.toList;
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 static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ForkJoinPool;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableMap;

package com.github.phantomthief.test;





/**
 * @author w.vela
 */
class MoreFunctionsTest {

    @Test
    void testTrying() {
        assertNull(catching(i -> function(i, Exception::new), 1));
        assertNull(catching(i -> function(i, IllegalArgumentException::new), 1));
        assertEquals("1", catching(i -> function(i, null), 1));
    }

    @Test
    void testThrowing() {
        assertThrows(IllegalArgumentException.class, () -> throwing(() -> {
            throw new IllegalArgumentException();
        }));
        assertTrue(assertThrows(RuntimeException.class, () -> throwing(() -> {
            throw new IOException();
        })).getCause() instanceof IOException);
    }

    private <X extends Throwable> String function(int i, Supplier<X> exception) throws X {
        if (exception != null) {
            X x = exception.get();
            throw x;
        } else {
            return i + "";
        }
    }

    @Test
    void testParallel() {