@Test public void shouldInitializePaginationOptionWithOffset0ForFirstPage() { Map<String, String> parameters = new HashMap<>(); Paginator paginator = new Paginator(parameters, scheme, parser); when(scheme.nextPage(eq(parameters), any(Page.class))).thenReturn("testresponse"); when(parser.parse("testresponse")) .thenReturn(new PaginatedResponse(null, new PaginatedResponseMeta(null, null, null, 0))); paginator.nextPage(); ArgumentCaptor<Page> optionCaptor = ArgumentCaptor.forClass(Page.class); verify(scheme).nextPage(eq(parameters), optionCaptor.capture()); Page paginationOption = optionCaptor.getValue(); assertEquals(100, paginationOption.getLimit()); assertEquals(0, paginationOption.getOffset()); }
@Test public void shouldReturnNullIfNoPage() { Map<String, String> parameters = new HashMap<>(); Paginator paginator = new Paginator(parameters, scheme, parser); PaginatedResponse paginatedResult = new PaginatedResponse( new JsonArray(), new PaginatedResponseMeta(new Page(100, 10), null, new Page(90, 10), 10)); when(parser.parse(anyString())).thenReturn(paginatedResult); paginator.nextPage(); PaginatedResponse lastPage = paginator.nextPage(); ArgumentCaptor<Page> optionCaptor = ArgumentCaptor.forClass(Page.class); verify(scheme, times(1)).nextPage(eq(parameters), optionCaptor.capture()); Page paginationOption = optionCaptor.getValue(); assertEquals(100, paginationOption.getLimit()); assertEquals(0, paginationOption.getOffset()); assertNull(lastPage); }