What would be a good way to compare two Stream
instances in Java 8 and find out whether they have the same elements, specifically for purposes of unit testing?<
You can assert the stream's content without creating a Stream<> expected
.
AssertJ has fluent and readable solutions for this.
import static org.assertj.core.api.Assertions.assertThat;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
class MyTests {
@Test
void test() {
Stream actual = Stream.of(0, 8, 15); // your thingUnderTest
assertThat(actual).containsExactly(0, 8, 15);
}
}