Skip to content

Commit 0dd6ddd

Browse files
daveRanjanmaibin
authored andcommitted
Updated test method names to BDD convention (eugenp#2643)
1 parent 562b9fc commit 0dd6ddd

2 files changed

Lines changed: 31 additions & 37 deletions

File tree

‎libraries/src/test/java/com/baeldung/protonpack/CollectorUtilsTests.java‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
public class CollectorUtilsTests {
1717

1818
@Test
19-
public void maxByWithProjectionAndDefaultComparer() {
19+
public void givenIntegerStream_whenCollectOnMaxByProjection_shouldReturnOptionalMaxValue() {
2020
Stream<String> integerStream = Stream.of("a", "bb", "ccc", "1");
2121

2222
Optional<String> max = integerStream.collect(maxBy(String::length));
@@ -25,7 +25,7 @@ public void maxByWithProjectionAndDefaultComparer() {
2525
}
2626

2727
@Test
28-
public void minByWithProjectionAndDefaultComparer() {
28+
public void givenIntegerStream_whenCollectOnMinByProjection_shouldReturnOptionalMinValue() {
2929
Stream<String> integerStream = Stream.of("abc", "bb", "ccc", "1");
3030

3131
Optional<String> max = integerStream.collect(minBy(String::length));
@@ -34,30 +34,30 @@ public void minByWithProjectionAndDefaultComparer() {
3434
}
3535

3636
@Test
37-
public void returnsEmptyForEmptyStream() {
37+
public void givenEmptyStream_withCollectorUnique_shouldReturnEmpty() {
3838
assertThat(Stream
3939
.empty()
4040
.collect(CollectorUtils.unique()), equalTo(Optional.empty()));
4141
}
4242

4343
@Test
44-
public void returnsUniqueItem() {
44+
public void givenIntegerStream_withCollectorUnique_shouldReturnUniqueValue() {
4545
assertThat(Stream
4646
.of(1, 2, 3)
4747
.filter(i -> i > 2)
4848
.collect(CollectorUtils.unique()), equalTo(Optional.of(3)));
4949
}
5050

5151
@Test
52-
public void returnsUniqueNullableItem() {
52+
public void givenIntegerStream_withUniqueNullable_shouldReturnUniqueValue() {
5353
assertThat(Stream
5454
.of(1, 2, 3)
5555
.filter(i -> i > 2)
5656
.collect(CollectorUtils.uniqueNullable()), equalTo(3));
5757
}
5858

5959
@Test(expected = NonUniqueValueException.class)
60-
public void throwsExceptionIfItemIsNotUnique() {
60+
public void givenIntegerStream_withCollectorUnique_shouldThrowNonUniqueValueException() {
6161
Stream
6262
.of(1, 2, 3)
6363
.filter(i -> i > 1)

‎libraries/src/test/java/com/baeldung/protonpack/StreamUtilsTests.java‎

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,7 @@
2121
public 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

Comments
 (0)