diff --git a/src/main/java/com/ljunggren/rules/engine/Codex.java b/src/main/java/com/ljunggren/rules/engine/Codex.java deleted file mode 100644 index 2373a21..0000000 --- a/src/main/java/com/ljunggren/rules/engine/Codex.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.ljunggren.rules.engine; - -import java.util.ArrayList; -import java.util.List; - -import lombok.Getter; - -@Getter -public class Codex { - - private List> rules; - private Rule defaultRule; - private ConflictResolution conflictResolution; - - public Codex() { - rules = new ArrayList>(); - } - - public void addRule(Rule rule) { - rules.add(rule); - } - - public void setConflictResolution(ConflictResolution conflictResolution) { - this.conflictResolution = conflictResolution; - } - - public void setDefaultRule(Rule defaultRule) { - this.defaultRule = defaultRule; - } - -} diff --git a/src/main/java/com/ljunggren/rules/engine/ConflictResolution.java b/src/main/java/com/ljunggren/rules/engine/ConflictResolution.java deleted file mode 100644 index e625ad2..0000000 --- a/src/main/java/com/ljunggren/rules/engine/ConflictResolution.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.ljunggren.rules.engine; - -import java.util.List; - -public interface ConflictResolution { - - Rule resolve(List> rules, I input); - -} diff --git a/src/main/java/com/ljunggren/rules/engine/Engine.java b/src/main/java/com/ljunggren/rules/engine/Engine.java deleted file mode 100644 index 5ebe905..0000000 --- a/src/main/java/com/ljunggren/rules/engine/Engine.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.ljunggren.rules.engine; - -import java.util.List; -import java.util.function.Consumer; -import java.util.stream.Collectors; - -import lombok.Getter; - -@Getter -public class Engine { - - private Codex codex; - private Consumer> trace; - - public Engine(Codex codex) { - this.codex = codex == null ? new Codex<>() : codex; - } - - public Engine trace(Consumer> trace) { - this.trace = trace; - return this; - } - - public O execute(I input) { - List> rules = applicableRules(input); - Rule rule = rules.isEmpty() ? noRules(input) : executeRules(rules, input); - trace(rule); - return rule == null ? null : rule.execute(input); - } - - private List> applicableRules(I input) { - return codex.getRules().stream() - .filter(rule -> rule.applies(input)) - .collect(Collectors.toList()); - } - - private Rule noRules(I input) { - return codex.getDefaultRule() == null ? - null : codex.getDefaultRule(); - } - - private Rule executeRules(List> rules, I input) { - return rules.size() == 1 ? - rules.get(0) : - multipleRules(rules, input); - } - - private Rule multipleRules(List> rules, I input) { - return codex.getConflictResolution() == null ? - rules.get(0) : - codex.getConflictResolution().resolve(rules, input); - } - - private void trace(Rule rule) { - if (trace != null) { - trace.accept(rule); - } - } - -} diff --git a/src/main/java/com/ljunggren/rules/engine/Rule.java b/src/main/java/com/ljunggren/rules/engine/Rule.java deleted file mode 100644 index bf97d7b..0000000 --- a/src/main/java/com/ljunggren/rules/engine/Rule.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.ljunggren.rules.engine; - -public interface Rule { - - boolean applies(I input); - O execute(I input); - -} diff --git a/src/main/java/com/ljunggren/rules/engine/analyzer/Analyzer.java b/src/main/java/com/ljunggren/rules/engine/analyzer/Analyzer.java deleted file mode 100644 index da5699e..0000000 --- a/src/main/java/com/ljunggren/rules/engine/analyzer/Analyzer.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.ljunggren.rules.engine.analyzer; - -import com.ljunggren.rules.engine.Rule; -import com.ljunggren.rules.engine.annotation.RuleInfo; - -public class Analyzer { - - public String getName(Rule rule) { - if (rule == null) { - return noRule(); - } - RuleInfo ruleInfo = getRuleInfo(rule); - return ruleInfo == null ? - rule.getClass().getSimpleName() : - ruleInfo.name(); - } - - public String getCondition(Rule rule) { - if (rule == null) { - return noRule(); - } - RuleInfo ruleInfo = getRuleInfo(rule); - return ruleInfo == null ? - noInfo() : - ruleInfo.condition(); - } - - public String getAction(Rule rule) { - if (rule == null) { - return noRule(); - } - RuleInfo ruleInfo = getRuleInfo(rule); - return ruleInfo == null ? - noInfo() : - ruleInfo.action(); - } - - private String noRule() { - return "No rule found"; - } - - private String noInfo() { - return "No info found"; - } - - private RuleInfo getRuleInfo(Rule rule) { - return rule.getClass().getAnnotation(RuleInfo.class); - } - -} diff --git a/src/main/java/com/ljunggren/rules/engine/annotation/RuleInfo.java b/src/main/java/com/ljunggren/rules/engine/annotation/RuleInfo.java deleted file mode 100644 index 7b81dd3..0000000 --- a/src/main/java/com/ljunggren/rules/engine/annotation/RuleInfo.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.ljunggren.rules.engine.annotation; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -public @interface RuleInfo { - - String name(); - String condition(); - String action(); - -} diff --git a/src/main/java/com/ljunggren/rulesEngine/Codex.java b/src/main/java/com/ljunggren/rulesEngine/Codex.java new file mode 100644 index 0000000..1edf597 --- /dev/null +++ b/src/main/java/com/ljunggren/rulesEngine/Codex.java @@ -0,0 +1,31 @@ +package com.ljunggren.rulesEngine; + +import java.util.ArrayList; +import java.util.List; + +import lombok.Getter; + +@Getter +public class Codex { + + private List> rules; + private Rule defaultRule; + private ConflictResolution conflictResolution; + + public Codex() { + rules = new ArrayList>(); + } + + public void addRule(Rule rule) { + rules.add(rule); + } + + public void setConflictResolution(ConflictResolution conflictResolution) { + this.conflictResolution = conflictResolution; + } + + public void setDefaultRule(Rule defaultRule) { + this.defaultRule = defaultRule; + } + +} diff --git a/src/main/java/com/ljunggren/rulesEngine/ConflictResolution.java b/src/main/java/com/ljunggren/rulesEngine/ConflictResolution.java new file mode 100644 index 0000000..6e4b632 --- /dev/null +++ b/src/main/java/com/ljunggren/rulesEngine/ConflictResolution.java @@ -0,0 +1,9 @@ +package com.ljunggren.rulesEngine; + +import java.util.List; + +public interface ConflictResolution { + + Rule resolve(List> rules, I input); + +} diff --git a/src/main/java/com/ljunggren/rulesEngine/Engine.java b/src/main/java/com/ljunggren/rulesEngine/Engine.java new file mode 100644 index 0000000..baf3b5e --- /dev/null +++ b/src/main/java/com/ljunggren/rulesEngine/Engine.java @@ -0,0 +1,60 @@ +package com.ljunggren.rulesEngine; + +import java.util.List; +import java.util.function.Consumer; +import java.util.stream.Collectors; + +import lombok.Getter; + +@Getter +public class Engine { + + private Codex codex; + private Consumer> trace; + + public Engine(Codex codex) { + this.codex = codex == null ? new Codex<>() : codex; + } + + public Engine trace(Consumer> trace) { + this.trace = trace; + return this; + } + + public O execute(I input) { + List> rules = applicableRules(input); + Rule rule = rules.isEmpty() ? noRules(input) : executeRules(rules, input); + trace(rule); + return rule == null ? null : rule.execute(input); + } + + private List> applicableRules(I input) { + return codex.getRules().stream() + .filter(rule -> rule.applies(input)) + .collect(Collectors.toList()); + } + + private Rule noRules(I input) { + return codex.getDefaultRule() == null ? + null : codex.getDefaultRule(); + } + + private Rule executeRules(List> rules, I input) { + return rules.size() == 1 ? + rules.get(0) : + multipleRules(rules, input); + } + + private Rule multipleRules(List> rules, I input) { + return codex.getConflictResolution() == null ? + rules.get(0) : + codex.getConflictResolution().resolve(rules, input); + } + + private void trace(Rule rule) { + if (trace != null) { + trace.accept(rule); + } + } + +} diff --git a/src/main/java/com/ljunggren/rulesEngine/Rule.java b/src/main/java/com/ljunggren/rulesEngine/Rule.java new file mode 100644 index 0000000..772e410 --- /dev/null +++ b/src/main/java/com/ljunggren/rulesEngine/Rule.java @@ -0,0 +1,8 @@ +package com.ljunggren.rulesEngine; + +public interface Rule { + + boolean applies(I input); + O execute(I input); + +} diff --git a/src/main/java/com/ljunggren/rulesEngine/analyzer/Analyzer.java b/src/main/java/com/ljunggren/rulesEngine/analyzer/Analyzer.java new file mode 100644 index 0000000..be5fdab --- /dev/null +++ b/src/main/java/com/ljunggren/rulesEngine/analyzer/Analyzer.java @@ -0,0 +1,50 @@ +package com.ljunggren.rulesEngine.analyzer; + +import com.ljunggren.rulesEngine.Rule; +import com.ljunggren.rulesEngine.annotation.RuleInfo; + +public class Analyzer { + + public String getName(Rule rule) { + if (rule == null) { + return noRule(); + } + RuleInfo ruleInfo = getRuleInfo(rule); + return ruleInfo == null ? + rule.getClass().getSimpleName() : + ruleInfo.name(); + } + + public String getCondition(Rule rule) { + if (rule == null) { + return noRule(); + } + RuleInfo ruleInfo = getRuleInfo(rule); + return ruleInfo == null ? + noInfo() : + ruleInfo.condition(); + } + + public String getAction(Rule rule) { + if (rule == null) { + return noRule(); + } + RuleInfo ruleInfo = getRuleInfo(rule); + return ruleInfo == null ? + noInfo() : + ruleInfo.action(); + } + + private String noRule() { + return "No rule found"; + } + + private String noInfo() { + return "No info found"; + } + + private RuleInfo getRuleInfo(Rule rule) { + return rule.getClass().getAnnotation(RuleInfo.class); + } + +} diff --git a/src/main/java/com/ljunggren/rulesEngine/annotation/RuleInfo.java b/src/main/java/com/ljunggren/rulesEngine/annotation/RuleInfo.java new file mode 100644 index 0000000..80f89a5 --- /dev/null +++ b/src/main/java/com/ljunggren/rulesEngine/annotation/RuleInfo.java @@ -0,0 +1,16 @@ +package com.ljunggren.rulesEngine.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface RuleInfo { + + String name(); + String condition(); + String action(); + +} diff --git a/src/test/java/com/ljunggren/rules/engine/CodexTest.java b/src/test/java/com/ljunggren/rules/engine/CodexTest.java deleted file mode 100644 index 98b0146..0000000 --- a/src/test/java/com/ljunggren/rules/engine/CodexTest.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.ljunggren.rules.engine; - -import static org.junit.Assert.*; - -import java.util.List; - -import org.junit.Test; - -public class CodexTest { - - @Test - public void instantiationTest() { - Codex codex = new Codex<>(); - assertTrue(codex instanceof Codex); - assertTrue(codex.getRules().isEmpty()); - assertNull(codex.getDefaultRule()); - assertNull(codex.getConflictResolution()); - } - - private Rule rule = new Rule() { - public Object execute(Object input) { - return input; - } - public boolean applies(Object input) { - return true; - } - }; - - @Test - public void addRuleTest() { - Codex codex = new Codex<>(); - codex.addRule(rule); - assertTrue(codex.getRules().contains(rule)); - } - - @Test - public void setConflictResoltutionTest() { - Codex codex = new Codex<>(); - ConflictResolution conflictResolution = new ConflictResolution() { - public Rule resolve(List> rules, Object input) { - return rules.get(0); - } - }; - codex.setConflictResolution(conflictResolution); - assertEquals(conflictResolution, codex.getConflictResolution()); - } - - @Test - public void setDefaultRuleTest() { - Codex codex = new Codex<>(); - codex.setDefaultRule(rule); - assertEquals(rule, codex.getDefaultRule()); - } - -} diff --git a/src/test/java/com/ljunggren/rules/engine/EngineTest.java b/src/test/java/com/ljunggren/rules/engine/EngineTest.java deleted file mode 100644 index 252fd4f..0000000 --- a/src/test/java/com/ljunggren/rules/engine/EngineTest.java +++ /dev/null @@ -1,124 +0,0 @@ -package com.ljunggren.rules.engine; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - -import java.util.List; -import java.util.function.Consumer; - -import org.junit.Before; -import org.junit.Test; - -public class EngineTest { - - private Codex codex; - private Rule rule; - - @Before - public void setup() { - codex = new Codex(); - codex.addRule(new Rule() { - public boolean applies(Object input) { - return input instanceof String; - } - public String execute(Object input) { - return "String"; - } - }); - codex.addRule(new Rule() { - public boolean applies(Object input) { - return input instanceof Number; - } - public String execute(Object input) { - return "Number"; - } - }); - codex.addRule(new Rule() { - public boolean applies(Object input) { - return input instanceof Integer; - } - public String execute(Object input) { - return "Integer"; - } - }); - } - - private void setRule(Rule rule) { - this.rule = rule; - } - - @Test - public void executeNullCodexTest() { - Engine engine = new Engine<>(null); - assertNotNull(engine.getCodex()); - assertNull(engine.execute("Test")); - } - - @Test - public void executeTest() { - Engine engine = new Engine<>(codex); - assertEquals("String", engine.execute("Test")); - } - - @Test - public void executeMultipleResultTest() { - Engine engine = new Engine<>(codex); - assertEquals("Number", engine.execute(100)); - } - - @Test - public void executeNoResultTest() { - Engine engine = new Engine<>(codex); - assertNull(engine.execute(true)); - } - - @Test - public void executeWithDefaultRuleTest() { - codex.setDefaultRule(new Rule() { - public String execute(Object input) { - return "Unknown"; - } - public boolean applies(Object input) { - return true; - } - }); - Engine engine = new Engine<>(codex); - assertEquals("Unknown", engine.execute(true)); - } - - @Test - public void executeWithConflictResolutionTest() { - codex.setConflictResolution(new ConflictResolution() { - public Rule resolve(List> rules, Object input) { - return rules.get(1); - } - }); - Engine engine = new Engine<>(codex); - assertEquals("Integer", engine.execute(100)); - } - - @Test - public void traceTest() { - Consumer> trace = e -> setRule(e); - Engine engine = new Engine<>(codex).trace(trace); - engine.execute("Test"); - assertNotNull(rule); - } - - @Test - public void traceNullTest() { - Consumer> trace = e -> setRule(e); - Engine engine = new Engine<>(codex).trace(trace); - engine.execute(true); - assertNull(rule); - } - - @Test - public void traceNotSetTest() { - Engine engine = new Engine<>(codex); - engine.execute("Test"); - assertNull(rule); - } - -} diff --git a/src/test/java/com/ljunggren/rules/engine/analyzer/AnalyzerTest.java b/src/test/java/com/ljunggren/rules/engine/analyzer/AnalyzerTest.java deleted file mode 100644 index 94a5d5c..0000000 --- a/src/test/java/com/ljunggren/rules/engine/analyzer/AnalyzerTest.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.ljunggren.rules.engine.analyzer; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -import com.ljunggren.rules.engine.Rule; -import com.ljunggren.rules.engine.annotation.RuleInfo; - -public class AnalyzerTest { - - private Analyzer analyzer = new Analyzer<>(); - private final String NO_RULE = "No rule found"; - private final String NO_INFO = "No info found"; - - @RuleInfo(action = "Return the word String", condition = "If input is a String", name = "Is String") - public class TestRuleWithAnnotation implements Rule { - public boolean applies(Object input) { - return input instanceof String; - } - public String execute(Object input) { - return "String"; - } - } - - public class TestRuleWithoutWithAnnotation implements Rule { - public boolean applies(Object input) { - return input instanceof String; - } - public String execute(Object input) { - return "String"; - } - } - - @Test - public void instantiationTest() { - assertTrue(analyzer instanceof Analyzer); - } - - @Test - public void actionTest() { - assertEquals(analyzer.getAction(new TestRuleWithAnnotation()), "Return the word String"); - } - - @Test - public void actionNoAnnotationTest() { - assertEquals(analyzer.getAction(new TestRuleWithoutWithAnnotation()), NO_INFO); - } - - @Test - public void actionNullTest() { - assertEquals(analyzer.getAction(null), NO_RULE); - } - - @Test - public void conditionTest() { - assertEquals(analyzer.getCondition(new TestRuleWithAnnotation()), "If input is a String"); - } - - @Test - public void conditionNoAnnotationTest() { - assertEquals(analyzer.getCondition(new TestRuleWithoutWithAnnotation()), NO_INFO); - } - - @Test - public void conditionNullTest() { - assertEquals(analyzer.getCondition(null), NO_RULE); - } - - @Test - public void nameTest() { - assertEquals(analyzer.getName(new TestRuleWithAnnotation()), "Is String"); - } - - @Test - public void nameNoAnnotationTest() { - assertEquals(analyzer.getName(new TestRuleWithoutWithAnnotation()), "TestRuleWithoutWithAnnotation"); - } - - @Test - public void nameNullTest() { - assertEquals(analyzer.getName(null), NO_RULE); - } - -} diff --git a/src/test/java/com/ljunggren/rulesEngine/CodexTest.java b/src/test/java/com/ljunggren/rulesEngine/CodexTest.java new file mode 100644 index 0000000..1a5116a --- /dev/null +++ b/src/test/java/com/ljunggren/rulesEngine/CodexTest.java @@ -0,0 +1,59 @@ +package com.ljunggren.rulesEngine; + +import static org.junit.Assert.*; + +import java.util.List; + +import org.junit.Test; + +import com.ljunggren.rulesEngine.Codex; +import com.ljunggren.rulesEngine.ConflictResolution; +import com.ljunggren.rulesEngine.Rule; + +public class CodexTest { + + @Test + public void instantiationTest() { + Codex codex = new Codex<>(); + assertTrue(codex instanceof Codex); + assertTrue(codex.getRules().isEmpty()); + assertNull(codex.getDefaultRule()); + assertNull(codex.getConflictResolution()); + } + + private Rule rule = new Rule() { + public Object execute(Object input) { + return input; + } + public boolean applies(Object input) { + return true; + } + }; + + @Test + public void addRuleTest() { + Codex codex = new Codex<>(); + codex.addRule(rule); + assertTrue(codex.getRules().contains(rule)); + } + + @Test + public void setConflictResoltutionTest() { + Codex codex = new Codex<>(); + ConflictResolution conflictResolution = new ConflictResolution() { + public Rule resolve(List> rules, Object input) { + return rules.get(0); + } + }; + codex.setConflictResolution(conflictResolution); + assertEquals(conflictResolution, codex.getConflictResolution()); + } + + @Test + public void setDefaultRuleTest() { + Codex codex = new Codex<>(); + codex.setDefaultRule(rule); + assertEquals(rule, codex.getDefaultRule()); + } + +} diff --git a/src/test/java/com/ljunggren/rulesEngine/EngineTest.java b/src/test/java/com/ljunggren/rulesEngine/EngineTest.java new file mode 100644 index 0000000..9cc346e --- /dev/null +++ b/src/test/java/com/ljunggren/rulesEngine/EngineTest.java @@ -0,0 +1,129 @@ +package com.ljunggren.rulesEngine; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import java.util.List; +import java.util.function.Consumer; + +import org.junit.Before; +import org.junit.Test; + +import com.ljunggren.rulesEngine.Codex; +import com.ljunggren.rulesEngine.ConflictResolution; +import com.ljunggren.rulesEngine.Engine; +import com.ljunggren.rulesEngine.Rule; + +public class EngineTest { + + private Codex codex; + private Rule rule; + + @Before + public void setup() { + codex = new Codex(); + codex.addRule(new Rule() { + public boolean applies(Object input) { + return input instanceof String; + } + public String execute(Object input) { + return "String"; + } + }); + codex.addRule(new Rule() { + public boolean applies(Object input) { + return input instanceof Number; + } + public String execute(Object input) { + return "Number"; + } + }); + codex.addRule(new Rule() { + public boolean applies(Object input) { + return input instanceof Integer; + } + public String execute(Object input) { + return "Integer"; + } + }); + } + + private void setRule(Rule rule) { + this.rule = rule; + } + + @Test + public void executeNullCodexTest() { + Engine engine = new Engine<>(null); + assertNotNull(engine.getCodex()); + assertNull(engine.execute("Test")); + } + + @Test + public void executeTest() { + Engine engine = new Engine<>(codex); + assertEquals("String", engine.execute("Test")); + } + + @Test + public void executeMultipleResultTest() { + Engine engine = new Engine<>(codex); + assertEquals("Number", engine.execute(100)); + } + + @Test + public void executeNoResultTest() { + Engine engine = new Engine<>(codex); + assertNull(engine.execute(true)); + } + + @Test + public void executeWithDefaultRuleTest() { + codex.setDefaultRule(new Rule() { + public String execute(Object input) { + return "Unknown"; + } + public boolean applies(Object input) { + return true; + } + }); + Engine engine = new Engine<>(codex); + assertEquals("Unknown", engine.execute(true)); + } + + @Test + public void executeWithConflictResolutionTest() { + codex.setConflictResolution(new ConflictResolution() { + public Rule resolve(List> rules, Object input) { + return rules.get(1); + } + }); + Engine engine = new Engine<>(codex); + assertEquals("Integer", engine.execute(100)); + } + + @Test + public void traceTest() { + Consumer> trace = e -> setRule(e); + Engine engine = new Engine<>(codex).trace(trace); + engine.execute("Test"); + assertNotNull(rule); + } + + @Test + public void traceNullTest() { + Consumer> trace = e -> setRule(e); + Engine engine = new Engine<>(codex).trace(trace); + engine.execute(true); + assertNull(rule); + } + + @Test + public void traceNotSetTest() { + Engine engine = new Engine<>(codex); + engine.execute("Test"); + assertNull(rule); + } + +} diff --git a/src/test/java/com/ljunggren/rulesEngine/analyzer/AnalyzerTest.java b/src/test/java/com/ljunggren/rulesEngine/analyzer/AnalyzerTest.java new file mode 100644 index 0000000..85ca4bd --- /dev/null +++ b/src/test/java/com/ljunggren/rulesEngine/analyzer/AnalyzerTest.java @@ -0,0 +1,87 @@ +package com.ljunggren.rulesEngine.analyzer; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +import com.ljunggren.rulesEngine.Rule; +import com.ljunggren.rulesEngine.analyzer.Analyzer; +import com.ljunggren.rulesEngine.annotation.RuleInfo; + +public class AnalyzerTest { + + private Analyzer analyzer = new Analyzer<>(); + private final String NO_RULE = "No rule found"; + private final String NO_INFO = "No info found"; + + @RuleInfo(action = "Return the word String", condition = "If input is a String", name = "Is String") + public class TestRuleWithAnnotation implements Rule { + public boolean applies(Object input) { + return input instanceof String; + } + public String execute(Object input) { + return "String"; + } + } + + public class TestRuleWithoutWithAnnotation implements Rule { + public boolean applies(Object input) { + return input instanceof String; + } + public String execute(Object input) { + return "String"; + } + } + + @Test + public void instantiationTest() { + assertTrue(analyzer instanceof Analyzer); + } + + @Test + public void actionTest() { + assertEquals(analyzer.getAction(new TestRuleWithAnnotation()), "Return the word String"); + } + + @Test + public void actionNoAnnotationTest() { + assertEquals(analyzer.getAction(new TestRuleWithoutWithAnnotation()), NO_INFO); + } + + @Test + public void actionNullTest() { + assertEquals(analyzer.getAction(null), NO_RULE); + } + + @Test + public void conditionTest() { + assertEquals(analyzer.getCondition(new TestRuleWithAnnotation()), "If input is a String"); + } + + @Test + public void conditionNoAnnotationTest() { + assertEquals(analyzer.getCondition(new TestRuleWithoutWithAnnotation()), NO_INFO); + } + + @Test + public void conditionNullTest() { + assertEquals(analyzer.getCondition(null), NO_RULE); + } + + @Test + public void nameTest() { + assertEquals(analyzer.getName(new TestRuleWithAnnotation()), "Is String"); + } + + @Test + public void nameNoAnnotationTest() { + assertEquals(analyzer.getName(new TestRuleWithoutWithAnnotation()), "TestRuleWithoutWithAnnotation"); + } + + @Test + public void nameNullTest() { + assertEquals(analyzer.getName(null), NO_RULE); + } + +}