IterableHelper { public static <E> void executeBatched(List<E> entries, int batchSize, Consumer<List<E>> batchFunction) { for (List<E> batch : ListUtils.partition(new ArrayList<>(entries), batchSize)) { if (CollectionUtils.isNotEmpty(batch)) { batchFunction.accept(batch); } } } private  IterableHelper(); static void executeBatched(List<E> entries, int batchSize, Consumer<List<E>> batchFunction);  }
@Test public void testExecuteBatched() { int batchSize = 3; assertExecuteCount(batchSize, 0); assertExecuteCount(batchSize, 1, 1); assertExecuteCount(batchSize, 1, 1, 2); assertExecuteCount(batchSize, 1, 1, 2, 3); assertExecuteCount(batchSize, 2, 1, 2, 3, 4); assertExecuteCount(batchSize, 2, 1, 2, 3, 4, 5); assertExecuteCount(batchSize, 2, 1, 2, 3, 4, 5, 6); assertExecuteCount(batchSize, 3, 1, 2, 3, 4, 5, 6, 7); assertExecuteCount(5, 2, 1, 2, 3, 4, 5, 6); }