issue : rename methods in RulesEngineListener to be consistent with RuleListener

pull/130/merge
Mahmoud Ben Hassine
parent 4d2dad6147
commit 14fe227c82

@ -33,20 +33,20 @@ import org.jeasy.rules.core.InferenceRulesEngine;
public interface RulesEngineListener { public interface RulesEngineListener {
/** /**
* Triggered before firing the rule set. * Triggered before evaluating the rule set.
* <strong>When this listener is used with a {@link InferenceRulesEngine}, this method will be triggered before each candidate rule set in each iteration.</strong> * <strong>When this listener is used with a {@link InferenceRulesEngine}, this method will be triggered before the evaluation of each candidate rule set in each iteration.</strong>
* *
* @param rules to fire * @param rules to fire
* @param facts present before firing rules * @param facts present before firing rules
*/ */
void beforeFiringRules(Rules rules, Facts facts); void beforeEvaluate(Rules rules, Facts facts);
/** /**
* Triggered after firing the rule set * Triggered after executing the rule set
* <strong>When this listener is used with a {@link InferenceRulesEngine}, this method will be triggered after each candidate rule set in each iteration.</strong> * <strong>When this listener is used with a {@link InferenceRulesEngine}, this method will be triggered after the execution of each candidate rule set in each iteration.</strong>
* *
* @param rules fired * @param rules fired
* @param facts present after firing rules * @param facts present after firing rules
*/ */
void afterFiringRules(Rules rules, Facts facts); void afterExecute(Rules rules, Facts facts);
} }

@ -213,13 +213,13 @@ public final class DefaultRulesEngine implements RulesEngine {
private void triggerListenersBeforeRules(Rules rule, Facts facts) { private void triggerListenersBeforeRules(Rules rule, Facts facts) {
for (RulesEngineListener rulesEngineListener : rulesEngineListeners) { for (RulesEngineListener rulesEngineListener : rulesEngineListeners) {
rulesEngineListener.beforeFiringRules(rule, facts); rulesEngineListener.beforeEvaluate(rule, facts);
} }
} }
private void triggerListenersAfterRules(Rules rule, Facts facts) { private void triggerListenersAfterRules(Rules rule, Facts facts) {
for (RulesEngineListener rulesEngineListener : rulesEngineListeners) { for (RulesEngineListener rulesEngineListener : rulesEngineListeners) {
rulesEngineListener.afterFiringRules(rule, facts); rulesEngineListener.afterExecute(rule, facts);
} }
} }

@ -51,7 +51,7 @@ public class RulesEngineListenerTest extends AbstractTest {
} }
@Test @Test
public void rulesEngineListenersShouldBeCalledInOrder() throws Exception { public void rulesEngineListenersShouldBeCalledInOrderWhenFiringRules() throws Exception {
// Given // Given
when(rule1.evaluate(facts)).thenReturn(true); when(rule1.evaluate(facts)).thenReturn(true);
rules.register(rule1); rules.register(rule1);
@ -61,12 +61,12 @@ public class RulesEngineListenerTest extends AbstractTest {
// Then // Then
InOrder inOrder = inOrder(rule1, fact1, fact2, rulesEngineListener1, rulesEngineListener2); InOrder inOrder = inOrder(rule1, fact1, fact2, rulesEngineListener1, rulesEngineListener2);
inOrder.verify(rulesEngineListener1).beforeFiringRules(rules, facts); inOrder.verify(rulesEngineListener1).beforeEvaluate(rules, facts);
inOrder.verify(rulesEngineListener2).beforeFiringRules(rules, facts); inOrder.verify(rulesEngineListener2).beforeEvaluate(rules, facts);
inOrder.verify(rule1).evaluate(facts); inOrder.verify(rule1).evaluate(facts);
inOrder.verify(rule1).execute(facts); inOrder.verify(rule1).execute(facts);
inOrder.verify(rulesEngineListener1).afterFiringRules(rules, facts); inOrder.verify(rulesEngineListener1).afterExecute(rules, facts);
inOrder.verify(rulesEngineListener2).afterFiringRules(rules, facts); inOrder.verify(rulesEngineListener2).afterExecute(rules, facts);
} }
} }

Loading…
Cancel
Save