Skip to content

Commit ce32db4

Browse files
mariuszsgmessner
authored andcommitted
Verify that PagerSplitter can collect data page by page (#299)
1 parent 8b782fa commit ce32db4

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/test/java/org/gitlab4j/api/PagerSpliteratorTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.gitlab4j.api;
22

33
import java.util.Collections;
4+
import java.util.stream.StreamSupport;
45

56
import org.junit.Assert;
67
import org.junit.Before;
@@ -9,6 +10,8 @@
910
import org.mockito.Mock;
1011
import org.mockito.junit.MockitoJUnitRunner;
1112

13+
import static java.util.Arrays.asList;
14+
import static org.junit.Assert.assertArrayEquals;
1215
import static org.junit.Assert.assertEquals;
1316
import static org.junit.Assert.assertFalse;
1417
import 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

Comments
 (0)