update copyright
[reguloj.git] / src / test / java / wtf / metio / reguloj / ChainedRuleEngineTest.java
blob4378026b9c5fc53bd7ed0b6a13d087fc55762bc2
1 /*
2 * This file is part of reguloj. It is subject to the license terms in the LICENSE file found in the top-level
3 * directory of this distribution and at https://creativecommons.org/publicdomain/zero/1.0/. No part of reguloj,
4 * including this file, may be copied, modified, propagated, or distributed except according to the terms contained
5 * in the LICENSE file.
6 */
8 package wtf.metio.reguloj;
10 import static org.mockito.BDDMockito.given;
11 import static org.mockito.Mockito.times;
12 import static org.mockito.Mockito.verify;
14 import java.util.List;
15 import org.junit.jupiter.api.DisplayName;
16 import org.junit.jupiter.api.Test;
18 final class ChainedRuleEngineTest extends RuleEngineTCK {
20 @Override
21 protected RuleEngine<Context<Object>> createRuleEngine() {
22 return new ChainedRuleEngine<>();
25 @Test
26 @DisplayName("loop as long as rules are firing")
27 void shouldLoopWithFiringRule() {
28 given(rule.fires(context)).willReturn(Boolean.TRUE).willReturn(Boolean.FALSE);
29 engine.infer(List.of(rule), context);
30 verify(rule, times(2)).fires(context);
31 verify(rule, times(1)).run(context);
34 @Test
35 @DisplayName("do not loop when no rule is firing")
36 void shouldNotLoopWithNotFiringRule() {
37 given(rule.fires(context)).willReturn(Boolean.FALSE);
38 engine.infer(List.of(rule), context);
39 verify(rule, times(1)).fires(context);
40 verify(rule, times(0)).run(context);