### Question:
ParameterValidation { public static <T extends Collection<?>> T size(T instance, int expectedSize, String name) { nonNull(instance, name); if (instance.size() != expectedSize) { throw new IllegalArgumentException(String.format("`%s` must has size %d, but was %d", name, expectedSize, instance.size())); } return instance; } private  ParameterValidation(); static Duration validate(Duration duration, String name); static T nonNull(T instance, String name); static T nonNullNpe(T instance, String name); static long positive(long amount, String name); static int positive(int amount, String name); static int positiveOrZero(int amount, String name); static long positiveOrZero(long amount, String name); static T doesNotContainNull(T iterable, String name); static T[] doesNotContainNull(T[] array, String name); static T size(T instance, int expectedSize, String name); static final String SUPPLIER_PRODUCED_NULL; static final String MAPPER_RETURNED_NULL; }### Answer:
@Test public void testUnexpectedSize() { assertThatThrownBy(() -> { List<Integer> list = Collections.singletonList(1); ParameterValidation.size(list, 2, "list"); }).isInstanceOf(IllegalArgumentException.class).hasMessageContaining("list"); }
@Test public void testSizeWithNull() { assertThatThrownBy(() -> ParameterValidation.size(null, 2, "list")).isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("list"); }