DateConstraint extends Constraint<Object> { @NonNull @Override public Set<Violation> validate() throws UnsupportedException { final Set<Violation> violations = new HashSet<>(); final String value = getStringFromObject(object, propertyName); if (null == value || !isValid(value)) { violations.add(new Violation(propertyName, object, message, ERROR_CODE_DATE_INVALID)); } return violations; } DateConstraint(@NonNull Object object, @NonNull String propertyName);  DateConstraint(@NonNull Object object, @NonNull String propertyName, @NonNull String format); @NonNull @Override Set<Violation> validate(); void setMessage(String message); void setFormat(String format); static final String ERROR_CODE_DATE_INVALID; }
@Test public void isNotValid() throws Exception { assertNotEmpty("is not valid with String", new DateConstraint(NOT_VALID, PROPERTY_NAME).validate()); assertNotEmpty("is not valid with EditText", new DateConstraint(generateEditText(NOT_VALID), PROPERTY_NAME).validate()); assertNotEmpty("is not valid with Spinner", new DateConstraint(generateSpinner(NOT_VALID), PROPERTY_NAME).validate()); }