Skip to content

Commit

Permalink
add test for issue j-easy#139 (NPE If i add Fact with null value and …
Browse files Browse the repository at this point in the history
…use annotation)
  • Loading branch information
bpoussin committed Mar 1, 2018
1 parent 13723a8 commit 7b7113b
Showing 1 changed file with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.jeasy.rules.core;

import org.jeasy.rules.annotation.Action;
import org.jeasy.rules.annotation.Condition;
import org.jeasy.rules.annotation.Fact;
import org.jeasy.rules.annotation.Rule;
import org.jeasy.rules.api.Facts;
import org.jeasy.rules.api.Rules;
import org.junit.Assert;
import org.junit.Test;

import java.util.Map;

/**
* Null value in facts must be accepted, this is not same thing that fact missing
*/
public class NullFactAnnotationParameterTest extends AbstractTest {

@Test
public void testNullFact() {
Rules rules = new Rules();
rules.register(new AnnotatedParametersRule());

Facts facts = new Facts();
facts.put("fact1", new Object());
facts.put("fact2", null);

Map<org.jeasy.rules.api.Rule, Boolean> results = rulesEngine.check(rules, facts);

for (boolean b : results.values()) {
Assert.assertTrue(b);
}
}

@Rule
public class AnnotatedParametersRule {

@Condition
public boolean when(@Fact("fact1") Object fact1, @Fact("fact2") Object fact2) {
return true;
}

@Action
public void then(@Fact("fact1") Object fact1, @Fact("fact2") Object fact2) {
}

}
}

0 comments on commit 7b7113b

Please sign in to comment.