2 * SPDX-FileCopyrightText: The reguloj Authors
3 * SPDX-License-Identifier: 0BSD
5 package wtf
.metio
.reguloj
;
7 import org
.junit
.jupiter
.api
.DisplayName
;
8 import org
.junit
.jupiter
.api
.Test
;
10 import java
.util
.List
;
12 import static org
.mockito
.BDDMockito
.given
;
13 import static org
.mockito
.Mockito
.*;
15 final class FirstWinsRuleEngineTest
extends RuleEngineTCK
{
18 protected RuleEngine
<Context
<Object
>> createRuleEngine() {
19 return new FirstWinsRuleEngine
<>();
23 @DisplayName("run only first matching rule")
24 void shouldOnlyRunFirstMatchingRule() {
25 given(rule
.fires(context
)).willReturn(Boolean
.TRUE
);
26 given(rule2
.fires(context
)).willReturn(Boolean
.FALSE
);
28 engine
.infer(List
.of(rule
, rule2
), context
);
30 verify(rule
, times(1)).fires(context
);
31 verify(rule
, times(1)).run(context
);
32 verifyNoMoreInteractions(rule2
);
36 @DisplayName("skip rules that are not firing")
37 void shouldOnlyRunFirstMatchingRuleSecond() {
38 given(rule
.fires(context
)).willReturn(Boolean
.FALSE
);
39 given(rule2
.fires(context
)).willReturn(Boolean
.TRUE
);
41 engine
.infer(List
.of(rule
, rule2
), context
);
43 verify(rule
, times(1)).fires(context
);
44 verify(rule
, times(0)).run(context
);
45 verify(rule2
, times(1)).fires(context
);
46 verify(rule2
, times(1)).run(context
);