use of net.sourceforge.pmd.lang.rule.MockRule in project pmd by pmd.
the class ReportTest method testSortedReportLine.
@Test
public void testSortedReportLine() throws IOException {
Report r = new Report();
RuleContext ctx = new RuleContext();
ctx.setSourceCodeFilename("foo1");
Node s = getNode(10, 5);
Rule rule1 = new MockRule("rule2", "rule2", "msg", "rulesetname");
r.addRuleViolation(new ParametricRuleViolation<>(rule1, ctx, s, rule1.getMessage()));
ctx.setSourceCodeFilename("foo2");
Node s1 = getNode(20, 5);
Rule rule2 = new MockRule("rule1", "rule1", "msg", "rulesetname");
r.addRuleViolation(new ParametricRuleViolation<>(rule2, ctx, s1, rule2.getMessage()));
Renderer rend = new XMLRenderer();
String result = render(rend, r);
assertTrue("sort order wrong", result.indexOf("rule2") < result.indexOf("rule1"));
}
use of net.sourceforge.pmd.lang.rule.MockRule in project pmd by pmd.
the class ReportTest method testSortedReportFile.
// Files are grouped together now.
@Test
public void testSortedReportFile() throws IOException {
Report r = new Report();
RuleContext ctx = new RuleContext();
ctx.setSourceCodeFilename("foo");
Node s = getNode(10, 5);
Rule rule1 = new MockRule("name", "desc", "msg", "rulesetname");
r.addRuleViolation(new ParametricRuleViolation<>(rule1, ctx, s, rule1.getMessage()));
ctx.setSourceCodeFilename("bar");
Node s1 = getNode(10, 5);
Rule rule2 = new MockRule("name", "desc", "msg", "rulesetname");
r.addRuleViolation(new ParametricRuleViolation<>(rule2, ctx, s1, rule2.getMessage()));
Renderer rend = new XMLRenderer();
String result = render(rend, r);
assertTrue("sort order wrong", result.indexOf("bar") < result.indexOf("foo"));
}
use of net.sourceforge.pmd.lang.rule.MockRule in project pmd by pmd.
the class ReportTest method testTreeIterator.
@Test
public void testTreeIterator() {
Report r = new Report();
RuleContext ctx = new RuleContext();
Rule rule = new MockRule("name", "desc", "msg", "rulesetname");
Node node1 = getNode(5, 5, true);
r.addRuleViolation(new ParametricRuleViolation<>(rule, ctx, node1, rule.getMessage()));
Node node2 = getNode(5, 6, true);
r.addRuleViolation(new ParametricRuleViolation<>(rule, ctx, node2, rule.getMessage()));
Iterator<RuleViolation> violations = r.iterator();
int violationCount = 0;
while (violations.hasNext()) {
violations.next();
violationCount++;
}
assertEquals(2, violationCount);
Iterator<RuleViolation> treeIterator = r.treeIterator();
int treeCount = 0;
while (treeIterator.hasNext()) {
treeIterator.next();
treeCount++;
}
assertEquals(2, treeCount);
}
use of net.sourceforge.pmd.lang.rule.MockRule in project pmd by pmd.
the class RuleSetTest method testIncludesRuleWithDFA.
@Test
public void testIncludesRuleWithDFA() {
MockRule mock = new MockRule("name", "desc", "msg", "rulesetname");
mock.setLanguage(LanguageRegistry.getLanguage(DummyLanguageModule.NAME));
mock.setDfa(true);
RuleSet rs = new RuleSetFactory().createSingleRuleRuleSet(mock);
assertTrue(rs.usesDFA(LanguageRegistry.getLanguage(DummyLanguageModule.NAME)));
}
use of net.sourceforge.pmd.lang.rule.MockRule in project pmd by pmd.
the class RuleSetTest method testGetRuleByName2.
@Test
public void testGetRuleByName2() {
MockRule mock = new MockRule("name", "desc", "msg", "rulesetname");
RuleSet rs = new RuleSetFactory().createSingleRuleRuleSet(mock);
assertNull("the rule FooRule must not be found!", rs.getRuleByName("FooRule"));
}
Aggregations