AbstractLazyDataView extends AbstractDataView<T> implements LazyDataView<T> { @Override public T getItem(int index) { return getDataCommunicator().getItem(index); } AbstractLazyDataView(DataCommunicator<T> dataCommunicator,
            Component component); @Override T getItem(int index); @SuppressWarnings("unchecked") @Override Stream<T> getItems(); @Override void setItemCountEstimate(int itemCountEstimate); @Override int getItemCountEstimate(); @Override void setItemCountEstimateIncrease(int itemCountEstimateIncrease); @Override int getItemCountEstimateIncrease(); @Override void setItemCountFromDataProvider(); @Override void setItemCountUnknown();  }
@Test public void getItem_correctIndex_itemObtained() { dataCommunicator.setRequestedRange(0, 50); dataCommunicator.setDataProvider(DataProvider.fromCallbacks(query -> { query.getOffset(); query.getLimit(); return Stream.of("foo", "bar", "baz"); }, query -> 3), null); fakeClientCommunication(); Assert.assertEquals("Invalid item on index 1", "bar", dataView.getItem(1)); }
@Test public void getItem_negativeIndex_throws() { exceptionRule.expect(IndexOutOfBoundsException.class); exceptionRule.expectMessage("Index must be non-negative"); dataCommunicator.setRequestedRange(0, 50); dataCommunicator.setDataProvider(DataProvider.fromCallbacks(query -> { query.getOffset(); query.getLimit(); return Stream.of("foo", "bar", "baz"); }, query -> 3), null); fakeClientCommunication(); dataView.getItem(-1); }
@Test public void getItem_emptyData_throws() { exceptionRule.expect(IndexOutOfBoundsException.class); exceptionRule.expectMessage("Requested index 0 on empty data."); dataCommunicator.setRequestedRange(0, 50); dataCommunicator.setDataProvider(DataProvider.fromCallbacks(query -> { query.getOffset(); query.getLimit(); return Stream.empty(); }, query -> 0), null); fakeClientCommunication(); dataView.getItem(0); }
@Test public void getItem_outsideOfRange_throws() { exceptionRule.expect(IndexOutOfBoundsException.class); exceptionRule.expectMessage( "Given index 3 is outside of the accepted range '0 - 2'"); dataCommunicator.setRequestedRange(0, 50); dataCommunicator.setDataProvider(DataProvider.fromCallbacks(query -> { query.getOffset(); query.getLimit(); return Stream.of("foo", "bar", "baz"); }, query -> 3), null); fakeClientCommunication(); dataView.getItem(3); }