// Path: core/src/main/java/com/github/phantomthief/util/MoreCollectors.java
// public static <T, K> Collector<T, ?, Map<K, List<T>>> groupingByAllowNullKey(
//         Function<? super T, ? extends K> classifier) {
//     return groupingByAllowNullKey(classifier, toList());
// }


import static com.github.phantomthief.util.MoreCollectors.groupingByAllowNullKey;
import static java.util.function.Function.identity;
import static java.util.stream.Collectors.groupingBy;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toMap;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
package com.github.phantomthief.util;




/**
 * MoreCollectorsTest
 * <p>
 * Write the code. Change the world.
 *
 * @author trang
 * @date 2019-07-31
 */
class MoreCollectorsTest {

    /**
     * toMap() 本身支持 null key，但不支持 null value
     */
    @Test
    void toMapTest() {
        Map<Integer, TestEnum1> map =
                Stream.of(TestEnum1.values()).collect(toMap(TestEnum1::getValue, identity()));
        assertEquals(4, map.size());
        assertNotNull(map.get(null));
    }

    @Test
    void groupingByTest() {
        assertThrows(NullPointerException.class,
                () -> Stream.of(TestEnum2.values()).collect(groupingBy(TestEnum2::getValue)));
    }

    @Test
    void groupingByAllowNullKeyTest() {
        Map<Integer, List<TestEnum2>> map =
// Path: core/src/main/java/com/github/phantomthief/util/MoreCollectors.java
// public static <T, K> Collector<T, ?, Map<K, List<T>>> groupingByAllowNullKey(
//         Function<? super T, ? extends K> classifier) {
//     return groupingByAllowNullKey(classifier, toList());
// }


// Path: core/src/test/java/com/github/phantomthief/util/MoreCollectorsTest.java
import static com.github.phantomthief.util.MoreCollectors.groupingByAllowNullKey;
import static java.util.function.Function.identity;
import static java.util.stream.Collectors.groupingBy;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toMap;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;

package com.github.phantomthief.util;




/**
 * MoreCollectorsTest
 * <p>
 * Write the code. Change the world.
 *
 * @author trang
 * @date 2019-07-31
 */
class MoreCollectorsTest {

    /**
     * toMap() 本身支持 null key，但不支持 null value
     */
    @Test
    void toMapTest() {
        Map<Integer, TestEnum1> map =
                Stream.of(TestEnum1.values()).collect(toMap(TestEnum1::getValue, identity()));
        assertEquals(4, map.size());
        assertNotNull(map.get(null));
    }

    @Test
    void groupingByTest() {
        assertThrows(NullPointerException.class,
                () -> Stream.of(TestEnum2.values()).collect(groupingBy(TestEnum2::getValue)));
    }

    @Test
    void groupingByAllowNullKeyTest() {
        Map<Integer, List<TestEnum2>> map =
                Stream.of(TestEnum2.values()).collect(groupingByAllowNullKey(TestEnum2::getValue));