BAEL-2514 - Changed key pattern example to use same map as others

This commit is contained in:
Juan Vaccari 2019-02-10 14:50:45 +00:00
parent d56efcfa97
commit a079636e79
1 changed files with 8 additions and 9 deletions

View File

@ -92,15 +92,14 @@ public class StreamMapUnitTest {
} }
@Test @Test
public void ValuesFromMapBasedOnPattern() { public void whenKeysFollowingPatternReturnsAllValuesForThoseKeys() {
Map<String, Integer> authorToYearOfBirth = new HashMap<>(); List<String> titlesForKeyPattern = books.entrySet().stream()
authorToYearOfBirth.put("Asimov, Isaac", 1920); .filter(e -> e.getKey().startsWith("978-0"))
authorToYearOfBirth.put("Adams, Douglas", 1952); .map(Map.Entry::getValue)
authorToYearOfBirth.put("Bradbury, Ray", 1920); .collect(Collectors.toList());
authorToYearOfBirth.put("Clarke, Arthur", 1917); assertEquals(2, titlesForKeyPattern.size());
assertTrue(titlesForKeyPattern.contains("Design patterns : elements of reusable object-oriented software"));
List<Integer> yearOfBirthAuthorsStartingWithA = authorToYearOfBirth.entrySet().stream().filter(e -> e.getKey().startsWith("A")).map(Map.Entry::getValue).collect(Collectors.toList()); assertTrue(titlesForKeyPattern.contains("Effective Java"));
assertEquals(2, yearOfBirthAuthorsStartingWithA.size());
} }