forked from phoedos/pmd
Add JUnit test to validate output
This commit is contained in:
@ -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);
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user