BAEL-583: Added additional test case for parallel streams

This commit is contained in:
Stephen Braimah 2017-01-19 09:43:34 +00:00
parent 4119fc9c23
commit ff29b0ca05
1 changed files with 15 additions and 5 deletions

View File

@ -1,9 +1,6 @@
package com.baeldung.java8;
import org.assertj.core.condition.AnyOf;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
import java.util.Arrays;
@ -22,10 +19,23 @@ public class Java8FindAnyFindFirstTest {
Optional<String> result = list.stream().findAny();
assert result.isPresent();
assertTrue(result.isPresent());
assertThat(result.get(), anyOf(is("A"), is("B"), is("C"), is("D")));
}
@Test
public void createParallelStream_whenFindAnyResultIsNotFirst_ThenCorrect() throws Exception {
List<Integer> list = Arrays.asList(1,2,3,4,5);
Optional<Integer> result = list
.stream()
.parallel()
.filter(num -> num<4)
.findAny();
assertTrue(result.isPresent());
assertThat(result.get(),anyOf(is(1), is(2), is(3)));
}
@Test
public void createStream_whenFindFirstResultIsPresent_thenCorrect() {
@ -33,7 +43,7 @@ public class Java8FindAnyFindFirstTest {
Optional<String> result = list.stream().findFirst();
assert result.isPresent();
assertTrue(result.isPresent());
assertThat(result.get(),is("A"));
}
}