From 5d51df880a68ff051b3808180aef7e2905a79786 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Mart=C3=ADn=20Sotuyo=20Dodero?= Date: Sat, 30 Sep 2017 18:37:04 -0300 Subject: [PATCH] Add JUnit test to validate output --- .../pmd/renderers/AbstractRendererTst.java | 2 +- .../renderers/CodeClimateRendererTest.java | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/renderers/AbstractRendererTst.java b/pmd-core/src/test/java/net/sourceforge/pmd/renderers/AbstractRendererTst.java index 2414966842..f0e2b96773 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/renderers/AbstractRendererTst.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/renderers/AbstractRendererTst.java @@ -75,7 +75,7 @@ public abstract class AbstractRendererTst { return new ParametricRuleViolation(new FooRule(), ctx, node, "blah"); } - private static DummyNode createNode(int endColumn) { + protected static DummyNode createNode(int endColumn) { DummyNode node = new DummyNode(1); node.testingOnlySetBeginLine(1); node.testingOnlySetBeginColumn(1); diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/renderers/CodeClimateRendererTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/renderers/CodeClimateRendererTest.java index ac5dcd5833..2962a3d371 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/renderers/CodeClimateRendererTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/renderers/CodeClimateRendererTest.java @@ -4,7 +4,18 @@ package net.sourceforge.pmd.renderers; +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + import net.sourceforge.pmd.PMD; +import net.sourceforge.pmd.Report; +import net.sourceforge.pmd.ReportTest; +import net.sourceforge.pmd.RuleContext; +import net.sourceforge.pmd.lang.ast.DummyNode; +import net.sourceforge.pmd.lang.ast.Node; +import net.sourceforge.pmd.lang.rule.ParametricRuleViolation; +import net.sourceforge.pmd.lang.rule.XPathRule; public class CodeClimateRendererTest extends AbstractRendererTst { @@ -74,4 +85,24 @@ public class CodeClimateRendererTest extends AbstractRendererTst { + "\"},\"categories\":[\"Style\"],\"location\":{\"path\":\"n/a\",\"lines\":{\"begin\":1,\"end\":1}},\"severity\":\"info\",\"remediation_points\":50000}" + "\u0000" + PMD.EOL; } + + @Test + public void testXPathRule() throws Exception { + DummyNode node = createNode(1); + RuleContext ctx = new RuleContext(); + ctx.setSourceCodeFilename(getSourceCodeFilename()); + Report report = new Report(); + XPathRule theRule = new XPathRule(); + theRule.setProperty(XPathRule.XPATH_DESCRIPTOR, "//dummyNode"); + + // Setup as FooRule + theRule.setDescription("desc"); + theRule.setName("Foo"); + + report.addRuleViolation(new ParametricRuleViolation(theRule, ctx, node, "blah")); + String rendered = ReportTest.render(getRenderer(), report); + + // Output should be the exact same as for non xpath rules + assertEquals(filter(getExpected()), filter(rendered)); + } }