### Question:
CollectionUtil { public static <T> Collection<List<T>> split(Collection<T> collection, final int subsetSize) { if(collection == null || subsetSize < 1) return null; AtomicInteger subsetCounter = new AtomicInteger(); return collection.stream().collect(Collectors.groupingBy(it -> subsetCounter.getAndIncrement() / subsetSize)).values(); }  static Collection<List<T>> split(Collection<T> collection, final int subsetSize);  }### Answer:
@Test(dataProvider = "splitProvider") public void testSplit(List<Integer> list, final int SUBSET_SIZE) { final int EXPECTED_SET_COUNT = (int)Math.ceil((double)list.size() / (double)SUBSET_SIZE); Collection<List<Integer>> splitCollection = CollectionUtil.split(list, SUBSET_SIZE); Assert.assertEquals(splitCollection.size(), EXPECTED_SET_COUNT); }
@Test(dataProvider = "splitInvalidInputProvider") public void testSplitInvalidInput(List<Integer> list, final int SUBSET_SIZE) { Assert.assertNull(CollectionUtil.split(list, SUBSET_SIZE)); }