PoliciesValidator implements ConstraintValidator<Policies, Object> { @Override public boolean isValid(Object value, ConstraintValidatorContext context) { if (value == null) { return true; } else if (value instanceof Collection) { return isValidCollection((Collection<?>) value); } else if (value instanceof Map) { return ((Map<?, ?>) value).values().stream().allMatch(v -> isValid(v, context)); } else { return false; } }  @Override void initialize(Policies constraintAnnotation); @Override boolean isValid(Object value, ConstraintValidatorContext context);  }
@Test public void testInvalidWithNonMatchingObject() { boolean valid = target.isValid(new Object(), constraintValidatorContext); assertThat(valid).isFalse(); }