IdBasedDataProvider extends BaseDataProvider<ID, T> { @Override public int size(Query<T, SerializablePredicate<T>> query) { SortOrders so = createSortOrder(query); FilterConverter<T> converter = getFilterConverter(); Filter filter = converter.convert(query.getFilter().orElse(null)); if (getMaxResults() != null) { Long count = getService().count(filter, false); if (showNotification && count >= getMaxResults()) { showNotification(getMessageService().getMessage("ocs.too.many.results", VaadinUtils.getLocale(), getMaxResults())); } } ids = getService().findIds(filter, getMaxResults(), so.toArray()); if (getAfterCountCompleted() != null) { getAfterCountCompleted().accept(ids.size()); } return ids.size(); } IdBasedDataProvider(BaseService<ID, T> service, EntityModel<T> entityModel, FetchJoinInformation... joins); @Override Stream<T> fetch(Query<T, SerializablePredicate<T>> query); @Override int getSize(); @Override int size(Query<T, SerializablePredicate<T>> query); @Override ID firstItemId(); @Override int indexOf(ID id);  }
@Test public void testNextItemId() { when(service.findIds(isNull(), isNull(), any())) .thenReturn(List.of(1, 2, 3)); provider = new IdBasedDataProvider<>(service, emf.getModel(TestEntity.class)); provider.size(query); provider.setCurrentlySelectedId(1); assertTrue(provider.hasNextItemId()); Integer next = provider.getNextItemId(); assertEquals(2, next.intValue()); assertTrue(provider.hasNextItemId()); next = provider.getNextItemId(); assertEquals(3, next.intValue()); assertFalse(provider.hasNextItemId()); }
@Test public void testPreviousItemId() { when(service.findIds(isNull(), isNull(), any())) .thenReturn(List.of(1, 2, 3)); provider = new IdBasedDataProvider<>(service, emf.getModel(TestEntity.class)); provider.size(query); provider.setCurrentlySelectedId(2); assertTrue(provider.hasPreviousItemId()); Integer next = provider.getPreviousItemId(); assertEquals(1, next.intValue()); assertFalse(provider.hasPreviousItemId()); }