Skip to content

Commit ff29b0c

Browse files
author
Stephen Braimah
committed
BAEL-583: Added additional test case for parallel streams
1 parent 4119fc9 commit ff29b0c

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

core-java/src/test/java/com/baeldung/java8/Java8FindAnyFindFirstTest.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package com.baeldung.java8;
22

33

4-
import org.assertj.core.condition.AnyOf;
5-
import org.hamcrest.Matchers;
6-
import org.junit.Assert;
74
import org.junit.Test;
85

96
import 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

Comments
 (0)