From f29191df67115dc488d8bb6f5e40ac6d30e29f03 Mon Sep 17 00:00:00 2001 From: cror <37755757+cror@users.noreply.github.com> Date: Fri, 15 Feb 2019 15:12:32 +0100 Subject: [PATCH] BAEL-2548 updated the test with toMap and binary operator (#6303) --- .../baeldung/collectors/Java8CollectorsUnitTest.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/core-java-8/src/test/java/com/baeldung/collectors/Java8CollectorsUnitTest.java b/core-java-8/src/test/java/com/baeldung/collectors/Java8CollectorsUnitTest.java index 9ace27e38f..e742635758 100644 --- a/core-java-8/src/test/java/com/baeldung/collectors/Java8CollectorsUnitTest.java +++ b/core-java-8/src/test/java/com/baeldung/collectors/Java8CollectorsUnitTest.java @@ -85,10 +85,16 @@ public class Java8CollectorsUnitTest { } @Test - public void whenCollectingToMap_shouldCollectToMapMerging() throws Exception { - final Map result = givenList.stream().collect(toMap(Function.identity(), String::length, (i1, i2) -> i1)); + public void whenCollectingToMapwWithDuplicates_shouldCollectToMapMergingTheIdenticalItems() throws Exception { + final Map result = listWithDuplicates.stream().collect( + toMap( + Function.identity(), + String::length, + (item, identicalItem) -> item + ) + ); - assertThat(result).containsEntry("a", 1).containsEntry("bb", 2).containsEntry("ccc", 3).containsEntry("dd", 2); + assertThat(result).containsEntry("a", 1).containsEntry("bb", 2).containsEntry("c", 1).containsEntry("d", 1); } @Test