Skip to content

Commit

Permalink
Merge pull request eugenp#7080 from rodrigolgraciano/BAEL-2936
Browse files Browse the repository at this point in the history
BAEL-2936
  • Loading branch information
maibin authored Jun 4, 2019
2 parents acc9c24 + 3cea8b6 commit 8d5f6af
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ public Map<Integer, Book> listToMapWithDupKeyError(List<Book> books) {
}

public Map<Integer, Book> listToMapWithDupKey(List<Book> books) {
return books.stream().collect(Collectors.toMap(Book::getReleaseYear, Function.identity(),
(o1, o2) -> o1));
return books.stream().collect(Collectors.toMap(Book::getReleaseYear, Function.identity(), (existing, replacement) -> existing));
}

public Map<Integer, Book> listToConcurrentMap(List<Book> books) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import static org.junit.Assert.*;
Expand Down Expand Up @@ -34,8 +35,10 @@ public void whenMapHasDuplicateKey_without_merge_function_then_runtime_exception
}

@Test
public void whenMapHasDuplicateKey_with_merge_function() {
assertTrue(convertToMap.listToMapWithDupKey(bookList).size() == 2);
public void whenMapHasDuplicateKeyThenMergeFunctionHandlesCollision() {
Map<Integer, Book> booksByYear = convertToMap.listToMapWithDupKey(bookList);
assertEquals(2, booksByYear.size());
assertEquals("0395489318", booksByYear.get(1954).getIsbn());
}

@Test
Expand Down

0 comments on commit 8d5f6af

Please sign in to comment.