-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListUtilsTest.java
More file actions
87 lines (68 loc) · 2.38 KB
/
Copy pathListUtilsTest.java
File metadata and controls
87 lines (68 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package com.bremp.utils;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
@DisplayName("ListUtils - splitToSubLists")
class ListUtilsTest {
@Test
@DisplayName("throws exception when number of sublists is zero.")
void whenNumberOfSubListsIsZero() {
List<String> list = new ArrayList<>();
int numOfLists = 0;
Assertions.assertThrows(IllegalArgumentException.class,
() -> ListUtils.splitToSubLists(list, numOfLists));
}
@Test
@DisplayName("when list is null.")
void whenListIsNull() {
List<String> list = null;
int numOfLists = 4;
List<List<String>> actual = ListUtils.splitToSubLists(list, numOfLists);
assertThat(actual.size(), is(0));
}
@Test
@DisplayName("when list is empty.")
void whenListIsEmpty() {
List<String> list = Collections.emptyList();
int numOfLists = 1;
List<List<String>> actual = ListUtils.splitToSubLists(list, numOfLists);
assertThat(actual.size(), is(0));
}
@Test
@DisplayName("when number of sublists is greater than list size.")
void whenNumberOfSubListsIsGreaterThanListSize() {
List<String> list = Collections.singletonList("1");
int numOfLists = 2;
List<List<String>> actual = ListUtils.splitToSubLists(list, numOfLists);
assertThat(actual.size(), is(1));
}
@ParameterizedTest
@DisplayName("with varying list sizes.")
@CsvSource({
"1, 1, 1",
"'1,2', 2, 1",
"'1,2,3', 3, 1",
"'1,2,3,4', 3, 2",
"'1,2,3,4,5', 3, 2",
"'1,2,3,4,5,6', 3, 2",
"'1,2,3,4,5,6,7', 3, 3",
"'1,2,3,4,5,6,7,8', 3, 3",
"'1,2,3,4,5,6,7,8,9', 3, 3"
})
void withVaryingListSizes(String listContent, int expectedListSize, int expectedSubListSize) {
List<String> list = Arrays.asList(listContent.split(","));
int numOfLists = 3;
List<List<String>> actual = ListUtils.splitToSubLists(list, numOfLists);
actual.forEach(s -> System.out.println(s.toString()));
assertThat(actual.size(), is(expectedListSize));
assertThat(actual.get(0).size(), is(expectedSubListSize));
}
}