Search in sources :

Example 11 with DummyNode

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

the class StatisticalRuleTest method testSingleDatapoint.

// Test Single Datapoint
@Test
public void testSingleDatapoint() {
    StatisticalRule rule = new MockStatisticalRule();
    DataPoint point = new DataPoint();
    point.setScore(POINTS + 1.0);
    DummyNode s = new DummyNode(1);
    s.testingOnlySetBeginLine(POINTS + 1);
    s.testingOnlySetBeginColumn(1);
    point.setNode(s);
    point.setMessage("SingleDataPoint");
    rule.setProperty(MINIMUM_DESCRIPTOR, (double) POINTS);
    rule.addDataPoint(point);
    Report report = makeReport(rule);
    assertEquals("Expecting only one result", 1, report.size());
}
Also used : StatisticalRule(net.sourceforge.pmd.lang.rule.stat.StatisticalRule) Report(net.sourceforge.pmd.Report) DummyNode(net.sourceforge.pmd.lang.ast.DummyNode) Test(org.junit.Test)

Example 12 with DummyNode

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

the class CodeClimateRendererTest method testXPathRule.

@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));
}
Also used : RuleContext(net.sourceforge.pmd.RuleContext) Report(net.sourceforge.pmd.Report) DummyNode(net.sourceforge.pmd.lang.ast.DummyNode) DummyNode(net.sourceforge.pmd.lang.ast.DummyNode) Node(net.sourceforge.pmd.lang.ast.Node) XPathRule(net.sourceforge.pmd.lang.rule.XPathRule) ReportTest(net.sourceforge.pmd.ReportTest) Test(org.junit.Test)

Example 13 with DummyNode

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

the class AbstractRendererTst method newRuleViolation.

private RuleViolation newRuleViolation(int endColumn) {
    DummyNode node = createNode(endColumn);
    RuleContext ctx = new RuleContext();
    ctx.setSourceCodeFilename(getSourceCodeFilename());
    return new ParametricRuleViolation<Node>(new FooRule(), ctx, node, "blah");
}
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 14 with DummyNode

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

the class StatisticalRuleTest method setUp.

@Before
public void setUp() {
    ruleUnderTest = new MockStatisticalRule();
    if (testName.endsWith("0")) {
        for (int i = 0; i < POINTS; i++) {
            points[i] = new DataPoint();
            points[i].setScore(1.0 * i);
            DummyNode s = new DummyNode(1);
            s.testingOnlySetBeginLine(i);
            s.testingOnlySetBeginColumn(1);
            points[i].setNode(s);
            points[i].setMessage("DataPoint[" + Integer.toString(i) + "]");
            ruleUnderTest.addDataPoint(points[i]);
        }
    } else if (testName.endsWith("1")) {
        for (int i = POINTS - 1; i >= 0; i--) {
            points[i] = new DataPoint();
            points[i].setScore(1.0 * i);
            DummyNode s = new DummyNode(1);
            s.testingOnlySetBeginLine(i);
            s.testingOnlySetBeginColumn(1);
            points[i].setNode(s);
            points[i].setMessage("DataPoint[" + Integer.toString(i) + "]");
            ruleUnderTest.addDataPoint(points[i]);
        }
    } else {
        List<DataPoint> lPoints = new ArrayList<>();
        for (int i = 0; i < POINTS; i++) {
            points[i] = new DataPoint();
            points[i].setScore(1.0 * i);
            DummyNode s = new DummyNode(1);
            s.testingOnlySetBeginLine(i);
            s.testingOnlySetBeginColumn(1);
            s.testingOnlySetBeginColumn(1);
            points[i].setNode(s);
            points[i].setMessage("DataPoint[" + Integer.toString(i) + "]");
            lPoints.add(points[i]);
        }
        Collections.shuffle(lPoints);
        for (int i = 0; i < POINTS; i++) {
            ruleUnderTest.addDataPoint(lPoints.get(i));
        }
    }
}
Also used : DummyNode(net.sourceforge.pmd.lang.ast.DummyNode) ArrayList(java.util.ArrayList) List(java.util.List) Before(org.junit.Before)

Example 15 with DummyNode

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

the class ReportTest method getNode.

private static Node getNode(int line, int column) {
    DummyNode s = new DummyNode(2);
    DummyNode parent = new DummyNode(1);
    parent.testingOnlySetBeginLine(line);
    parent.testingOnlySetBeginColumn(column);
    s.jjtSetParent(parent);
    s.testingOnlySetBeginLine(10);
    s.testingOnlySetBeginColumn(5);
    return s;
}
Also used : DummyNode(net.sourceforge.pmd.lang.ast.DummyNode)

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