diff --git a/core-java/src/test/java/com/baeldung/java8/Java8FindAnyFindFirstTest.java b/core-java/src/test/java/com/baeldung/java8/Java8FindAnyFindFirstTest.java index 7708d7e098..9fb2bee647 100644 --- a/core-java/src/test/java/com/baeldung/java8/Java8FindAnyFindFirstTest.java +++ b/core-java/src/test/java/com/baeldung/java8/Java8FindAnyFindFirstTest.java @@ -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 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 list = Arrays.asList(1,2,3,4,5); + Optional 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 result = list.stream().findFirst(); - assert result.isPresent(); + assertTrue(result.isPresent()); assertThat(result.get(),is("A")); } }