record & tck
[reguloj.git] / src / test / java / wtf / metio / reguloj / LimitedRuleEngineTest.java
blob9da759b53ce0e0e9fb6ab5c2f4c8049b83739b6f
1 package wtf.metio.reguloj;
3 import org.junit.jupiter.api.DisplayName;
4 import org.junit.jupiter.api.Test;
5 import org.mockito.BDDMockito;
6 import org.mockito.Mockito;
8 import java.util.List;
10 final class LimitedRuleEngineTest extends RuleEngineTCK {
12 @Override
13 protected RuleEngine<Context<Object>> createRuleEngine() {
14 return new LimitedRuleEngine<>(2);
17 @Test
18 @DisplayName("limit the number of loops")
19 void shouldRunTwoTimesWithMatchingRules() {
20 BDDMockito.given(rule.fires(context)).willReturn(Boolean.TRUE);
21 BDDMockito.given(rule2.fires(context)).willReturn(Boolean.TRUE);
23 engine.infer(List.of(rule, rule2), context);
25 Mockito.verify(rule, Mockito.times(2)).run(context);
26 Mockito.verify(rule2, Mockito.times(2)).run(context);
29 @Test
30 @DisplayName("iterate over all rules at least once")
31 void shouldRunOnceWithNonMatchingRules() {
32 BDDMockito.given(rule.fires(context)).willReturn(Boolean.FALSE);
33 BDDMockito.given(rule2.fires(context)).willReturn(Boolean.FALSE);
35 engine.infer(List.of(rule, rule2), context);
37 Mockito.verify(rule, Mockito.times(1)).fires(context);
38 Mockito.verify(rule2, Mockito.times(1)).fires(context);