WomanIsDischargedWithin48HoursOfDeliveryRule implements IRule { @Override public boolean apply(SafeMap reportFields) { LocalDate deliveryDate = LocalDate.parse(reportFields.get(REFERENCE_DATE)); LocalDate dischargeDate = LocalDate.parse(reportFields.get(AllConstants.PNCVisitFormFields.DISCHARGE_DATE)); return dischargeDate.equals(deliveryDate) || dischargeDate.equals(deliveryDate.plusDays(1)) || dischargeDate.equals(deliveryDate.plusDays(2)); }  @Override boolean apply(SafeMap reportFields);  }
@Test public void shouldReturnTrueWhenWomanIsDischargedWithin48HoursOfDelivery() throws Exception { LocalDate deliveryDate = LocalDate.parse("2013-01-01"); Map<String, String> reportFields = create("referenceDate", deliveryDate.toString()) .put("dischargeDate", deliveryDate.toString()) .map(); assertTrue(rule.apply(new SafeMap(reportFields))); reportFields = create("referenceDate", deliveryDate.toString()) .put("dischargeDate", deliveryDate.plusDays(1).toString()) .map(); assertTrue(rule.apply(new SafeMap(reportFields))); reportFields = create("referenceDate", deliveryDate.toString()) .put("dischargeDate", deliveryDate.plusDays(2).toString()) .map(); assertTrue(rule.apply(new SafeMap(reportFields))); }
@Test public void shouldReturnFalseWhenWomanIsDischargedLaterThen48HoursOfDelivery() throws Exception { LocalDate deliveryDate = LocalDate.parse("2013-01-01"); Map<String, String> reportFields = create("referenceDate", deliveryDate.toString()) .put("dischargeDate", deliveryDate.plusDays(3).toString()) .map(); assertFalse(rule.apply(new SafeMap(reportFields))); }