5
5
import java .util .Arrays ;
6
6
import java .util .List ;
7
7
import java .util .stream .Collectors ;
8
- import java .util .stream .Stream ;
8
+ import java .util .stream .IntStream ;
9
9
10
10
import static com .pivovarit .collectors .BatchingSpliterator .partitioned ;
11
11
import static org .assertj .core .api .Assertions .assertThat ;
@@ -15,33 +15,33 @@ class BatchingSpliteratorTest {
15
15
16
16
@ Test
17
17
void shouldSplitInNEvenBatches () {
18
- List < Integer > list = Stream . generate (() -> 42 ). limit ( 10 ). collect ( Collectors . toList () );
18
+ var list = IntStream . range ( 0 , 10 ). boxed (). toList ();
19
19
20
- List < List < Integer >> result = partitioned (list , 3 ).collect ( Collectors . toList () );
20
+ var result = partitioned (list , 3 ).toList ();
21
21
22
22
assertThat (result )
23
- .hasSize (3 )
24
- .extracting (List ::size )
25
- .contains (4 , 3 );
23
+ .hasSize (3 )
24
+ .extracting (List ::size )
25
+ .contains (4 , 3 );
26
26
}
27
27
28
28
@ Test
29
29
void shouldSplitInNBatches () {
30
- List < Integer > list = Stream . generate (() -> 42 ). limit ( 10 ). collect ( Collectors . toList () );
30
+ var list = IntStream . range ( 0 , 10 ). boxed (). toList ();
31
31
32
- List < List < Integer >> result = partitioned (list , 2 ).collect ( Collectors . toList () );
32
+ var result = partitioned (list , 2 ).toList ();
33
33
34
34
assertThat (result )
35
- .hasSize (2 )
36
- .extracting (List ::size )
37
- .containsOnly (5 );
35
+ .hasSize (2 )
36
+ .extracting (List ::size )
37
+ .containsOnly (5 );
38
38
}
39
39
40
40
@ Test
41
41
void shouldSplitInNSingletonLists () {
42
- List < Integer > list = Stream . generate (() -> 42 ). limit ( 5 ). collect ( Collectors . toList () );
42
+ var list = IntStream . range ( 0 , 5 ). boxed (). toList ();
43
43
44
- List < List < Integer >> result = partitioned (list , 10 ).collect ( Collectors . toList () );
44
+ var result = partitioned (list , 10 ).toList ();
45
45
46
46
assertThat (result )
47
47
.hasSize (5 )
@@ -51,15 +51,29 @@ void shouldSplitInNSingletonLists() {
51
51
52
52
@ Test
53
53
void shouldReturnNestedListIfOneBatch () {
54
- List < Integer > list = Stream . generate (() -> 42 ). limit ( 10 ). collect ( Collectors . toList () );
54
+ var list = IntStream . range ( 0 , 10 ). boxed (). toList ();
55
55
56
- List < List < Integer >> result = partitioned (list , 1 ).collect ( Collectors . toList () );
56
+ var result = partitioned (list , 1 ).toList ();
57
57
58
- assertThat (result .get ( 0 )).containsExactlyElementsOf (list );
58
+ assertThat (result .getFirst ( )).containsExactlyElementsOf (list );
59
59
}
60
60
61
61
@ Test
62
62
void shouldReturnEmptyIfZeroParts () {
63
63
assertThatThrownBy (() -> partitioned (Arrays .asList (1 , 2 , 3 ), 0 ).collect (Collectors .toList ()));
64
64
}
65
+
66
+ @ Test
67
+ void shouldReportCorrectSizeWhenOneBatch () {
68
+ var list = IntStream .range (0 , 10 ).boxed ().toList ();
69
+
70
+ assertThat (partitioned (list , 1 ).count ()).isEqualTo (1 );
71
+ }
72
+
73
+ @ Test
74
+ void shouldReportCorrectSizeWhenMultipleBatches () {
75
+ var list = IntStream .range (0 , 10 ).boxed ().toList ();
76
+
77
+ assertThat (partitioned (list , 2 ).count ()).isEqualTo (2 );
78
+ }
65
79
}
0 commit comments