add license header
[reguloj.git] / src / test / java / wtf / metio / reguloj / LimitedRuleEngineTest.java
blob71a0c346b6d482c4e008dd217bfa8b6b7fe037f2
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 http://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 org.junit.jupiter.api.DisplayName;
11 import org.junit.jupiter.api.Test;
12 import org.mockito.BDDMockito;
13 import org.mockito.Mockito;
15 import java.util.List;
17 final class LimitedRuleEngineTest extends RuleEngineTCK {
19 @Override
20 protected RuleEngine<Context<Object>> createRuleEngine() {
21 return new LimitedRuleEngine<>(2);
24 @Test
25 @DisplayName("limit the number of loops")
26 void shouldRunTwoTimesWithMatchingRules() {
27 BDDMockito.given(rule.fires(context)).willReturn(Boolean.TRUE);
28 BDDMockito.given(rule2.fires(context)).willReturn(Boolean.TRUE);
30 engine.infer(List.of(rule, rule2), context);
32 Mockito.verify(rule, Mockito.times(2)).run(context);
33 Mockito.verify(rule2, Mockito.times(2)).run(context);
36 @Test
37 @DisplayName("iterate over all rules at least once")
38 void shouldRunOnceWithNonMatchingRules() {
39 BDDMockito.given(rule.fires(context)).willReturn(Boolean.FALSE);
40 BDDMockito.given(rule2.fires(context)).willReturn(Boolean.FALSE);
42 engine.infer(List.of(rule, rule2), context);
44 Mockito.verify(rule, Mockito.times(1)).fires(context);
45 Mockito.verify(rule2, Mockito.times(1)).fires(context);