MoreThan100IFATabletsAreProvidedRule implements IRule { @Override public boolean apply(SafeMap reportFields) { int totalNumberOfIFATabletsGiven = IntegerUtil.tryParse(reportFields.get(AllConstants.IFAFields.TOTAL_NUMBER_OF_IFA_TABLETS_GIVEN), 0); int numberOfIFATabletsGivenThisTime = IntegerUtil.tryParse(reportFields.get(AllConstants.IFAFields.NUMBER_OF_IFA_TABLETS_GIVEN), 0); return totalNumberOfIFATabletsGiven >= 100 && totalNumberOfIFATabletsGiven - numberOfIFATabletsGivenThisTime < 100; }  @Override boolean apply(SafeMap reportFields);  }
@Test public void shouldReturnTrueWhenMoreThan100IFATabletsAreProvidedSoFar() throws Exception { Map<String, String> reportFields = create("totalNumberOfIFATabletsGiven", "100") .put("numberOfIFATabletsGiven", "60") .map(); assertTrue(rule.apply(new SafeMap(reportFields))); }
@Test public void shouldReturnFalseWhenLessThan100IFATabletsAreProvidedSoFar() throws Exception { Map<String, String> reportFields = create("totalNumberOfIFATabletsGiven", "99") .put("numberOfIFATabletsGiven", "60") .map(); assertFalse(rule.apply(new SafeMap(reportFields))); }
@Test public void shouldReturnFalseWhenMoreThan100IFATabletsAreProvidedSoFarButThisIsNotTheFirstTime() throws Exception { Map<String, String> reportFields = create("totalNumberOfIFATabletsGiven", "120") .put("numberOfIFATabletsGiven", "20") .map(); assertFalse(rule.apply(new SafeMap(reportFields))); }