|
4 | 4 | import com.codepoetics.protonpack.StreamUtils; |
5 | 5 | import com.codepoetics.protonpack.collectors.CollectorUtils; |
6 | 6 | import com.codepoetics.protonpack.collectors.NonUniqueValueException; |
7 | | -import com.codepoetics.protonpack.selectors.Selector; |
| 7 | +import com.codepoetics.protonpack.selectors.Selectors; |
8 | 8 | import org.junit.Test; |
9 | 9 |
|
10 | | -import java.util.Arrays; |
11 | 10 | import java.util.List; |
12 | 11 | import java.util.Optional; |
13 | 12 | import java.util.Set; |
@@ -92,20 +91,13 @@ public void givenMultipleStream_whenInterleaved_thenInterleaved() { |
92 | 91 | Stream<String> streamOfPlayers = Stream.of("Ronaldo", "Messi"); |
93 | 92 | Stream<String> streamOfLeagues = Stream.of("Serie A", "La Liga"); |
94 | 93 |
|
95 | | - AtomicInteger counter = new AtomicInteger(0); |
96 | | - Selector roundRobinSelector = (o) -> { |
97 | | - Object[] vals = (Object[]) o; |
98 | | - while (counter.get() >= vals.length || vals[counter.get()] == null) { |
99 | | - if (counter.incrementAndGet() >= vals.length) |
100 | | - counter.set(0); |
101 | | - } |
102 | | - return counter.getAndIncrement(); |
103 | | - }; |
104 | | - Stream<String> interleavedStream = StreamUtils.interleave(roundRobinSelector, streamOfClubs, streamOfPlayers, |
105 | | - streamOfLeagues); |
106 | | - List<String> interleavedList = interleavedStream.collect(Collectors.toList()); |
107 | | - assertThat(interleavedList).containsExactly("Juventus", "Ronaldo", "Serie A", "Barcelona", "Messi", "La Liga", |
108 | | - "Liverpool"); |
| 94 | + List<String> interleavedList = StreamUtils |
| 95 | + .interleave(Selectors.roundRobin(), streamOfClubs, streamOfPlayers, streamOfLeagues) |
| 96 | + .collect(Collectors.toList()); |
| 97 | + |
| 98 | + assertThat(interleavedList) |
| 99 | + .hasSize(7) |
| 100 | + .containsExactly("Juventus", "Ronaldo", "Serie A", "Barcelona", "Messi", "La Liga", "Liverpool"); |
109 | 101 | } |
110 | 102 |
|
111 | 103 | @Test |
|
0 commit comments