update project metadata
[reguloj.git] / src / test / java / wtf / metio / reguloj / LimitedRuleEngineTest.java
blobff5e2c2fb76303d89d68cad7bae221cd20d29eba
1 /*
2 * SPDX-FileCopyrightText: The reguloj Authors
3 * SPDX-License-Identifier: 0BSD
4 */
5 package wtf.metio.reguloj;
7 import org.junit.jupiter.api.DisplayName;
8 import org.junit.jupiter.api.Test;
9 import org.mockito.BDDMockito;
10 import org.mockito.Mockito;
12 import java.util.List;
14 final class LimitedRuleEngineTest extends RuleEngineTCK {
16 @Override
17 protected RuleEngine<Context<Object>> createRuleEngine() {
18 return new LimitedRuleEngine<>(2);
21 @Test
22 @DisplayName("limit the number of loops")
23 void shouldRunTwoTimesWithMatchingRules() {
24 BDDMockito.given(rule.fires(context)).willReturn(Boolean.TRUE);
25 BDDMockito.given(rule2.fires(context)).willReturn(Boolean.TRUE);
27 engine.infer(List.of(rule, rule2), context);
29 Mockito.verify(rule, Mockito.times(2)).run(context);
30 Mockito.verify(rule2, Mockito.times(2)).run(context);
33 @Test
34 @DisplayName("iterate over all rules at least once")
35 void shouldRunOnceWithNonMatchingRules() {
36 BDDMockito.given(rule.fires(context)).willReturn(Boolean.FALSE);
37 BDDMockito.given(rule2.fires(context)).willReturn(Boolean.FALSE);
39 engine.infer(List.of(rule, rule2), context);
41 Mockito.verify(rule, Mockito.times(1)).fires(context);
42 Mockito.verify(rule2, Mockito.times(1)).fires(context);