ConstrainedValuesValidator implements PropertyValidator { @Override public ValidationResult validate(final Object raw) { final T value = valueParser.apply(raw); return allowedValuesSupplier.get().stream() .anyMatch(v -> v.equals(value)) ? new ValidationResult(true, Collections.emptyList()) : new ValidationResult(false, Collections.singletonList(NOT_ALLOWED_VALIDATION_KEY)); } ConstrainedValuesValidator(final Supplier<Collection<T>> allowedValuesSupplier,
                                      final Function<Object, T> valueParser); @Override ValidationResult validate(final Object raw);  }
@Test public void testValues() { assertResultSuccess(tested.validate("value1")); assertResultSuccess(tested.validate("value2")); assertResultSuccess(tested.validate("value3")); assertResultFailed(tested.validate("value4")); }