PaginatedSearchResultsScroller extends Scroller { @Override public void loadRecordsForNextPage() throws JSONException { if (shouldQueryForMoreData()) { adapter.addAll(childSearch.getRecordsForNextPage(adapter.getCount(), adapter.getCount() + DEFAULT_PAGE_SIZE)); } } PaginatedSearchResultsScroller(ChildSearch childSearch, HighlightedFieldsViewAdapter<Child> adapter); @Override void loadRecordsForNextPage();  }
@Test public void shouldLoadRecordsForNextPage() throws JSONException { childSearch = new ChildSearch("", repository, null); scroller = spy(new PaginatedSearchResultsScroller(childSearch, highlightedFieldsViewAdapter)); List<Child> children = Arrays.asList(new Child("id", "user", "{\"name\": \"Foo Bar\"}")); when(repository.getChildrenMatchingStringBetween(anyString(), anyInt(), anyInt())).thenReturn(children); doReturn(true).when(scroller).shouldQueryForMoreData(); scroller.loadRecordsForNextPage(); verify(repository, times(1)).getChildrenMatchingStringBetween(anyString(), anyInt(), anyInt()); verify(highlightedFieldsViewAdapter, times(1)).addAll(children); }
@Test public void shouldNotLoadRecordsForNextPage() throws JSONException { scroller = spy(new PaginatedSearchResultsScroller(childSearch, highlightedFieldsViewAdapter)); doReturn(false).when(scroller).shouldQueryForMoreData(); scroller.loadRecordsForNextPage(); verify(repository, times(0)).getChildrenMatchingStringBetween(anyString(), anyInt(), anyInt()); verify(highlightedFieldsViewAdapter, times(0)).addAll(anyList()); }