ChunkingSpliterator implements Spliterator<String> { @Override public long estimateSize() { final int size = minChunkSize + (maxChunkSize - minChunkSize) / 2; return string.length() / size + Integer.signum(string.length() % size); } ChunkingSpliterator(final String string, final int minChunkSize, final int maxChunkSize); @Override boolean tryAdvance(final Consumer<? super String> action); @Override Spliterator<String> trySplit(); @Override long estimateSize(); @Override int characteristics();  }
@Test void shouldEstimateSizeWithoutTrailingPart() { assertThat(new ChunkingSpliterator("Hello", 5, 5).estimateSize(), is(1L)); }
@Test void shouldEstimateSizeWithTrailingPart() { assertThat(new ChunkingSpliterator("Hello World", 5, 5).estimateSize(), is(3L)); }