File tree Expand file tree Collapse file tree 2 files changed +11
-1
lines changed
src/test/java/com/codenerve/streams/lists Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Original file line number Diff line number Diff line change 11# java cookbook
22
3- Sample code for article [ @codenerve .com] ( https://www.codenerve.com/ ) #TODO update link
3+ Sample code for article [ @codenerve .com] ( https://www.codenerve.com/java-streams-cookbook/ )
44
55## Contents
66- Basic operations on lists
Original file line number Diff line number Diff line change 44import org .junit .jupiter .api .Test ;
55
66import java .util .List ;
7+ import java .util .Optional ;
78import java .util .function .Predicate ;
89import java .util .stream .Collectors ;
910
@@ -69,6 +70,15 @@ void filter_pattern_books() {
6970 assertThat (fiveStarBooks .size (), is (equalTo (3 )));
7071 }
7172
73+ @ Test
74+ void find_a_robert_martin_book () {
75+ Optional <Book > aRobertMartinBook = books .stream ()
76+ .filter (book -> book .getAuthor ().contains ("Martin Fowler" ))
77+ .findAny ();
78+
79+ assertThat (aRobertMartinBook .get ().getAuthor (), is (equalTo ("Martin Fowler" )));
80+ }
81+
7282 @ Test
7383 void find_a_martin_fowler_book () {
7484 Book aMartinFowlerBook = books .stream ()
You can’t perform that action at this time.
0 commit comments