TimelineDelegate { public T getItem(int position) { if (isLastPosition(position)) { previous(); } return itemList.get(position); } 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 testGetItem() { delegate = new TimelineDelegate<>(mockTimeline, null, testItems); assertEquals(TEST_ITEM_2, delegate.getItem(0)); assertEquals(TEST_ITEM_1, delegate.getItem(1)); }
@Test public void testNextCallback_successReceivedItems() { delegate = new TimelineDelegate<>(mockTimeline, mockObservable, testItems); final TimelineStateHolder timelineStateHolder = new TimelineStateHolder( new TimelineCursor(ANY_POSITION, ANY_POSITION), new TimelineCursor(ANY_POSITION, ANY_POSITION)); final TimelineDelegate.NextCallback cb = delegate.new NextCallback(null, timelineStateHolder); cb.success(new Result<>(new TimelineResult<>(TEST_TIMELINE_CURSOR, testExtraItems), null)); assertEquals(TEST_MAX_POSITION, timelineStateHolder.positionForNext()); assertEquals(ANY_POSITION, timelineStateHolder.positionForPrevious()); assertEquals(TOTAL_ITEMS, delegate.itemList.size()); assertEquals(TEST_ITEM_4, delegate.getItem(0)); assertEquals(TEST_ITEM_3, delegate.getItem(1)); assertEquals(TEST_ITEM_2, delegate.getItem(2)); assertEquals(TEST_ITEM_1, delegate.getItem(3)); verify(mockObservable).notifyChanged(); }
@Test public void testRefreshCallback_successReceivedItems() { delegate = new TimelineDelegate<>(mockTimeline, mockObservable, testItems); final TimelineStateHolder timelineStateHolder = new TimelineStateHolder( new TimelineCursor(ANY_POSITION, ANY_POSITION), new TimelineCursor(ANY_POSITION, ANY_POSITION)); final TimelineDelegate.RefreshCallback cb = delegate.new RefreshCallback(null, timelineStateHolder); cb.success(new Result<>(new TimelineResult<>(TEST_TIMELINE_CURSOR, testExtraItems), null)); assertEquals(TEST_MAX_POSITION, timelineStateHolder.positionForNext()); assertEquals(ANY_POSITION, timelineStateHolder.positionForPrevious()); assertEquals(testExtraItems.size(), delegate.itemList.size()); assertEquals(TEST_ITEM_4, delegate.getItem(0)); assertEquals(TEST_ITEM_3, delegate.getItem(1)); verify(mockObservable).notifyChanged(); }
@Test public void testPreviousCallback_successReceivedItems() { delegate = new TimelineDelegate<>(mockTimeline, mockObservable, testItems); final TimelineStateHolder timelineStateHolder = new TimelineStateHolder( new TimelineCursor(ANY_POSITION, ANY_POSITION), new TimelineCursor(ANY_POSITION, ANY_POSITION)); final TimelineDelegate.PreviousCallback cb = delegate.new PreviousCallback(timelineStateHolder); cb.success(new Result<>(new TimelineResult<>(TEST_TIMELINE_CURSOR, testExtraItems), null)); assertEquals(TEST_MIN_POSITION, timelineStateHolder.positionForPrevious()); assertEquals(ANY_POSITION, timelineStateHolder.positionForNext()); assertEquals(TOTAL_ITEMS, delegate.itemList.size()); assertEquals(TEST_ITEM_2, delegate.getItem(0)); assertEquals(TEST_ITEM_1, delegate.getItem(1)); assertEquals(TEST_ITEM_4, delegate.getItem(2)); assertEquals(TEST_ITEM_3, delegate.getItem(3)); verify(mockObservable).notifyChanged(); }