public static <T, K, U, M extends Map<K,U>>
    Collector<T, ?, M> toCustomMap(Function<? super T, ? extends K> keyMapper,
                                   Function<? super T, ? extends U> valueMapper,
                                   Supplier<M> mapSupplier) {
        return Collectors.toMap(keyMapper, valueMapper, throwingMerger(), mapSupplier);
    }
@Test
    public void custom_map_collector_throws_exception_upon_duplicate_keys() {
        List<String> duplicates = List.of("same", "same");

        try {
            duplicates.stream().collect(toCustomMap(Function.identity(), Function.identity(), HashMap::new));
            fail();
        } catch (DuplicateKeyException e) {

        }
    }