/** * @see RelationshipValidator#validate(Object,Errors) */ @Test public void validate_shouldFailIfStartDateIsInFuture() { Relationship relationship = new Relationship(1); Map<String, String> map = new HashMap<>(); MapBindingResult errors = new MapBindingResult(map, Relationship.class.getName()); Calendar cal = Calendar.getInstance(); cal.add(Calendar.YEAR, 1); Date nextYear = cal.getTime(); relationship.setStartDate(nextYear); new RelationshipValidator().validate(relationship, errors); Assert.assertTrue(errors.hasErrors()); }
/** * @see RelationshipValidator#validate(Object,Errors) */ @Test public void validate_shouldPassIfStartDateIsNotInFuture() { Relationship relationship = new Relationship(1); Map<String, String> map = new HashMap<>(); MapBindingResult errors = new MapBindingResult(map, Relationship.class.getName()); Calendar cal = Calendar.getInstance(); cal.add(Calendar.YEAR, -1); Date lastYear = cal.getTime(); relationship.setStartDate(lastYear); new RelationshipValidator().validate(relationship, errors); Assert.assertFalse(errors.hasErrors()); }
/** * @throws ParseException * @see RelationshipValidator#validate(Object,Errors) */ @Test public void validate_shouldFailIfEndDateIsBeforeStartDate() throws ParseException { Relationship relationship = new Relationship(1); relationship.setStartDate(Context.getDateFormat().parse("18/02/2012")); relationship.setEndDate(Context.getDateFormat().parse("18/02/2001")); Map<String, String> map = new HashMap<>(); MapBindingResult errors = new MapBindingResult(map, Relationship.class.getName()); new RelationshipValidator().validate(relationship, errors); Assert.assertEquals(true, errors.hasErrors()); }
/** * @see RelationshipValidator#validate(Object,Errors) */ @Test public void validate_shouldPassIfStartDateIsEmpty() { Map<String, String> map = new HashMap<>(); MapBindingResult errors = new MapBindingResult(map, Relationship.class.getName()); Relationship relationship = new Relationship(1); relationship.setStartDate(null); new RelationshipValidator().validate(relationship, errors); Assert.assertFalse(errors.hasErrors()); } }
/** * @throws ParseException * @see RelationshipValidator#validate(Object,Errors) */ @Test public void validate_shouldPassIfEndDateIsAfterStartDate() throws ParseException { Relationship relationship = new Relationship(1); relationship.setStartDate(Context.getDateFormat().parse("18/02/2012")); relationship.setEndDate(Context.getDateFormat().parse("18/03/2012")); Map<String, String> map = new HashMap<>(); MapBindingResult errors = new MapBindingResult(map, Relationship.class.getName()); new RelationshipValidator().validate(relationship, errors); Assert.assertFalse(errors.hasErrors()); }
r.setPersonB(personB); r.setRelationshipType(rt); r.setStartDate(df.parse("1980-01-01")); r.setEndDate(df.parse("2010-01-01")); personService.saveRelationship(r); r.setPersonB(personB); r.setRelationshipType(rt); r.setStartDate(df.parse("1990-01-01")); r.setEndDate(df.parse("2010-01-01")); personService.saveRelationship(r); r.setPersonB(personB); r.setRelationshipType(rt); r.setStartDate(df.parse("1980-01-01")); r.setEndDate(df.parse("1990-01-01")); personService.saveRelationship(r); r.setPersonB(personB); r.setRelationshipType(rt); r.setStartDate(df.parse("1980-01-01")); personService.saveRelationship(r); rels.add(r); r.setPersonB(personB); r.setRelationshipType(rt); r.setStartDate(df.parse("1990-01-01")); personService.saveRelationship(r); rels.add(r);