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
.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();
30 engine
= createRuleEngine();
31 context
= mock(Context
.class);
32 rule
= mock(Rule
.class);
33 rule2
= mock(Rule
.class);
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
);
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
);
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
);
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
);