use of net.sourceforge.pmd.lang.rule.MockRule in project pmd by pmd.
the class RuleSetTest method testRuleList.
@Test
public void testRuleList() {
MockRule rule = new MockRule("name", "desc", "msg", "rulesetname");
RuleSet ruleset = new RuleSetFactory().createSingleRuleRuleSet(rule);
assertEquals("Size of RuleSet isn't one.", 1, ruleset.size());
Collection<Rule> rules = ruleset.getRules();
Iterator<Rule> i = rules.iterator();
assertTrue("Empty Set", i.hasNext());
assertEquals("Returned set of wrong size.", 1, rules.size());
assertEquals("Rule isn't in ruleset.", rule, i.next());
}
use of net.sourceforge.pmd.lang.rule.MockRule in project pmd by pmd.
the class RuleSetTest method testLanguageApplies.
@Test
public void testLanguageApplies() {
Rule rule = new MockRule();
rule.setLanguage(LanguageRegistry.getLanguage(DummyLanguageModule.NAME));
assertFalse("Different languages should not apply", RuleSet.applies(rule, LanguageRegistry.getLanguage(Dummy2LanguageModule.NAME).getDefaultVersion()));
rule.setLanguage(LanguageRegistry.getLanguage(DummyLanguageModule.NAME));
assertTrue("Same language with no min/max should apply", RuleSet.applies(rule, LanguageRegistry.getLanguage(DummyLanguageModule.NAME).getVersion("1.5")));
rule.setMinimumLanguageVersion(LanguageRegistry.getLanguage(DummyLanguageModule.NAME).getVersion("1.5"));
assertTrue("Same language with valid min only should apply", RuleSet.applies(rule, LanguageRegistry.getLanguage(DummyLanguageModule.NAME).getVersion("1.5")));
rule.setMaximumLanguageVersion(LanguageRegistry.getLanguage(DummyLanguageModule.NAME).getVersion("1.6"));
assertTrue("Same language with valid min and max should apply", RuleSet.applies(rule, LanguageRegistry.getLanguage(DummyLanguageModule.NAME).getVersion("1.5")));
assertFalse("Same language with outside range of min/max should not apply", RuleSet.applies(rule, LanguageRegistry.getLanguage(DummyLanguageModule.NAME).getVersion("1.4")));
assertFalse("Same language with outside range of min/max should not apply", RuleSet.applies(rule, LanguageRegistry.getLanguage(DummyLanguageModule.NAME).getVersion("1.7")));
}
use of net.sourceforge.pmd.lang.rule.MockRule 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));
}
use of net.sourceforge.pmd.lang.rule.MockRule 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());
}
use of net.sourceforge.pmd.lang.rule.MockRule in project pmd by pmd.
the class ReportTest method testSummary.
@Test
public void testSummary() {
Report r = new Report();
RuleContext ctx = new RuleContext();
ctx.setSourceCodeFilename("foo1");
Node s = getNode(5, 5);
Rule rule = new MockRule("name", "desc", "msg", "rulesetname");
r.addRuleViolation(new ParametricRuleViolation<>(rule, ctx, s, rule.getMessage()));
ctx.setSourceCodeFilename("foo2");
Rule mr = new MockRule("rule1", "rule1", "msg", "rulesetname");
Node s1 = getNode(20, 5);
Node s2 = getNode(30, 5);
r.addRuleViolation(new ParametricRuleViolation<>(mr, ctx, s1, mr.getMessage()));
r.addRuleViolation(new ParametricRuleViolation<>(mr, ctx, s2, mr.getMessage()));
Map<String, Integer> summary = r.getSummary();
assertEquals(summary.keySet().size(), 2);
assertTrue(summary.values().contains(Integer.valueOf(1)));
assertTrue(summary.values().contains(Integer.valueOf(2)));
}
Aggregations