### Question:
CollectionUtils { public static <T> List<List<T>> partition(final List<T> items, final int size) { if (items == null) { throw new IllegalArgumentException("Items must not be null"); } if (size < 0) { throw new IllegalArgumentException("Size must be more than 0"); } final int maxIndex = items.size() < size ? items.size() : size; final List<List<T>> lists = new ArrayList<>(); lists.add(items.subList(0, maxIndex)); final List<T> remainingItems = items.subList(maxIndex, items.size()); if (remainingItems.size() > 0) { final List<List<T>> remainingLists = partition(remainingItems, size); lists.addAll(remainingLists); } return lists; }  static List<List<T>> partition(final List<T> items, final int size);  }### Answer:
@Test public void shouldPartionList_withItemLengthEqualToSize() throws Exception { final List<Integer> items = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); final int size = 10; final List<List<Integer>> expected = Arrays.asList(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); final List<List<Integer>> actual = CollectionUtils.partition(items, size); Assert.assertEquals(actual, expected); }
@Test public void shouldPartionList_withItemLengthHalfTheSize() throws Exception { final List<Integer> items = Arrays.asList(1, 2, 3, 4, 5); final int size = 10; final List<List<Integer>> expected = Arrays.asList(Arrays.asList(1, 2, 3, 4, 5)); final List<List<Integer>> actual = CollectionUtils.partition(items, size); Assert.assertEquals(actual, expected); }
@Test public void shouldPartionList_withItemLengthDoubleTheSize() throws Exception { final List<Integer> items = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); final int size = 5; final List<List<Integer>> expected = Arrays.asList(Arrays.asList(1, 2, 3, 4, 5), Arrays.asList(6, 7, 8, 9, 10)); final List<List<Integer>> actual = CollectionUtils.partition(items, size); Assert.assertEquals(actual, expected); }
@Test public void shouldPartionList_withItemLengthMoreThanDoubleTheSize() throws Exception { final List<Integer> items = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11); final int size = 5; final List<List<Integer>> expected = Arrays.asList(Arrays.asList(1, 2, 3, 4, 5), Arrays.asList(6, 7, 8, 9, 10), Arrays.asList(11)); final List<List<Integer>> actual = CollectionUtils.partition(items, size); Assert.assertEquals(actual, expected); }
@Test public void shouldPartionList_withItemLengthOfZero() throws Exception { final List<Integer> items = Arrays.asList(); final int size = 5; final List<List<Integer>> expected = Arrays.asList(Arrays.asList()); final List<List<Integer>> actual = CollectionUtils.partition(items, size); Assert.assertEquals(actual, expected); }
@Test(expected = IllegalArgumentException.class) public void shouldNotPartionList_withNegativeSize() throws Exception { final List<Integer> items = Arrays.asList(1, 2, 3, 4, 5); final int size = -1; CollectionUtils.partition(items, size); }
@Test(expected = IllegalArgumentException.class) public void shouldNotPartionList_withNullItems() throws Exception { final List<Integer> items = null; final int size = 10; CollectionUtils.partition(items, size); }