public static <T> void checkNotNullAndNumberOfElements(
      Collection<T> collection, int numElements, String argName) {
    checkNotNull(collection, argName);
    checkArgument(
        collection.size() == numElements,
        "Number of elements in '%s' must be exactly %s, %s given.",
        argName,
        numElements,
        collection.size()
    );
  }
@Test
  public void testCheckNotNullAndNumberOfElements() throws Exception {
    // Should not throw.
    Validate.checkNotNullAndNumberOfElements(Arrays.asList(1, 2, 3), 3, "arg");

    // Verify it throws.

    intercept(IllegalArgumentException.class, "'arg' must not be null",
        () -> Validate.checkNotNullAndNumberOfElements(null, 3, "arg"));

    // Verify it throws.
    ExceptionAsserts.assertThrows(
        IllegalArgumentException.class,
        "Number of elements in 'arg' must be exactly 3, 2 given.",
        () -> Validate.checkNotNullAndNumberOfElements(Arrays.asList(1, 2), 3,
            "arg")
    );
  }