update copyright
[reguloj.git] / src / test / java / wtf / metio / reguloj / RuleEngineTCK.java
blob56332c59d5c3eba5a202bfad551b8ae7dc63f786
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.mock;
13 import java.util.List;
14 import org.junit.jupiter.api.Assertions;
15 import org.junit.jupiter.api.BeforeEach;
16 import org.junit.jupiter.api.DisplayName;
17 import org.junit.jupiter.api.Test;
19 abstract class RuleEngineTCK {
21 protected RuleEngine<Context<Object>> engine;
22 protected Context<Object> context;
23 protected Rule<Context<Object>> rule;
24 protected Rule<Context<Object>> rule2;
26 protected abstract RuleEngine<Context<Object>> createRuleEngine();
28 @BeforeEach
29 final void setup() {
30 engine = createRuleEngine();
31 context = mock(Context.class);
32 rule = mock(Rule.class);
33 rule2 = mock(Rule.class);
36 @Test
37 @DisplayName("does not fire for empty rules collection")
38 final void shouldReturnFalseForEmptyRuleCollection() {
39 final var rules = List.<Rule<Context<Object>>>of();
40 final boolean fired = engine.analyze(rules, context);
41 Assertions.assertFalse(fired);
44 @Test
45 @DisplayName("fire if any rule fires")
46 final void shouldReturnTrueIfRuleFired() {
47 given(rule.fires(context)).willReturn(Boolean.TRUE);
48 final boolean fired = engine.analyze(List.of(rule), context);
49 Assertions.assertTrue(fired);
52 @Test
53 @DisplayName("does not fire if no rule fires")
54 final void shouldReturnFalseIfNoRuleFires() {
55 given(rule.fires(context)).willReturn(Boolean.FALSE);
56 final boolean fired = engine.analyze(List.of(rule), context);
57 Assertions.assertFalse(fired);
60 @Test
61 @DisplayName("can infer with empty rule collection")
62 final void shouldRunWithEmptyRuleSet() {
63 final var rules = List.<Rule<Context<Object>>>of();
64 engine.infer(rules, context);