@Test public void testValidate02() { SearchTourFormDateValidator validator = new SearchTourFormDateValidator(); SearchTourForm criteria = new SearchTourForm(); BindingResult result = new DirectFieldBindingResult(criteria, "SearchTourcriteria"); criteria.setDepDay(31); criteria.setDepMonth(2); criteria.setDepYear(2000); validator.validate(criteria, result); assertThat(result.hasErrors(), is(true)); FieldError error = result.getFieldError("depYear"); if (error != null) { assertThat(error.getCode(), is("IncorrectDate.inputdate")); assertThat(error.getDefaultMessage(), is( "Incorrect date was entered.")); } else { fail("error"); } }
@Override public void validate(Object target, Errors errors) { SearchTourForm searchTourForm = (SearchTourForm) target; try { new DateTime(searchTourForm.getDepYear(), searchTourForm .getDepMonth(), searchTourForm.getDepDay(), 0, 0).toDate(); } catch (IllegalFieldValueException e) { errors.rejectValue("depYear", "IncorrectDate.inputdate", "Incorrect date was entered."); } }
SearchTourFormDateValidator implements Validator { @Override public void validate(Object target, Errors errors) { SearchTourForm searchTourForm = (SearchTourForm) target; try { new DateTime(searchTourForm.getDepYear(), searchTourForm .getDepMonth(), searchTourForm.getDepDay(), 0, 0).toDate(); } catch (IllegalFieldValueException e) { errors.rejectValue("depYear", "IncorrectDate.inputdate", "Incorrect date was entered."); } } }
SearchTourFormDateValidator implements Validator { @Override public void validate(Object target, Errors errors) { SearchTourForm searchTourForm = (SearchTourForm) target; try { new DateTime(searchTourForm.getDepYear(), searchTourForm .getDepMonth(), searchTourForm.getDepDay(), 0, 0).toDate(); } catch (IllegalFieldValueException e) { errors.rejectValue("depYear", "IncorrectDate.inputdate", "Incorrect date was entered."); } }  }
SearchTourFormDateValidator implements Validator { @Override public void validate(Object target, Errors errors) { SearchTourForm searchTourForm = (SearchTourForm) target; try { new DateTime(searchTourForm.getDepYear(), searchTourForm .getDepMonth(), searchTourForm.getDepDay(), 0, 0).toDate(); } catch (IllegalFieldValueException e) { errors.rejectValue("depYear", "IncorrectDate.inputdate", "Incorrect date was entered."); } }  @Override boolean supports(Class<?> clazz); @Override void validate(Object target, Errors errors); }
SearchTourFormDateValidator implements Validator { @Override public void validate(Object target, Errors errors) { SearchTourForm searchTourForm = (SearchTourForm) target; try { new DateTime(searchTourForm.getDepYear(), searchTourForm .getDepMonth(), searchTourForm.getDepDay(), 0, 0).toDate(); } catch (IllegalFieldValueException e) { errors.rejectValue("depYear", "IncorrectDate.inputdate", "Incorrect date was entered."); } }  @Override boolean supports(Class<?> clazz); @Override void validate(Object target, Errors errors);  }