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
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
{
21 protected RuleEngine
<Context
<Object
>> createRuleEngine() {
22 return new ChainedRuleEngine
<>();
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
);
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
);