Search in sources :

Example 1 with ParametricRuleViolation

use of net.sourceforge.pmd.lang.rule.ParametricRuleViolation in project pmd by pmd.

the class AbstractRuleTest method testCreateRV.

@Test
public void testCreateRV() {
    MyRule r = new MyRule();
    r.setRuleSetName("foo");
    RuleContext ctx = new RuleContext();
    ctx.setSourceCodeFilename("filename");
    DummyNode s = new DummyNode(1);
    s.testingOnlySetBeginColumn(5);
    s.testingOnlySetBeginLine(5);
    RuleViolation rv = new ParametricRuleViolation(r, ctx, s, r.getMessage());
    assertEquals("Line number mismatch!", 5, rv.getBeginLine());
    assertEquals("Filename mismatch!", "filename", rv.getFilename());
    assertEquals("Rule object mismatch!", r, rv.getRule());
    assertEquals("Rule msg mismatch!", "my rule msg", rv.getDescription());
    assertEquals("RuleSet name mismatch!", "foo", rv.getRule().getRuleSetName());
}
Also used : ParametricRuleViolation(net.sourceforge.pmd.lang.rule.ParametricRuleViolation) DummyNode(net.sourceforge.pmd.lang.ast.DummyNode) ParametricRuleViolation(net.sourceforge.pmd.lang.rule.ParametricRuleViolation) Test(org.junit.Test)

Example 2 with ParametricRuleViolation

use of net.sourceforge.pmd.lang.rule.ParametricRuleViolation in project pmd by pmd.

the class AbstractRuleTest method testCreateRV2.

@Test
public void testCreateRV2() {
    MyRule r = new MyRule();
    RuleContext ctx = new RuleContext();
    ctx.setSourceCodeFilename("filename");
    DummyNode s = new DummyNode(1);
    s.testingOnlySetBeginColumn(5);
    s.testingOnlySetBeginLine(5);
    RuleViolation rv = new ParametricRuleViolation(r, ctx, s, "specificdescription");
    assertEquals("Line number mismatch!", 5, rv.getBeginLine());
    assertEquals("Filename mismatch!", "filename", rv.getFilename());
    assertEquals("Rule object mismatch!", r, rv.getRule());
    assertEquals("Rule description mismatch!", "specificdescription", rv.getDescription());
}
Also used : ParametricRuleViolation(net.sourceforge.pmd.lang.rule.ParametricRuleViolation) DummyNode(net.sourceforge.pmd.lang.ast.DummyNode) ParametricRuleViolation(net.sourceforge.pmd.lang.rule.ParametricRuleViolation) Test(org.junit.Test)

Example 3 with ParametricRuleViolation

use of net.sourceforge.pmd.lang.rule.ParametricRuleViolation 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 4 with ParametricRuleViolation

use of net.sourceforge.pmd.lang.rule.ParametricRuleViolation 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 5 with ParametricRuleViolation

use of net.sourceforge.pmd.lang.rule.ParametricRuleViolation 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)

Aggregations

ParametricRuleViolation (net.sourceforge.pmd.lang.rule.ParametricRuleViolation)14 DummyNode (net.sourceforge.pmd.lang.ast.DummyNode)13 Test (org.junit.Test)10 MockRule (net.sourceforge.pmd.lang.rule.MockRule)6 FooRule (net.sourceforge.pmd.FooRule)4 RuleContext (net.sourceforge.pmd.RuleContext)4 HashMap (java.util.HashMap)2 Report (net.sourceforge.pmd.Report)2 Node (net.sourceforge.pmd.lang.ast.Node)2 ReportTest (net.sourceforge.pmd.ReportTest)1 RuleViolation (net.sourceforge.pmd.RuleViolation)1 Ignore (org.junit.Ignore)1