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