public static <E> List<List<E>> batches(List<E> list, int batchSize) {
    return batchesAsStream(list, batchSize).collect(Collectors.toList());
  }
@Test
  void getBatchesFromList() {
    assertThrows(IllegalArgumentException.class, () -> {
      batches(Collections.emptyList(), -1);
    });

    assertThrows(IllegalArgumentException.class, () -> {
      batches(Collections.emptyList(), 0);
    });

    assertEquals(Collections.emptyList(), batches(Collections.emptyList(), 1));

    List<List<Integer>> intsBatches1 = batches(Arrays.asList(1, 2, 3, 4, 5, 6), 3);
    assertEquals(2, intsBatches1.size());
    assertEquals(Arrays.asList(1, 2, 3), intsBatches1.get(0));
    assertEquals(Arrays.asList(4, 5, 6), intsBatches1.get(1));

    List<List<Integer>> intsBatches2 = batches(Arrays.asList(1, 2, 3, 4, 5, 6), 5);
    assertEquals(2, intsBatches2.size());
    assertEquals(Arrays.asList(1, 2, 3, 4, 5), intsBatches2.get(0));
    assertEquals(Collections.singletonList(6), intsBatches2.get(1));
  }