IsPNCVisitFirstRule implements IRule { @Override public boolean apply(SafeMap reportFields) { String pncVisitDate = reportFields.get(VISIT_DATE_FIELD_NAME); String pncVisitDates = reportFields.get(VISIT_DATES_FIELD_NAME); if(pncVisitDates != null){ String[] pncVisitDatesList = pncVisitDates.split(" "); return (pncVisitDatesList.length == 1 && pncVisitDatesList[0].equalsIgnoreCase(pncVisitDate)); } return false; }  @Override boolean apply(SafeMap reportFields);  }
@Test public void shouldReturnTrueIfThePNCVisitIsTheFirstOne() { SafeMap safeMap = new SafeMap(); safeMap.put("pncVisitDate", "2012-01-02"); safeMap.put("pncVisitDates", "2012-01-02"); boolean didRuleApply = rule.apply(safeMap); assertTrue(didRuleApply); }
@Test public void shouldReturnFalseIfThePNCVisitIsNotTheFirstOne() { SafeMap safeMap = new SafeMap(); safeMap.put("pncVisitDate", "2012-01-02"); safeMap.put("pncVisitDates", null); boolean didRuleApply = rule.apply(safeMap); assertFalse(didRuleApply); safeMap = new SafeMap(); safeMap.put("pncVisitDate", "2012-01-02"); safeMap.put("pncVisitDates", "2012-01-01 2012-01-02"); didRuleApply = rule.apply(safeMap); assertFalse(didRuleApply); }