IsChildBelowFiveYearsRule implements IRule { @Override public boolean apply(SafeMap reportFields) { LocalDate dateOfBirth = LocalDate.parse(reportFields.get(DATE_OF_BIRTH)); LocalDate reportDate = LocalDate.parse(reportFields.get(REPORT_CHILD_DISEASE_DATE)); return dateOfBirth.plusYears(5).isAfter(reportDate); }  @Override boolean apply(SafeMap reportFields);  }
@Test public void shouldReturnFalseWhenChildIsNotBelowFiveYears() { Map<String, String> reportData = create("reportChildDiseaseDate", "2012-01-01") .put("dateOfBirth", "2002-01-01") .map(); boolean didRuleSucceed = rule.apply(new SafeMap(reportData)); assertFalse(didRuleSucceed); reportData = create("reportChildDiseaseDate", "2012-01-01") .put("dateOfBirth", "2007-01-01") .map(); didRuleSucceed = rule.apply(new SafeMap(reportData)); assertFalse(didRuleSucceed); }
@Test public void shouldReturnTrueWhenChildIsBelowFiveYears() { Map<String, String> reportData = create("reportChildDiseaseDate", "2011-12-30") .put("dateOfBirth", "2007-01-01") .map(); boolean didRuleSucceed = rule.apply(new SafeMap(reportData)); assertTrue(didRuleSucceed); }