Skip to content

Commit f29191d

Browse files
crorKevinGilmore
authored andcommitted
BAEL-2548 updated the test with toMap and binary operator (eugenp#6303)
1 parent ca7c2b8 commit f29191d

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

‎core-java-8/src/test/java/com/baeldung/collectors/Java8CollectorsUnitTest.java‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,16 @@ public void whenCollectingToMap_shouldCollectToMap() throws Exception {
8585
}
8686

8787
@Test
88-
public void whenCollectingToMap_shouldCollectToMapMerging() throws Exception {
89-
final Map<String, Integer> result = givenList.stream().collect(toMap(Function.identity(), String::length, (i1, i2) -> i1));
90-
91-
assertThat(result).containsEntry("a", 1).containsEntry("bb", 2).containsEntry("ccc", 3).containsEntry("dd", 2);
88+
public void whenCollectingToMapwWithDuplicates_shouldCollectToMapMergingTheIdenticalItems() throws Exception {
89+
final Map<String, Integer> result = listWithDuplicates.stream().collect(
90+
toMap(
91+
Function.identity(),
92+
String::length,
93+
(item, identicalItem) -> item
94+
)
95+
);
96+
97+
assertThat(result).containsEntry("a", 1).containsEntry("bb", 2).containsEntry("c", 1).containsEntry("d", 1);
9298
}
9399

94100
@Test

0 commit comments

Comments
 (0)