public void testToImmutableBiMap_exceptionOnDuplicateKey() { Collector<Entry<String, Integer>, ?, ImmutableBiMap<String, Integer>> collector = ImmutableBiMap.toImmutableBiMap(Entry::getKey, Entry::getValue); try { Stream.of(mapEntry("one", 1), mapEntry("one", 11)).collect(collector); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { } }
public void testToImmutableBiMap() { Collector<Entry<String, Integer>, ?, ImmutableBiMap<String, Integer>> collector = ImmutableBiMap.toImmutableBiMap(Entry::getKey, Entry::getValue); Equivalence<ImmutableBiMap<String, Integer>> equivalence = Equivalence.equals() .<Entry<String, Integer>>pairwise() .onResultOf(ImmutableBiMap::entrySet); CollectorTester.of(collector, equivalence) .expectCollects( ImmutableBiMap.of("one", 1, "two", 2, "three", 3), mapEntry("one", 1), mapEntry("two", 2), mapEntry("three", 3)); }