forked from j-easy/easy-rules
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test for issue j-easy#139 (NPE If i add Fact with null value and …
…use annotation)
- Loading branch information
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
easy-rules-core/src/test/java/org/jeasy/rules/core/NullFactAnnotationParameterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
} | ||
|
||
} | ||
} |