FieldUtil { @SafeVarargs public static ValidationResult validateRequiredFields(final Pair<String, Object>... fields) { final ValidationResult validationResult = new ValidationResult(); for (final Pair field : fields) { if (null == field.getSecond()) { validationResult.addError(field.getFirst() + " is required."); } } return validationResult; } private  FieldUtil(); @SafeVarargs static ValidationResult validateRequiredFields(final Pair<String, Object>... fields); @SafeVarargs static ValidationResult validateRequiredFields(final Tuple3<String, Object, Predicate>... fields);  }
@Test public void testNullField() { final Pair nullPair = new Pair("Test", null); final ValidationResult validationResult = FieldUtil.validateRequiredFields(nullPair); final Set<String> expected = new LinkedHashSet<>(); expected.add("Test is required."); assertEquals(expected, validationResult.getErrors()); }
@Test public void testNotNullField() { final Pair nonNullPair = new Pair("Test", "Test"); final ValidationResult validationResult = FieldUtil.validateRequiredFields(nonNullPair); final Set<String> expected = new LinkedHashSet<>(); assertEquals(expected, validationResult.getErrors()); }