IsChildMoreThan5YearsOldRule implements IRule { @Override public boolean apply(SafeMap reportFields) { LocalDate dateOfBirth = LocalDate.parse(reportFields.get(DATE_OF_BIRTH)); LocalDate serviceProvidedDate = LocalDate.parse(reportFields.get(SERVICE_PROVIDED_DATE)); return dateOfBirth.plusYears(5).isBefore(serviceProvidedDate); }  @Override boolean apply(SafeMap reportFields);  }
@Test public void shouldReturnTrueIfAgeIsMoreThan5Years() { SafeMap safeMap = new SafeMap(); safeMap.put("entityId", "child id 1"); safeMap.put("serviceProvidedDate", "2012-03-01"); safeMap.put("dateOfBirth", "2007-01-01"); boolean didRuleApply = rule.apply(safeMap); assertTrue(didRuleApply); }
@Test public void shouldReturnFalseIfAgeIsNotMoreThan5Years() { SafeMap safeMap = new SafeMap(); safeMap.put("entityId", "child id 1"); safeMap.put("serviceProvidedDate", "2012-03-01"); safeMap.put("dateOfBirth", "2011-01-01"); boolean didRuleApply = rule.apply(safeMap); assertFalse(didRuleApply); }