1+ package org .gitlab4j .api ;
2+
3+ import java .util .Collections ;
4+
5+ import org .junit .Assert ;
6+ import org .junit .Before ;
7+ import org .junit .Test ;
8+ import org .junit .runner .RunWith ;
9+ import org .mockito .Mock ;
10+ import org .mockito .junit .MockitoJUnitRunner ;
11+
12+ import static org .junit .Assert .assertEquals ;
13+ import static org .junit .Assert .assertFalse ;
14+ import static org .junit .Assert .assertTrue ;
15+ import static org .mockito .Mockito .when ;
16+
17+ @ RunWith (MockitoJUnitRunner .class )
18+ public class PagerSpliteratorTest {
19+
20+ PagerSpliterator <Integer > pagerSpliterator ;
21+
22+ @ Mock
23+ Pager pager ;
24+
25+ @ Before
26+ public void setUp () {
27+ pagerSpliterator = new PagerSpliterator <>(pager );
28+ }
29+
30+ @ Test
31+ public void shouldAcceptElementFromSource () {
32+ when (pager .hasNext ()).thenReturn (true );
33+ when (pager .next ()).thenReturn (Collections .singletonList (1 ));
34+
35+ boolean success = pagerSpliterator .tryAdvance (System .out ::println );
36+
37+ assertTrue (success );
38+ }
39+
40+ @ Test
41+ public void shouldDoNotFailOnEmptySource () {
42+ boolean success = pagerSpliterator .tryAdvance (System .out ::println );
43+
44+ assertFalse (success );
45+ }
46+
47+ @ Test
48+ public void shouldThrowNullPointerExceptionWhenActionIsMissing () {
49+ try {
50+ pagerSpliterator .tryAdvance (null );
51+ Assert .fail ("Missing NullPointerException" );
52+ } catch (Throwable e ) {
53+ assertEquals (NullPointerException .class , e .getClass ());
54+ }
55+ }
56+ }
0 commit comments