Search in sources :

Example 6 with DummyNode

use of net.sourceforge.pmd.lang.ast.DummyNode in project pmd by pmd.

the class AttributeTest method testConstructor.

@Test
public void testConstructor() {
    DummyNode p = new DummyNode(1);
    p.testingOnlySetBeginLine(5);
    Method[] methods = p.getClass().getMethods();
    Method m = null;
    for (int i = 0; i < methods.length; i++) {
        if (methods[i].getName().equals("getBeginLine")) {
            m = methods[i];
            break;
        }
    }
    Attribute a = new Attribute(p, "BeginLine", m);
    assertEquals("BeginLine", a.getName());
    assertEquals(5, a.getValue());
    assertEquals("5", a.getStringValue());
    assertEquals(p, a.getParent());
}
Also used : Attribute(net.sourceforge.pmd.lang.ast.xpath.Attribute) DummyNode(net.sourceforge.pmd.lang.ast.DummyNode) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 7 with DummyNode

use of net.sourceforge.pmd.lang.ast.DummyNode in project pmd by pmd.

the class RuleViolationTest method testComparatorWithSameFileSameLines.

@Ignore
@Test
public void testComparatorWithSameFileSameLines() {
    Rule rule = new MockRule("name", "desc", "msg", "rulesetname");
    RuleViolationComparator comp = RuleViolationComparator.INSTANCE;
    RuleContext ctx = new RuleContext();
    ctx.setSourceCodeFilename("filename");
    DummyNode s = new DummyNode(1);
    s.testingOnlySetBeginLine(10);
    s.testingOnlySetBeginColumn(1);
    DummyNode s1 = new DummyNode(1);
    s1.testingOnlySetBeginLine(10);
    s1.testingOnlySetBeginColumn(1);
    RuleViolation r1 = new ParametricRuleViolation<Node>(rule, ctx, s, "description");
    RuleViolation r2 = new ParametricRuleViolation<Node>(rule, ctx, s1, "description");
    assertEquals(1, comp.compare(r1, r2));
    assertEquals(1, comp.compare(r2, r1));
}
Also used : ParametricRuleViolation(net.sourceforge.pmd.lang.rule.ParametricRuleViolation) DummyNode(net.sourceforge.pmd.lang.ast.DummyNode) MockRule(net.sourceforge.pmd.lang.rule.MockRule) ParametricRuleViolation(net.sourceforge.pmd.lang.rule.ParametricRuleViolation) MockRule(net.sourceforge.pmd.lang.rule.MockRule) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with DummyNode

use of net.sourceforge.pmd.lang.ast.DummyNode in project pmd by pmd.

the class RuleViolationTest method testConstructor2.

@Test
public void testConstructor2() {
    Rule rule = new MockRule("name", "desc", "msg", "rulesetname");
    RuleContext ctx = new RuleContext();
    ctx.setSourceCodeFilename("filename");
    DummyNode s = new DummyNode(1);
    s.testingOnlySetBeginLine(2);
    s.testingOnlySetBeginColumn(1);
    RuleViolation r = new ParametricRuleViolation<Node>(rule, ctx, s, "description");
    assertEquals("object mismatch", rule, r.getRule());
    assertEquals("line number is wrong", 2, r.getBeginLine());
    assertEquals("filename is wrong", "filename", r.getFilename());
    assertEquals("description is wrong", "description", r.getDescription());
}
Also used : ParametricRuleViolation(net.sourceforge.pmd.lang.rule.ParametricRuleViolation) DummyNode(net.sourceforge.pmd.lang.ast.DummyNode) MockRule(net.sourceforge.pmd.lang.rule.MockRule) ParametricRuleViolation(net.sourceforge.pmd.lang.rule.ParametricRuleViolation) MockRule(net.sourceforge.pmd.lang.rule.MockRule) Test(org.junit.Test)

Example 9 with DummyNode

use of net.sourceforge.pmd.lang.ast.DummyNode in project pmd by pmd.

the class XMLRendererTest method createRuleViolation.

private static RuleViolation createRuleViolation(String description) {
    DummyNode node = new DummyNode(1);
    node.testingOnlySetBeginLine(1);
    node.testingOnlySetBeginColumn(1);
    node.testingOnlySetEndLine(1);
    node.testingOnlySetEndColumn(1);
    RuleContext ctx = new RuleContext();
    ctx.setSourceCodeFilename("n/a");
    return new ParametricRuleViolation<Node>(new FooRule(), ctx, node, description);
}
Also used : ParametricRuleViolation(net.sourceforge.pmd.lang.rule.ParametricRuleViolation) FooRule(net.sourceforge.pmd.FooRule) RuleContext(net.sourceforge.pmd.RuleContext) DummyNode(net.sourceforge.pmd.lang.ast.DummyNode)

Example 10 with DummyNode

use of net.sourceforge.pmd.lang.ast.DummyNode in project pmd by pmd.

the class XSLTRendererTest method testDefaultStylesheet.

@Test
public void testDefaultStylesheet() throws Exception {
    XSLTRenderer renderer = new XSLTRenderer();
    Report report = new Report();
    DummyNode node = new DummyNode(1);
    node.testingOnlySetBeginLine(1);
    node.testingOnlySetBeginColumn(1);
    RuleViolation rv = new ParametricRuleViolation<Node>(new FooRule(), new RuleContext(), node, "violation message");
    report.addRuleViolation(rv);
    String result = ReportTest.render(renderer, report);
    Assert.assertTrue(result.contains("violation message"));
}
Also used : ParametricRuleViolation(net.sourceforge.pmd.lang.rule.ParametricRuleViolation) FooRule(net.sourceforge.pmd.FooRule) RuleContext(net.sourceforge.pmd.RuleContext) Report(net.sourceforge.pmd.Report) DummyNode(net.sourceforge.pmd.lang.ast.DummyNode) RuleViolation(net.sourceforge.pmd.RuleViolation) ParametricRuleViolation(net.sourceforge.pmd.lang.rule.ParametricRuleViolation) ReportTest(net.sourceforge.pmd.ReportTest) Test(org.junit.Test)

Aggregations

DummyNode (net.sourceforge.pmd.lang.ast.DummyNode)25 Test (org.junit.Test)17 ParametricRuleViolation (net.sourceforge.pmd.lang.rule.ParametricRuleViolation)13 RuleContext (net.sourceforge.pmd.RuleContext)5 MockRule (net.sourceforge.pmd.lang.rule.MockRule)5 Report (net.sourceforge.pmd.Report)4 Node (net.sourceforge.pmd.lang.ast.Node)4 FooRule (net.sourceforge.pmd.FooRule)3 ReportTest (net.sourceforge.pmd.ReportTest)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Method (java.lang.reflect.Method)1 List (java.util.List)1 RuleViolation (net.sourceforge.pmd.RuleViolation)1 RuleWithProperties (net.sourceforge.pmd.RuleWithProperties)1 RootNode (net.sourceforge.pmd.lang.ast.RootNode)1 Attribute (net.sourceforge.pmd.lang.ast.xpath.Attribute)1 AttributeAxisIterator (net.sourceforge.pmd.lang.ast.xpath.AttributeAxisIterator)1 XPathRule (net.sourceforge.pmd.lang.rule.XPathRule)1 StatisticalRule (net.sourceforge.pmd.lang.rule.stat.StatisticalRule)1