コード例 #1
0
 // should set both nextCursor and previousCursor to be non-null
 @Test
 public void testNextCallback_successFirstReceivedItems() {
   delegate = new TimelineDelegate<>(mockTimeline, mockObservable, testItems);
   final TimelineStateHolder timelineStateHolder = new TimelineStateHolder();
   final TimelineDelegate.NextCallback cb = delegate.new NextCallback(null, timelineStateHolder);
   cb.success(new Result<>(new TimelineResult<>(TEST_TIMELINE_CURSOR, testExtraItems), null));
   // assert the next TimelineCursor is set on the ScrollStateHolder, previous unchanged
   assertEquals(TEST_MAX_POSITION, timelineStateHolder.positionForNext());
   assertEquals(TEST_MIN_POSITION, timelineStateHolder.positionForPrevious());
 }
コード例 #2
0
 // should do nothing
 @Test
 public void testNextCallback_successReceivedZeroItems() {
   delegate = new TimelineDelegate<>(mockTimeline, mockObservable, testItems);
   final TimelineStateHolder timelineStateHolder = new TimelineStateHolder();
   final TimelineDelegate.NextCallback cb = delegate.new NextCallback(null, timelineStateHolder);
   cb.success(
       new Result<>(new TimelineResult<>(TEST_TIMELINE_CURSOR, Collections.emptyList()), null));
   // assert that the cursors and itemList are left unmodified
   assertNull(timelineStateHolder.positionForNext());
   assertNull(timelineStateHolder.positionForPrevious());
   assertEquals(testItems.size(), delegate.itemList.size());
   verifyZeroInteractions(mockObservable);
 }
コード例 #3
0
 // should prepend result items, set next cursor, and call notifyChanged
 @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));
   // assert the next TimelineCursor is set on the ScrollStateHolder, previous unchanged
   assertEquals(TEST_MAX_POSITION, timelineStateHolder.positionForNext());
   assertEquals(ANY_POSITION, timelineStateHolder.positionForPrevious());
   // assert that extra items were prepended in reverse order
   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));
   // assert observer's notifyChanged is called
   verify(mockObservable).notifyChanged();
 }