IsPNCVisitFirstBetween2And14DaysOfDeliveryRule implements IRule { @Override public boolean apply(SafeMap reportFields) { String pncVisitDate = reportFields.get(VISIT_DATE_FIELD_NAME); String pncVisitDates = reportFields.get(VISIT_DATES_FIELD_NAME); LocalDate dateOfBirth = LocalDate.parse(reportFields.get(REFERENCE_DATE)); if (pncVisitDates != null) { String[] pncVisitDatesList = pncVisitDates.split(" "); for (String date : pncVisitDatesList) { if (LocalDate.parse(date).isBefore(dateOfBirth.plusDays(3))) { continue; } return (date.equalsIgnoreCase(pncVisitDate)); } } return false; }  @Override boolean apply(SafeMap reportFields);  }
@Test public void shouldReturnTrueIfThePNCVisitIsTheFirstVisitBetween2And14DaysOfDelivery() { SafeMap safeMap = new SafeMap(); safeMap.put("pncVisitDate", "2012-01-04"); safeMap.put("pncVisitDates", "2012-01-04"); safeMap.put("referenceDate", "2012-01-01"); boolean didRuleApply = rule.apply(safeMap); assertTrue(didRuleApply); safeMap = new SafeMap(); safeMap.put("pncVisitDate", "2012-01-04"); safeMap.put("pncVisitDates", "2012-01-01 2012-01-03 2012-01-04"); safeMap.put("referenceDate", "2012-01-01"); didRuleApply = rule.apply(safeMap); assertTrue(didRuleApply); }
@Test public void shouldReturnFalseIfThePNCVisitIsNotTheFirstVisitBetween2And14DaysOfDelivery() { SafeMap safeMap = new SafeMap(); safeMap.put("pncVisitDate", "2012-01-04"); safeMap.put("pncVisitDates", null); safeMap.put("referenceDate", "2012-01-01"); boolean didRuleApply = rule.apply(safeMap); assertFalse(didRuleApply); safeMap.put("pncVisitDate", "2012-01-05"); safeMap.put("pncVisitDates", "2012-01-01 2012-01-03 2012-01-04 2012-01-05"); safeMap.put("referenceDate", "2012-01-01"); didRuleApply = rule.apply(safeMap); assertFalse(didRuleApply); }