### Question:
Collectors { public static <T extends Map.Entry<K, U>, K, U> Collector<T, ?, Map<K, U>> toMap() { return toMap( Map.Entry::getKey, Map.Entry::getValue, HashMap::new ); } private  Collectors(); static Collector<T, ?, T> single(); static Collector<T, ?, Optional<T>> singleOrEmpty(); static Collector<T, ?, Map<K, U>> toMap(); static Collector<T, ?, M> toMap( Supplier<M> mapSupplier ); static Collector<T, ?, M> toMap( Function<? super T, ? extends K> keyMapper,
                              Function<? super T, ? extends U> valueMapper,
                              Supplier<M> mapSupplier ); static Collector<T, ?, Map<K, U>> toMapWithNullValues(); static Collector<T, ?, M> toMapWithNullValues( Supplier<M> mapSupplier ); static Collector<T, ?, M> toMapWithNullValues( Function<? super T, ? extends K> keyMapper,
                                            Function<? super T, ? extends U> valueMapper,
                                            Supplier<M> mapSupplier );  }### Answer:
@Test public void toMap() { Map<String, String> input = new LinkedHashMap<>(); input.put( "foo", "bar" ); input.put( "bazar", "cathedral" ); Map<String, String> output = input.entrySet().stream().collect( Collectors.toMap() ); assertThat( output.get( "foo" ), equalTo( "bar" ) ); assertThat( output.get( "bazar" ), equalTo( "cathedral" ) ); }
@Test public void toMapRejectNullValues() { Map<String, String> input = new LinkedHashMap<>(); input.put( "foo", "bar" ); input.put( "bazar", null ); try { input.entrySet().stream().collect( Collectors.toMap() ); fail( "Should have failed, that's the default Map::merge behaviour" ); } catch( NullPointerException expected ) {} }