Skip to content

Commit e725c02

Browse files
andrea-ligiospivovarit
authored andcommitted
BAEL-1698 (latest) (eugenp#4138)
* Also needed * BAEL-1698 * BAEL-1698
1 parent 94e0755 commit e725c02

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

‎core-java-collections/src/test/java/com/baeldung/java/map/MapMultipleValuesTest.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ public void givenCollectionAsValue_whenPuttingTwice_thenReturningCollection() {
4545
assertThat(map.get("key1").get(1)).isEqualTo("value2");
4646
}
4747

48+
@Test
49+
public void givenCollectionAsValueAndJava8_whenPuttingTwice_thenReturningCollection() {
50+
Map<String, List<String>> map = new HashMap<>();
51+
map.computeIfAbsent("key1", k -> new ArrayList<>()).add("value1");
52+
map.computeIfAbsent("key1", k -> new ArrayList<>()).add("value2");
53+
assertThat(map.get("key1").get(0)).isEqualTo("value1");
54+
assertThat(map.get("key1").get(1)).isEqualTo("value2");
55+
}
56+
4857
@Test
4958
public void givenMultiValueMap_whenPuttingTwice_thenReturningValues() {
5059
MultiMap<String, String> map = new MultiValueMap<>();

0 commit comments

Comments
 (0)