IsPersonSevereAnaemicRule implements IRule { @Override public boolean apply(SafeMap reportFields) { double hbLevel = DoubleUtil.tryParse(reportFields.get(HB_LEVEL_FIELD), HB_LEVEL_HIGHER_THRESHOLD_FOR_ANAEMIA + 1); return hbLevel < HB_LEVEL_LOWER_THRESHOLD_FOR_ANAEMIA; }  @Override boolean apply(SafeMap reportFields); static final Double HB_LEVEL_HIGHER_THRESHOLD_FOR_ANAEMIA; static final Double HB_LEVEL_LOWER_THRESHOLD_FOR_ANAEMIA; }
@Test public void shouldReturnTrueWhenHBLevelIsLessThanSeven() throws Exception { boolean rulePassed = rule.apply(new SafeMap(create("hbLevel", "6.9").map())); assertTrue(rulePassed); rulePassed = rule.apply(new SafeMap(create("hbLevel", "2").map())); assertTrue(rulePassed); }
@Test public void shouldReturnFalseWhenHBLevelIsGreaterThanOrEqualToSeven() throws Exception { boolean rulePassed = rule.apply(new SafeMap(create("hbLevel", "7").map())); assertFalse(rulePassed); rulePassed = rule.apply(new SafeMap(create("hbLevel", "11").map())); assertFalse(rulePassed); }