public static <T> List<List<T>> partition(Collection<T> values, int partitionSize) {
        if (values == null) {
            return null;
        } else if (values.isEmpty()) {
            return Collections.emptyList();
        }

        List<T> valuesList;
        if (values instanceof List) {
            valuesList = (List<T>) values;
        } else {
            valuesList = new ArrayList<>(values);
        }

        int valuesSize = values.size();

        if (valuesSize <= partitionSize) {
            return Collections.singletonList(valuesList);
        }

        List<List<T>> safeValuesList = new ArrayList<>();

        consumePartitions(values, partitionSize, safeValuesList::add);

        return safeValuesList;
    }
@Test
    void partitionNullCollection() {
        assertThat(CollectionUtil.partition(null, 10)).isNull();
    }