2121public class StreamUtilsTests {
2222
2323 @ Test
24- public void createInfiniteIndex () {
25- LongStream indices = StreamUtils
26- .indices ()
27- .limit (500 );
28-
29- }
30-
31- @ Test
32- public void zipAStreamWithIndex () {
24+ public void givenStream_whenZipWithIndex_shouldReturnZippedStreamWithIndex () {
3325 Stream <String > source = Stream .of ("Foo" , "Bar" , "Baz" );
3426
3527 List <Indexed <String >> zipped = StreamUtils
@@ -40,7 +32,7 @@ public void zipAStreamWithIndex() {
4032 }
4133
4234 @ Test
43- public void zipAPairOfStreams () {
35+ public void givenTwoStreams_whenZip_shouldReturnZippedStream () {
4436 Stream <String > streamA = Stream .of ("A" , "B" , "C" );
4537 Stream <String > streamB = Stream .of ("Apple" , "Banana" , "Carrot" );
4638
@@ -52,7 +44,7 @@ public void zipAPairOfStreams() {
5244 }
5345
5446 @ Test
55- public void zipThreeStreams () {
47+ public void givenThreeStreams_whenZip_shouldReturnZippedStream () {
5648 Stream <String > streamA = Stream .of ("A" , "B" , "C" );
5749 Stream <String > streamB = Stream .of ("aggravating" , "banausic" , "complaisant" );
5850 Stream <String > streamC = Stream .of ("Apple" , "Banana" , "Carrot" );
@@ -65,7 +57,8 @@ public void zipThreeStreams() {
6557 }
6658
6759 @ Test
68- public void mergeThreeStreams () {
60+ //givenThreeStreams_whenMerge_shouldReturnMergedStream
61+ public void givenThreeStreams_whenMerge_shouldReturnMergedStream () {
6962 Stream <String > streamA = Stream .of ("A" , "B" , "C" );
7063 Stream <String > streamB = Stream .of ("apple" , "banana" , "carrot" , "date" );
7164 Stream <String > streamC = Stream .of ("fritter" , "split" , "cake" , "roll" , "pastry" );
@@ -76,7 +69,8 @@ public void mergeThreeStreams() {
7669 }
7770
7871 @ Test
79- public void roundRobinInterleaving () {
72+ //givenThreeStreams_whenInterleave_shouldReturnRoundRobinInterleavingStream
73+ public void givenThreeStreams_whenInterleave_shouldReturnRoundRobinInterleavingStream () {
8074 Stream <String > streamA = Stream .of ("Peter" , "Paul" , "Mary" );
8175 Stream <String > streamB = Stream .of ("A" , "B" , "C" , "D" , "E" );
8276 Stream <String > streamC = Stream .of ("foo" , "bar" , "baz" , "xyzzy" );
@@ -87,23 +81,24 @@ public void roundRobinInterleaving() {
8781 }
8882
8983 @ Test
90- public void takeWhileConditionIsMet () {
84+ //givenInfiniteStream_whenTakeWhile10_shouldReturnStreamOfSize10
85+ public void givenInfiniteStream_whenTakeWhile10_shouldReturnStream () {
9186 Stream <Integer > infiniteInts = Stream .iterate (0 , i -> i + 1 );
9287 Stream <Integer > finiteInts = StreamUtils .takeWhile (infiniteInts , i -> i < 10 );
9388
9489 assertThat (finiteInts .collect (Collectors .toList ()), hasSize (10 ));
9590 }
9691
9792 @ Test
98- public void takeUntilConditionIsNotMet () {
93+ public void givenInfiniteStream_whenTakeUntil10_shouldReturnStreamUpto10 () {
9994 Stream <Integer > infiniteInts = Stream .iterate (0 , i -> i + 1 );
10095 Stream <Integer > finiteInts = StreamUtils .takeUntil (infiniteInts , i -> i > 10 );
10196
10297 assertThat (finiteInts .collect (Collectors .toList ()), hasSize (11 ));
10398 }
10499
105100 @ Test
106- public void skipWhileConditionMet () {
101+ public void givenIntegerStreamOfTen_whenSkipWhileLessThanFour_shouldReturnStreamFromFourToTen () {
107102 Stream <Integer > ints = Stream .of (1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 );
108103 Stream <Integer > skipped = StreamUtils .skipWhile (ints , i -> i < 4 );
109104 List <Integer > collected = skipped .collect (Collectors .toList ());
@@ -112,7 +107,7 @@ public void skipWhileConditionMet() {
112107 }
113108
114109 @ Test
115- public void skipUntilConditionMet () {
110+ public void givenIntegerStreamOfTen_whenSkipUntilFour_shouldReturnStreamFromFiveToTen () {
116111 Stream <Integer > ints = Stream .of (1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 );
117112 Stream <Integer > skipped = StreamUtils .skipUntil (ints , i -> i > 4 );
118113 List <Integer > collected = skipped .collect (Collectors .toList ());
@@ -121,14 +116,14 @@ public void skipUntilConditionMet() {
121116 }
122117
123118 @ Test
124- public void unfoldUntilEmptyIsReturned () {
119+ public void givenSeedValue_withUnfold_shouldReturnStreamAccordingToGeneratorMethod () {
125120 Stream <Integer > unfolded = StreamUtils .unfold (1 , i -> (i < 10 ) ? Optional .of (i + 1 ) : Optional .empty ());
126121
127122 assertThat (unfolded .collect (Collectors .toList ()), contains (1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ));
128123 }
129124
130125 @ Test
131- public void groupRunsStreamTest () {
126+ public void giveIntegerStream_whenGroupRuns_shouldReturnListGroupItems () {
132127 Stream <Integer > integerStream = Stream .of (1 , 1 , 2 , 2 , 3 , 4 , 5 );
133128 List <List <Integer >> runs = StreamUtils
134129 .groupRuns (integerStream )
@@ -138,14 +133,14 @@ public void groupRunsStreamTest() {
138133 }
139134
140135 @ Test
141- public void aggreagateOnBiElementPredicate () {
136+ public void givenAStream_whenAggregate_shouldReturnAggregatedStreamOnTheBasisOfBiFunction () {
142137 Stream <String > stream = Stream .of ("a1" , "b1" , "b2" , "c1" );
143138 Stream <List <String >> aggregated = StreamUtils .aggregate (stream , (e1 , e2 ) -> e1 .charAt (0 ) == e2 .charAt (0 ));
144139 assertThat (aggregated .collect (toList ()), contains (asList ("a1" ), asList ("b1" , "b2" ), asList ("c1" )));
145140 }
146141
147142 @ Test
148- public void windowingOnList () {
143+ public void givenIntegerStream_whenWindowed_shouldReturnListOfListOfItemsOfWindowSize () {
149144 Stream <Integer > integerStream = Stream .of (1 , 2 , 3 , 4 , 5 );
150145
151146 List <List <Integer >> windows = StreamUtils
@@ -156,7 +151,8 @@ public void windowingOnList() {
156151 }
157152
158153 @ Test
159- public void windowingOnListTwoOverlap () {
154+ //givenIntegerStream_whenWindowedWithWindowSizeAndSkip_shouldReturnListOfListOfWindowSizeAddingASkip
155+ public void givenIntegerStream_whenWindowedWithWindowSizeAndSkip_shouldReturnListOfListOfWindowSizeAddingASkip () {
160156 Stream <Integer > integerStream = Stream .of (1 , 2 , 3 , 4 , 5 );
161157
162158 List <List <Integer >> windows = StreamUtils
@@ -167,7 +163,7 @@ public void windowingOnListTwoOverlap() {
167163 }
168164
169165 @ Test
170- public void windowingOnEmptyList () {
166+ public void givenEmptyStream_whenWindowed_shouldReturnIterableWithSizeZero () {
171167 ArrayList <Integer > ints = new ArrayList <>();
172168
173169 ints
@@ -184,7 +180,7 @@ public void windowingOnEmptyList() {
184180 }
185181
186182 @ Test
187- public void windowingOnListTwoOverlapAllowLesserSize () {
183+ public void givenIntegerStream_whenWindowedWithWindowSizeAndSkipAndAllowLesserSize_shouldReturnListOfListOfInteger () {
188184 Stream <Integer > integerStream = Stream .of (1 , 2 , 3 , 4 , 5 );
189185
190186 List <List <Integer >> windows = StreamUtils
@@ -195,14 +191,12 @@ public void windowingOnListTwoOverlapAllowLesserSize() {
195191 }
196192
197193 @ Test
198- public void windowingOnListOneOverlapAllowLesserSizeMultipleLesserWindows () {
199- Stream <Integer > integerStream = Stream .of (1 , 2 , 3 , 4 , 5 );
200-
201- List <List <Integer >> windows = StreamUtils
202- .windowed (integerStream , 3 , 1 , true )
203- .collect (toList ());
194+ public void givenLimit_withIndices_shouldReturnLongStreamUptoLimit () {
195+ LongStream indices = StreamUtils
196+ .indices ()
197+ .limit (500 );
204198
205- assertThat (windows , contains ( asList ( 1 , 2 , 3 ), asList ( 2 , 3 , 4 ), asList ( 3 , 4 , 5 ), asList ( 4 , 5 ), asList ( 5 ) ));
199+ assertThat (indices . count ( ), equalTo ( 500 ));
206200 }
207201
208202}
0 commit comments