|
4 | 4 | import org.junit.Test; |
5 | 5 |
|
6 | 6 | import java.util.Arrays; |
| 7 | +import java.util.stream.Collectors; |
| 8 | +import java.util.stream.Stream; |
7 | 9 |
|
8 | 10 | import static org.junit.Assert.assertEquals; |
9 | 11 |
|
10 | 12 | public class StreamExMergeStreamsTest { |
11 | 13 |
|
12 | 14 | @Test |
13 | 15 | public void givenTwoStreams_whenMergingStreams_thenResultingStreamContainsElementsFromBothStreams() { |
14 | | - StreamEx<Integer> stream1 = StreamEx.of(1, 3, 5); |
15 | | - StreamEx<Integer> stream2 = StreamEx.of(2, 4, 6); |
| 16 | + Stream<Integer> stream1 = Stream.of(1, 3, 5); |
| 17 | + Stream<Integer> stream2 = Stream.of(2, 4, 6); |
16 | 18 |
|
17 | | - StreamEx<Integer> resultingStream = stream1.append(stream2); |
| 19 | + Stream<Integer> resultingStream = StreamEx.of(stream1).append(stream2); |
18 | 20 |
|
19 | 21 | assertEquals(Arrays.asList(1, 3, 5, 2, 4, 6), |
20 | | - resultingStream.toList()); |
| 22 | + resultingStream.collect(Collectors.toList())); |
21 | 23 | } |
22 | 24 |
|
23 | 25 | @Test |
24 | 26 | public void givenFourStreams_whenMergingStreams_thenResultingStreamContainsElementsFromAllStreams() { |
25 | | - StreamEx<Integer> stream1 = StreamEx.of(1, 3, 5); |
26 | | - StreamEx<Integer> stream2 = StreamEx.of(2, 4, 6); |
27 | | - StreamEx<Integer> stream3 = StreamEx.of(18, 15, 36); |
28 | | - StreamEx<Integer> stream4 = StreamEx.of(99); |
| 27 | + Stream<Integer> stream1 = Stream.of(1, 3, 5); |
| 28 | + Stream<Integer> stream2 = Stream.of(2, 4, 6); |
| 29 | + Stream<Integer> stream3 = Stream.of(18, 15, 36); |
| 30 | + Stream<Integer> stream4 = Stream.of(99); |
29 | 31 |
|
30 | | - StreamEx<Integer> resultingStream = stream1.append(stream2) |
31 | | - .append(stream3) |
32 | | - .append(stream4); |
| 32 | + Stream<Integer> resultingStream = StreamEx.of(stream1) |
| 33 | + .append(stream2) |
| 34 | + .append(stream3) |
| 35 | + .append(stream4); |
33 | 36 |
|
34 | 37 | assertEquals(Arrays.asList(1, 3, 5, 2, 4, 6, 18, 15, 36, 99), |
35 | | - resultingStream.toList()); |
| 38 | + resultingStream.collect(Collectors.toList())); |
36 | 39 |
|
37 | 40 | } |
38 | 41 |
|
39 | 42 | @Test |
40 | 43 | public void givenThreeStreams_whenAppendingAndPrependingStreams_thenResultingStreamContainsElementsFromAllStreams() { |
41 | | - StreamEx<String> stream1 = StreamEx.of("foo", "bar"); |
42 | | - StreamEx<String> openingBracketStream = StreamEx.of("["); |
43 | | - StreamEx<String> closingBracketStream = StreamEx.of("]"); |
| 44 | + Stream<String> stream1 = Stream.of("foo", "bar"); |
| 45 | + Stream<String> openingBracketStream = Stream.of("["); |
| 46 | + Stream<String> closingBracketStream = Stream.of("]"); |
44 | 47 |
|
45 | | - StreamEx<String> resultingStream = stream1.append(closingBracketStream) |
46 | | - .prepend(openingBracketStream); |
| 48 | + Stream<String> resultingStream = StreamEx.of(stream1) |
| 49 | + .append(closingBracketStream) |
| 50 | + .prepend(openingBracketStream); |
47 | 51 |
|
48 | 52 | assertEquals(Arrays.asList("[", "foo", "bar", "]"), |
49 | | - resultingStream.toList()); |
| 53 | + resultingStream.collect(Collectors.toList())); |
50 | 54 | } |
51 | 55 | } |
0 commit comments