IsANCRegisteredWithinTwelveWeeksOfPregnancy implements IRule { @Override public boolean apply(SafeMap reportFields) { return !(parse(reportFields.get(SERVICE_PROVIDED_DATE)).minusDays(NUMBER_OF_DAYS_IN_12_WEEKS) .isAfter(parse(reportFields.get(REFERENCE_DATE)))); }  @Override boolean apply(SafeMap reportFields); static final int NUMBER_OF_DAYS_IN_12_WEEKS; }
@Test public void shouldReturnTrueWhenANCIsRegisteredWithin12Weeks() { Map<String, String> reportData = create("serviceProvidedDate", "2012-10-23") .put("referenceDate", "2012-10-01") .map(); boolean didRuleSucceed = rule.apply(new SafeMap(reportData)); assertTrue(didRuleSucceed); reportData = create("serviceProvidedDate", "2013-03-26") .put("referenceDate", "2013-01-01") .map(); didRuleSucceed = rule.apply(new SafeMap(reportData)); assertTrue(didRuleSucceed); }
@Test public void shouldReturnFalseWhenANCIsRegisteredAfter12Weeks() { Map<String, String> reportData = create("serviceProvidedDate", "2013-10-23") .put("referenceDate", "2012-10-01") .map(); boolean didRuleSucceed = rule.apply(new SafeMap(reportData)); assertFalse(didRuleSucceed); reportData = create("serviceProvidedDate", "2013-03-27") .put("referenceDate", "2013-01-01") .map(); didRuleSucceed = rule.apply(new SafeMap(reportData)); assertFalse(didRuleSucceed); }