### Question:
DefaultRulesEngine extends AbstractRulesEngine { @Override public Map<Rule, Boolean> check(Rules rules, Facts facts) { triggerListenersBeforeRules(rules, facts); Map<Rule, Boolean> result = doCheck(rules, facts); triggerListenersAfterRules(rules, facts); return result; } DefaultRulesEngine();  DefaultRulesEngine(final RulesEngineParameters parameters); @Override void fire(Rules rules, Facts facts); @Override Map<Rule, Boolean> check(Rules rules, Facts facts);  }### Answer:
@Test public void rulesMustBeCheckedInTheirNaturalOrder() { when(rule1.evaluate(facts)).thenReturn(true); when(rule2.evaluate(facts)).thenReturn(true); when(rule2.compareTo(rule1)).thenReturn(1); rules.register(rule1); rules.register(rule2); rulesEngine.check(rules, facts); InOrder inOrder = inOrder(rule1, rule2); inOrder.verify(rule1).evaluate(facts); inOrder.verify(rule2).evaluate(facts); }
@Test public void testCheckRules() { when(rule1.evaluate(facts)).thenReturn(true); rules.register(rule1); rules.register(annotatedRule); Map<org.jeasy.rules.api.Rule, Boolean> result = rulesEngine.check(rules, facts); assertThat(result).hasSize(2); for (org.jeasy.rules.api.Rule r : rules) { assertThat(result.get(r)).isTrue(); } }
@Test public void listenerShouldBeInvokedBeforeCheckingRules() { when(rule1.evaluate(facts)).thenReturn(true); when(ruleListener.beforeEvaluate(rule1, facts)).thenReturn(true); DefaultRulesEngine rulesEngine = new DefaultRulesEngine(); rulesEngine.registerRuleListener(ruleListener); rules.register(rule1); rulesEngine.check(rules, facts); verify(ruleListener).beforeEvaluate(rule1, facts); }