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
;
10 final class LimitedRuleEngineTest
extends RuleEngineTCK
{
13 protected RuleEngine
<Context
<Object
>> createRuleEngine() {
14 return new LimitedRuleEngine
<>(2);
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
);
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
);