PartitionedDataProvider implements ISortableDataProvider<List<T>, S> { @Override public long size() { if (partitionSize > 0) { final double valuesCount = (double) provider.size(); final double partitionsCount = Math.ceil(valuesCount / partitionSize); return (long) partitionsCount; } else { return 1; } } PartitionedDataProvider(ISortableDataProvider<T, S> provider, int partitionSize); @Override Iterator<? extends List<T>> iterator(long first, long count); @Override long size(); @Override IModel<List<T>> model(List<T> object); @Override void detach(); @Override ISortState<S> getSortState();  }
@Test public void testSizeNoPartitions() { final ISortableDataProvider provider = context.mock(ISortableDataProvider.class); final PartitionedDataProvider instance = new PartitionedDataProvider(provider, 0); context.checking(new Expectations() { { never(provider).size(); } }); assertEquals(1, instance.size()); }
@Test public void testSizePartitions() { final ISortableDataProvider provider = context.mock(ISortableDataProvider.class); final PartitionedDataProvider instance = new PartitionedDataProvider(provider, 2); context.checking(new Expectations() { { oneOf(provider).size(); will(returnValue(9L)); } }); assertEquals("ceil(9/2) = 5", 5, instance.size()); }