11package com .baeldung .java8 ;
22
33
4- import org .assertj .core .condition .AnyOf ;
5- import org .hamcrest .Matchers ;
6- import org .junit .Assert ;
74import org .junit .Test ;
85
96import java .util .Arrays ;
@@ -22,18 +19,31 @@ public void createStream_whenFindAnyResultIsPresent_thenCorrect() {
2219
2320 Optional <String > result = list .stream ().findAny ();
2421
25- assert result .isPresent ();
22+ assertTrue ( result .isPresent () );
2623 assertThat (result .get (), anyOf (is ("A" ), is ("B" ), is ("C" ), is ("D" )));
2724 }
2825
26+ @ Test
27+ public void createParallelStream_whenFindAnyResultIsNotFirst_ThenCorrect () throws Exception {
28+ List <Integer > list = Arrays .asList (1 ,2 ,3 ,4 ,5 );
29+ Optional <Integer > result = list
30+ .stream ()
31+ .parallel ()
32+ .filter (num -> num <4 )
33+ .findAny ();
34+
35+ assertTrue (result .isPresent ());
36+ assertThat (result .get (),anyOf (is (1 ), is (2 ), is (3 )));
37+ }
38+
2939 @ Test
3040 public void createStream_whenFindFirstResultIsPresent_thenCorrect () {
3141
3242 List <String > list = Arrays .asList ("A" ,"B" ,"C" ,"D" );
3343
3444 Optional <String > result = list .stream ().findFirst ();
3545
36- assert result .isPresent ();
46+ assertTrue ( result .isPresent () );
3747 assertThat (result .get (),is ("A" ));
3848 }
3949}
0 commit comments