TimelineDelegate { void loadNext(Long minPosition, Callback<TimelineResult<T>> cb) { if (withinMaxCapacity()) { if (timelineStateHolder.startTimelineRequest()) { timeline.next(minPosition, cb); } else { cb.failure(new TwitterException("Request already in flight")); } } else { cb.failure(new TwitterException("Max capacity reached")); } } TimelineDelegate(Timeline<T> timeline);   TimelineDelegate(Timeline<T> timeline, DataSetObservable observable, List<T> items); void refresh(Callback<TimelineResult<T>> developerCb); void next(Callback<TimelineResult<T>> developerCb); void previous(); int getCount(); Timeline getTimeline(); T getItem(int position); long getItemId(int position); void setItemById(T item); void registerDataSetObserver(DataSetObserver observer); void unregisterDataSetObserver(DataSetObserver observer); void notifyDataSetChanged(); void notifyDataSetInvalidated();  }
@Test public void testLoadNext() { delegate = new TimelineDelegate<>(mockTimeline); final Callback<TimelineResult<TestItem>> testCb = delegate.new NextCallback(null, delegate.timelineStateHolder); delegate.loadNext(TEST_MIN_POSITION, testCb); verify(mockTimeline).next(TEST_MIN_POSITION, testCb); }
@Test public void testLoadNext_respectsMaxCapacity() { delegate = new TimelineDelegate<>(mockTimeline); TestItem.populateList(delegate.itemList, TimelineDelegate.CAPACITY); final Callback<TimelineResult<TestItem>> mockCallback = mock(Callback.class); delegate.loadNext(ANY_POSITION, mockCallback); final ArgumentCaptor<TwitterException> exceptionCaptor = ArgumentCaptor.forClass(TwitterException.class); verifyZeroInteractions(mockTimeline); verify(mockCallback).failure(exceptionCaptor.capture()); assertEquals(exceptionCaptor.getValue().getMessage(), REQUIRED_MAX_CAPACITY_ERROR); }
@Test public void testLoadNext_respectsRequestInFlight() { delegate = new TimelineDelegate<>(mockTimeline); delegate.timelineStateHolder.startTimelineRequest(); final Callback<TimelineResult<TestItem>> mockCallback = mock(Callback.class); delegate.loadNext(ANY_POSITION, mockCallback); final ArgumentCaptor<TwitterException> exceptionCaptor = ArgumentCaptor.forClass(TwitterException.class); verifyZeroInteractions(mockTimeline); verify(mockCallback).failure(exceptionCaptor.capture()); assertEquals(exceptionCaptor.getValue().getMessage(), REQUIRED_REQUEST_IN_FLIGHT_ERROR); }