Skip to content

Commit 901b2d7

Browse files
committed
Improve unit test code
1 parent 2bd1df4 commit 901b2d7

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

http/http/src/test/java/io/helidon/http/HeaderValueIterableTest.java

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818

1919
import java.util.ArrayList;
2020
import java.util.Arrays;
21-
import java.util.Collection;
2221
import java.util.HashSet;
2322
import java.util.Iterator;
2423
import java.util.List;
24+
import java.util.Set;
2525
import java.util.stream.Stream;
2626
import java.util.stream.StreamSupport;
2727

@@ -36,8 +36,11 @@
3636

3737
class HeaderValueIterableTest {
3838
private static final List<String> ordinalNumbers = Arrays.asList("First", "Second", "Third");
39-
private static final String FourthOrdinal = "Fourth";
39+
private static final Set<String> ordinalNumbersSet = new HashSet<>(ordinalNumbers);
40+
private static final CustomIterableString ordinalNumbersCustomIterable = new CustomIterableString(ordinalNumbers);
4041
private static final List<String> emptyStringIterable = Arrays.asList("");
42+
private static final CustomIterableString emptyCustomIterable = new CustomIterableString(emptyStringIterable);
43+
private static final String FourthOrdinal = "Fourth";
4144

4245
@ParameterizedTest
4346
@MethodSource("IterableObjects")
@@ -61,7 +64,6 @@ void testAddValueOnHeaderValueIterable(Iterable<String> ordinals) {
6164
// This will be not equal because "Fourth" was added
6265
assertThat(ordinalsList, not(headerValueList.allValues()));
6366

64-
// ordinalsList.add("Fourth");
6567
List<String> ordinalsListWithFourth = new ArrayList<>(ordinalsList);
6668
ordinalsListWithFourth.add("Fourth");
6769
assertThat(ordinalsListWithFourth, is(headerValueList.allValues()));
@@ -82,28 +84,19 @@ private static Stream<Arguments> IterableObjects() {
8284
return Stream.of(
8385
// Collection type iterable
8486
arguments(ordinalNumbers),
85-
arguments(new HashSet<>(ordinalNumbers)),
86-
// non-Collection type iterable
87-
arguments(new CustomStringIterable(ordinalNumbers))
88-
);
89-
}
90-
91-
// This will allow testing of a Collection and non-Collection type Iterable
92-
private static Stream<Arguments> MutableIterableObjects() {
93-
return Stream.of(
94-
// Collection type iterable
95-
arguments(new ArrayList<>(ordinalNumbers)),
87+
arguments(ordinalNumbersSet),
9688
// non-Collection type iterable
97-
arguments(new CustomStringIterable(ordinalNumbers))
89+
arguments(ordinalNumbersCustomIterable)
9890
);
9991
}
10092

93+
// This will test empty value iterables will still work
10194
private static Stream<Arguments> EmptyStringIterableObjects() {
10295
return Stream.of(
10396
// Collection type iterable
10497
arguments(emptyStringIterable),
10598
// non-Collection type iterable
106-
arguments(new CustomStringIterable(emptyStringIterable))
99+
arguments(emptyCustomIterable)
107100
);
108101
}
109102

@@ -115,10 +108,10 @@ private static List<String> convertIterableStringToList(Iterable<String> iterabl
115108
}
116109

117110
// Custom non-Collection type Iterable
118-
static class CustomStringIterable implements Iterable<String> {
111+
static class CustomIterableString implements Iterable<String> {
119112
private final List<String> data;
120113

121-
public CustomStringIterable(List<String> data) {
114+
public CustomIterableString(List<String> data) {
122115
this.data = data;
123116
}
124117

0 commit comments

Comments
 (0)