### Question:
CollectionUtils { static <T> List<List<T>> multiplyWithOtherElements(Collection<T> allValues, Collection<? extends Collection<T>> collectionValues) { int collectionValueSize = CollectionUtils.getElementAtPosition(collectionValues, 0).size(); for (Collection<T> collectionValue : collectionValues) { Assert.isTrue(allValues.contains(collectionValue), () -> "Expected " + collectionValue + " to be part of " + allValues); Assert.isTrue(collectionValue.size() == collectionValueSize, () -> "Expected " + collectionValue + " to be size " + collectionValueSize); } List<List<T>> result = new ArrayList<>(collectionValueSize); for (int i = 0; i < collectionValueSize; i++) { List<T> newValues = new ArrayList(); for (Object value : allValues) { if (collectionValues.contains(value)) { newValues.add(CollectionUtils.getElementAtPosition((Collection<T>) value, i)); } else { newValues.add((T) value); } } result.add(newValues); } return result; } private  CollectionUtils(); static T getSingleElement(Iterable<T> iterable); static T getLastElement(List<T> list); static T getSingleElement(Iterable<T> iterable, Supplier<? extends RuntimeException> exceptionSupplier); static T removeAll(T map, Collection<K> keysToRemove);  }### Answer:
@Test void testMultiplyWithOtherElements() throws Exception { List<Object> values = Arrays.asList(1, 2); List<Object> collection = Arrays.asList("abc", "def", values); assertThat(CollectionUtils.multiplyWithOtherElements(collection, Arrays.asList(values))) .containsExactly( Arrays.asList("abc", "def", 1), Arrays.asList("abc", "def", 2) ); assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> CollectionUtils.multiplyWithOtherElements(collection, Arrays.asList(Arrays.asList(1, 2, 3)))) .withMessage("Expected [1, 2, 3] to be part of [abc, def, [1, 2]]"); List<Object> first = Arrays.asList("abc", "xyz", Arrays.asList("L", "M", "S"), Arrays.asList("red", "green", "blue")); List<List<Object>> second = Arrays.asList(Arrays.asList("L", "M", "S"), Arrays.asList("red", "green", "blue")); assertThat(CollectionUtils.multiplyWithOtherElements(first, second)) .containsExactly( Arrays.asList("abc", "xyz", "L", "red"), Arrays.asList("abc", "xyz", "M", "green"), Arrays.asList("abc", "xyz", "S", "blue") ); }
@Test void testMultiplyWithOtherElementsWrongSize() throws Exception { List<Object> smallValues = Arrays.asList(1, 2); List<Object> bigValues = Arrays.asList(1, 2, 3); List<Object> collection = Arrays.asList("abc", "def", smallValues, bigValues); assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> CollectionUtils.multiplyWithOtherElements(collection, Arrays.asList(smallValues, bigValues))) .withMessage("Expected [1, 2, 3] to be size 2"); }