Add JUnit test to validate output

This commit is contained in:
Juan Martín Sotuyo Dodero
2017-09-30 18:37:04 -03:00
parent a4c1150891
commit 5d51df880a
2 changed files with 32 additions and 1 deletions

View File

@ -75,7 +75,7 @@ public abstract class AbstractRendererTst {
return new ParametricRuleViolation<Node>(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);

View File

@ -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<Node>(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));
}
}