From 65f65e310d5a9d22e5de95cbf1972843449ee753 Mon Sep 17 00:00:00 2001 From: Mahmoud Ben Hassine Date: Sun, 21 May 2017 22:25:09 +0200 Subject: [PATCH] add Rules tests --- .../java/org/jeasy/rules/api/RulesTest.java | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 easy-rules-core/src/test/java/org/jeasy/rules/api/RulesTest.java diff --git a/easy-rules-core/src/test/java/org/jeasy/rules/api/RulesTest.java b/easy-rules-core/src/test/java/org/jeasy/rules/api/RulesTest.java new file mode 100644 index 0000000..85e8a09 --- /dev/null +++ b/easy-rules-core/src/test/java/org/jeasy/rules/api/RulesTest.java @@ -0,0 +1,68 @@ +package org.jeasy.rules.api; + +import org.jeasy.rules.annotation.Action; +import org.jeasy.rules.annotation.Condition; +import org.jeasy.rules.core.BasicRule; +import org.junit.Test; + +import java.util.HashSet; +import java.util.Set; + +import static org.assertj.core.api.Assertions.assertThat; + +public class RulesTest { + + private Rules rules = new Rules(); + + @Test + public void register() throws Exception { + rules.register(new DummyRule()); + + assertThat(rules).hasSize(1); + } + + @Test + public void rulesMustHaveUniqueName() throws Exception { + Rule r1 = new BasicRule("rule"); + Rule r2 = new BasicRule("rule"); + Set ruleSet = new HashSet<>(); + ruleSet.add(r1); + ruleSet.add(r2); + + rules = new Rules(ruleSet); + + assertThat(rules).hasSize(1); + } + + @Test + public void unregister() throws Exception { + DummyRule rule = new DummyRule(); + rules.register(rule); + rules.unregister(rule); + + assertThat(rules).isEmpty(); + } + + @Test + public void isEmpty() throws Exception { + assertThat(rules.isEmpty()).isTrue(); + } + + @Test + public void clear() throws Exception { + rules.register(new DummyRule()); + rules.clear(); + + assertThat(rules).isEmpty(); + } + + @org.jeasy.rules.annotation.Rule + class DummyRule { + @Condition + public boolean when() { return true; } + + @Action + public void then() { } + } + +} \ No newline at end of file