package com.mars.test.easyrule.fizz;

import lombok.extern.slf4j.Slf4j;
import org.jeasy.rules.api.Facts;
import org.jeasy.rules.api.Rules;
import org.jeasy.rules.api.RulesEngine;
import org.jeasy.rules.core.RulesEngineBuilder;
import org.junit.Test;

/**
 * Created by USER on 2017/5/31.
 */
@Slf4j
public class FizzBuzzWithEasyRules {

    @Test
    public void test1(){
        RulesEngine fizzBuzzEngine = RulesEngineBuilder.aNewRulesEngine()
                .withSkipOnFirstAppliedRule(true)
                .withSilentMode(true)
                .build();

        // create rules
        Rules rules = new Rules();
        rules.register(new FizzRule());
        rules.register(new BuzzRule());
        rules.register(new FizzBuzzRule(new FizzRule(), new BuzzRule()));
        rules.register(new NonFizzBuzzRule());

        // fire rules
        Facts facts = new Facts();
        for (int i = 1; i <= 100; i++) {
            facts.put("number", i);
            fizzBuzzEngine.fire(rules, facts);
            System.out.println();
        }
    }

}

@@ -99,16 +99,49 @@
 .Facts;%0A
+import org.jeasy.rules.api.Rule;%0A
 import o
@@ -166,16 +166,16 @@
 .Rules;%0A
-
 import o
@@ -278,16 +278,61 @@
 .Test;%0A%0A
+import java.util.Map;%0Aimport java.util.Set;%0A%0A
 /**%0A * C
@@ -1028,16 +1028,16 @@
 r%22, i);%0A
-
         
@@ -1126,10 +1126,910 @@
 %0A    %7D%0A%0A
+    @Test%0A    public void test2()%7B%0A        RulesEngine fizzBuzzEngine = RulesEngineBuilder.aNewRulesEngine()%0A                .withSkipOnFirstAppliedRule(true)%0A                .withSilentMode(true)%0A                .build();%0A%0A        // create rules%0A        Rules rules = new Rules();%0A        rules.register(new FizzRule());%0A        rules.register(new BuzzRule());%0A        rules.register(new FizzBuzzRule(new FizzRule(), new BuzzRule()));%0A        rules.register(new NonFizzBuzzRule());%0A%0A        // fire rules%0A        Facts facts = new Facts();%0A        for (int i = 1; i %3C= 21; i++) %7B%0A            facts.put(%22number%22, i);%0A            Map%3CRule, Boolean%3E check = fizzBuzzEngine.check(rules, facts);%0A            check.forEach((k,v)-%3E %7B%0A                log.info(%22rule = %22 + k.toString());%0A                log.info(%22value = %22+ v.toString());%0A            %7D);%0A            System.out.println();%0A        %7D%0A    %7D%0A%0A
 %7D%0A

change fizz test