package com.mars.test.easyrule.shop;

import com.google.common.base.Preconditions;
import lombok.extern.slf4j.Slf4j;
import org.jeasy.rules.annotation.Rule;
import org.jeasy.rules.api.Facts;
import org.jeasy.rules.core.BasicRule;

/**
 * Created by USER on 2017/5/24.
 */
@Rule
@Slf4j
public class AgeRule extends BasicRule {

    private static final int ADULT_AGE = 18;

    private Person person;

    public AgeRule() {
        super("AgeRule", "Check if person's age is > 18 and marks the person as adult", 1);
    }

    @Override
    public boolean evaluate(Facts facts) {
        Person person = (Person) facts.get("person");
        Preconditions.checkState(person != null,"person can't be empty");
        return person.getAge() > ADULT_AGE;
    }

    @Override
    public void execute(Facts facts) throws Exception {
        Person person = (Person) facts.get("person");
        person.setAdult(true);
        log.info("Person "+person.getName()+" has been marked as adult");
        System.out.println();
    }
}

@@ -697,24 +697,58 @@
 be empty%22);%0A
+        facts.put(%22test%22,%22test%22);%0A
         retu
@@ -856,16 +856,102 @@
 ption %7B%0A
+        String test = (String) facts.get(%22test%22);%0A        log.info(%22test = %22 + test);%0A
         

add pass value between evaluate and execute var facts