11package org .gitlab4j .api ;
22
33import java .util .Collections ;
4+ import java .util .stream .StreamSupport ;
45
56import org .junit .Assert ;
67import org .junit .Before ;
910import org .mockito .Mock ;
1011import org .mockito .junit .MockitoJUnitRunner ;
1112
13+ import static java .util .Arrays .asList ;
14+ import static org .junit .Assert .assertArrayEquals ;
1215import static org .junit .Assert .assertEquals ;
1316import static org .junit .Assert .assertFalse ;
1417import static org .junit .Assert .assertTrue ;
@@ -53,4 +56,23 @@ public void shouldThrowNullPointerExceptionWhenActionIsMissing() {
5356 assertEquals (NullPointerException .class , e .getClass ());
5457 }
5558 }
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+ }
5678}
0 commit comments