IsChildLessThanFourWeeksOldRule implements IRule { @Override public boolean apply(SafeMap reportFields) { LocalDate dateOfBirth = LocalDate.parse(reportFields.get(DATE_OF_BIRTH)); String serviceProvidedDate = reportFields.get(SERVICE_PROVIDED_DATE); return serviceProvidedDate != null ? dateOfBirth.plusWeeks(4).isAfter(LocalDate.parse(serviceProvidedDate)) : false; }  @Override boolean apply(SafeMap reportFields);  }
@Test public void shouldReturnTrueIfAgeIsLessThanFourWeeks() { SafeMap safeMap = new SafeMap(); safeMap.put("entityId", "child id 1"); safeMap.put("serviceProvidedDate", "2012-01-28"); safeMap.put("dateOfBirth", "2012-01-01"); boolean didRuleApply = rule.apply(safeMap); assertTrue(didRuleApply); }
@Test public void shouldReturnFalseIfAgeIsNotLessThanFourWeeks() { SafeMap safeMap = new SafeMap(); safeMap.put("entityId", "child id 1"); safeMap.put("serviceProvidedDate", "2012-01-31"); safeMap.put("dateOfBirth", "2012-01-01"); boolean didRuleApply = rule.apply(safeMap); assertFalse(didRuleApply); safeMap.put("entityId", "child id 1"); safeMap.put("serviceProvidedDate", "2011-02-01"); safeMap.put("dateOfBirth", "2011-01-01"); didRuleApply = rule.apply(safeMap); assertFalse(didRuleApply); }
@Test public void shouldReturnFalseWhenAgeIsNotKnown() { SafeMap safeMap = new SafeMap(); safeMap.put("entityId", "child id 1"); safeMap.put("serviceProvidedDate", null); safeMap.put("dateOfBirth", "2012-01-01"); boolean didRuleApply = rule.apply(safeMap); assertFalse(didRuleApply); }