From db1b92ef34644ae4f73400e64e71d25188cf25bf Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Mon, 12 Oct 2015 00:08:45 +1100 Subject: [PATCH] Tests for boolean expression checker --- .../cflint/TestBooleanExpressionChecker.java | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/test/java/com/cflint/TestBooleanExpressionChecker.java diff --git a/src/test/java/com/cflint/TestBooleanExpressionChecker.java b/src/test/java/com/cflint/TestBooleanExpressionChecker.java new file mode 100644 index 000000000..1f5def938 --- /dev/null +++ b/src/test/java/com/cflint/TestBooleanExpressionChecker.java @@ -0,0 +1,65 @@ +package com.cflint; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.util.List; + +import org.junit.Before; +import org.junit.Test; + +import cfml.parsing.reporting.ParseException; + +import com.cflint.config.CFLintPluginInfo.PluginInfoRule; +import com.cflint.config.CFLintPluginInfo.PluginInfoRule.PluginMessage; +import com.cflint.config.ConfigRuntime; +import com.cflint.plugins.core.BooleanExpressionChecker; + +public class TestBooleanExpressionChecker { + + private CFLint cfBugs; + + @Before + public void setUp() { + final ConfigRuntime conf = new ConfigRuntime(); + final PluginInfoRule pluginRule = new PluginInfoRule(); + pluginRule.setName("BooleanExpressionChecker"); + conf.getRules().add(pluginRule); + final PluginMessage pluginMessage = new PluginMessage("EXPLICIT_BOOLEAN_CHECK"); + pluginMessage.setSeverity("INFO"); + cfBugs = new CFLint(conf, new BooleanExpressionChecker()); + } + + @Test + public void testBooleanExpressionInScript() throws ParseException, IOException { + final String scriptSrc = "\r\n" + + "if (a && b == true) {\r\n" + + " c = 1;\r\n" + + "}\r\n" + + "else if (a or b is false) {\r\n" + + " c = 1;\r\n" + + "}\r\n" + + ""; + + cfBugs.process(scriptSrc, "test"); + final List result = cfBugs.getBugs().getBugList().values().iterator().next(); + assertEquals(2, result.size()); + assertEquals("EXPLICIT_BOOLEAN_CHECK", result.get(0).getMessageCode()); + assertEquals(2, result.get(0).getLine()); + assertEquals("EXPLICIT_BOOLEAN_CHECK", result.get(1).getMessageCode()); + assertEquals(5, result.get(1).getLine()); + } + + @Test + public void testBooleanExpressionInTag() throws ParseException, IOException { + final String tagSrc = "\r\n" + + ""; + + cfBugs.process(tagSrc, "test"); + final List result = cfBugs.getBugs().getBugList().values().iterator().next(); + assertEquals(1, result.size()); + assertEquals("EXPLICIT_BOOLEAN_CHECK", result.get(0).getMessageCode()); + assertEquals(2, result.get(0).getLine()); + } + +}