@Test public void testPrevious_doesNotUpdatePositionAtEndOfTimeline() { final Timeline<TestItem> fakeEndTimeline = new FakeItemTimeline(ZERO_ITEMS, ANY_POSITION, ANY_POSITION); delegate = new TimelineDelegate<>(fakeEndTimeline); delegate.timelineStateHolder.setPreviousCursor(new TimelineCursor(null, null)); delegate.previous(); assertNull(delegate.timelineStateHolder.positionForPrevious()); }
@Test public void testPrevious_updatesPositionForPrevious() { final Timeline<TestItem> fakeTimeline = new FakeItemTimeline(NUM_ITEMS, TEST_MIN_POSITION, ANY_POSITION); delegate = new TimelineDelegate<>(fakeTimeline); assertNull(delegate.timelineStateHolder.positionForPrevious()); delegate.previous(); assertEquals(TEST_MIN_POSITION, delegate.timelineStateHolder.positionForPrevious()); }
@Test public void testPrevious_addsItems() { final Timeline<TestItem> fakeTimeline = new FakeItemTimeline(NUM_ITEMS, ANY_POSITION, ANY_POSITION); delegate = new TimelineDelegate<>(fakeTimeline, mockObservable, null); delegate.refresh(null); // refresh loads latest items (notifyChange) delegate.previous(); // assert items are added and notifyChanges is called again assertEquals(2 * NUM_ITEMS, delegate.getCount()); verify(mockObservable, times(2)).notifyChanged(); }
@Test public void testPrevious_doesNotAddItemsAtEndOfTimeline() { // when a Timeline successfully returns an empty set of items, its end has been reached LinkedList<TestItem> initialItems = new LinkedList<>(); final int INITIAL_COUNT = 5; initialItems = TestItem.populateList(initialItems, INITIAL_COUNT); final Timeline<TestItem> fakeEndTimeline = new FakeItemTimeline(ZERO_ITEMS, ANY_POSITION, ANY_POSITION); delegate = new TimelineDelegate<>(fakeEndTimeline, mockObservable, initialItems); delegate.previous(); // assert no items are added and notifyChanged is not called assertEquals(INITIAL_COUNT, delegate.getCount()); verifyZeroInteractions(mockObservable); }