BAEL-2548 updated the test with toMap and binary operator (#6303)

This commit is contained in:
cror 2019-02-15 15:12:32 +01:00 committed by KevinGilmore
parent ca7c2b8c60
commit f29191df67
1 changed files with 9 additions and 3 deletions

View File

@ -85,10 +85,16 @@ public class Java8CollectorsUnitTest {
}
@Test
public void whenCollectingToMap_shouldCollectToMapMerging() throws Exception {
final Map<String, Integer> result = givenList.stream().collect(toMap(Function.identity(), String::length, (i1, i2) -> i1));
public void whenCollectingToMapwWithDuplicates_shouldCollectToMapMergingTheIdenticalItems() throws Exception {
final Map<String, Integer> 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