IsChildLessThanOneYearOldRule implements IRule { @Override public boolean apply(SafeMap reportFields) { LocalDate dateOfBirth = LocalDate.parse(reportFields.get(DATE_OF_BIRTH)); if (isBlank(reportFields.get(SERVICE_PROVIDED_DATE))) return false; LocalDate serviceProvidedDate = LocalDate.parse(reportFields.get(SERVICE_PROVIDED_DATE)); return dateOfBirth.plusYears(1).isAfter(serviceProvidedDate); }  @Override boolean apply(SafeMap reportFields);  }
@Test public void shouldReturnTrueIfAgeIsLessThanOneYear() { SafeMap safeMap = new SafeMap(); safeMap.put("entityId", "child id 1"); safeMap.put("serviceProvidedDate", "2012-03-01"); safeMap.put("dateOfBirth", "2012-01-01"); boolean didRuleApply = rule.apply(safeMap); assertTrue(didRuleApply); }
@Test public void shouldReturnFalseIfAgeIsNotLessThanOneYear() { 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); }
@Test public void shouldReturnFalseIfServiceProvidedDateIsBlank() { SafeMap safeMap = new SafeMap(); safeMap.put("entityId", "child id 1"); safeMap.put("serviceProvidedDate", ""); safeMap.put("dateOfBirth", "2011-01-01"); boolean didRuleApply = rule.apply(safeMap); assertFalse(didRuleApply); }