### Question:
AlertValidator implements Validator { @Override public void validate(Object obj, Errors errors) { Alert alert = (Alert) obj; if (alert == null) { errors.rejectValue("alert", "error.general"); } else { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "text", "Alert.text.required"); ValidateUtil.validateFieldLengths(errors, obj.getClass(), "text"); } }  @Override boolean supports(Class<?> c); @Override void validate(Object obj, Errors errors);  }### Answer:
@Test public void shouldFailValidationIfAlertTextIsNull() { validator.validate(alert, errors); assertThatFieldTextHasError(); }
@Test public void shouldFailValidationIfAlertTextIsEmpty() { alert.setText(""); validator.validate(alert, errors); assertThatFieldTextHasError(); }
@Test public void shouldFailValidationIfAlertTextIsOnlyWhitespaces() { alert.setText(" "); validator.validate(alert, errors); assertThatFieldTextHasError(); }
@Test public void validate_shouldPassValidationIfAllRequiredValuesAreSet() { alert.setText("Alert Text"); validator.validate(alert, errors); Assert.assertFalse(errors.hasErrors()); }
@Test public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() { alert .setText("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text"); validator.validate(alert, errors); assertThatFieldTextHasError(); }