1
1
package org .gitlab4j .api ;
2
2
3
3
import java .util .Collections ;
4
+ import java .util .stream .StreamSupport ;
4
5
5
6
import org .junit .Assert ;
6
7
import org .junit .Before ;
9
10
import org .mockito .Mock ;
10
11
import org .mockito .junit .MockitoJUnitRunner ;
11
12
13
+ import static java .util .Arrays .asList ;
14
+ import static org .junit .Assert .assertArrayEquals ;
12
15
import static org .junit .Assert .assertEquals ;
13
16
import static org .junit .Assert .assertFalse ;
14
17
import static org .junit .Assert .assertTrue ;
@@ -53,4 +56,23 @@ public void shouldThrowNullPointerExceptionWhenActionIsMissing() {
53
56
assertEquals (NullPointerException .class , e .getClass ());
54
57
}
55
58
}
59
+
60
+ @ Test
61
+ public void shouldAllowToGatherDataPageByPage () {
62
+ when (pager .hasNext ()).thenReturn (true );
63
+ when (pager .getTotalItems ()).thenReturn (12 );
64
+ when (pager .next ())
65
+ .thenReturn (asList (1 , 2 , 3 ))
66
+ .thenReturn (asList (4 , 5 , 6 ))
67
+ .thenReturn (asList (7 , 8 , 9 ))
68
+ .thenReturn (asList (0 , 1 , 2 ));
69
+
70
+ Integer [] elements = StreamSupport .stream (new PagerSpliterator <Integer >(pager ), false )
71
+ .parallel () // should be ignored
72
+ .skip (2 ) // should be ignored
73
+ .limit (5 )
74
+ .toArray (Integer []::new );
75
+
76
+ assertArrayEquals (new Integer []{1 , 2 , 3 , 4 , 5 }, elements );
77
+ }
56
78
}
0 commit comments