IsChildBelowThreeYearsRule implements IRule { @Override public boolean apply(SafeMap reportFields) { LocalDate dateOfBirth = LocalDate.parse(reportFields.get(DATE_OF_BIRTH)); LocalDate reportDate = LocalDate.parse(reportFields.get(VITAMIN_A_DATE)); return dateOfBirth.plusYears(3).isAfter(reportDate); }  @Override boolean apply(SafeMap reportFields);  }
@Test public void shouldReturnFalseWhenChildIsNotBelowThreeYears() { Map<String, String> reportData = create("vitaminADate", "2012-01-01") .put("dateOfBirth", "2002-01-01") .map(); boolean didRuleSucceed = rule.apply(new SafeMap(reportData)); assertFalse(didRuleSucceed); reportData = create("vitaminADate", "2012-01-01") .put("dateOfBirth", "2007-01-01") .map(); didRuleSucceed = rule.apply(new SafeMap(reportData)); assertFalse(didRuleSucceed); }
@Test public void shouldReturnTrueWhenChildIsBelowThreeYears() { Map<String, String> reportData = create("vitaminADate", "2010-12-30") .put("dateOfBirth", "2008-01-01") .map(); boolean didRuleSucceed = rule.apply(new SafeMap(reportData)); assertTrue(didRuleSucceed); }