update project metadata
[reguloj.git] / src / test / java / wtf / metio / reguloj / FirstWinsRuleEngineTest.java
blobc328fa48ddf32d10d885b4eb6148266e0580ae23
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;
10 import java.util.List;
12 import static org.mockito.BDDMockito.given;
13 import static org.mockito.Mockito.*;
15 final class FirstWinsRuleEngineTest extends RuleEngineTCK {
17 @Override
18 protected RuleEngine<Context<Object>> createRuleEngine() {
19 return new FirstWinsRuleEngine<>();
22 @Test
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);
35 @Test
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);