Search in sources :

Example 6 with MockRule

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

the class RuleSetTest method testAddRuleSetByReferenceSingleRule.

@Test
public void testAddRuleSetByReferenceSingleRule() {
    RuleSet set2 = createRuleSetBuilder("ruleset2").withFileName("foo").addRule(new MockRule("name", "desc", "msg", "rulesetname")).addRule(new MockRule("name2", "desc", "msg", "rulesetname")).build();
    RuleSet set1 = createRuleSetBuilder("ruleset1").addRuleSetByReference(set2, false).build();
    assertEquals("wrong rule size", 2, set1.getRules().size());
    for (Rule rule : set1.getRules()) {
        assertTrue("not a rule reference", rule instanceof RuleReference);
        RuleReference ruleReference = (RuleReference) rule;
        assertEquals("wrong ruleset file name", "foo", ruleReference.getRuleSetReference().getRuleSetFileName());
        assertFalse("should not be all rule reference", ruleReference.getRuleSetReference().isAllRules());
    }
}
Also used : RuleReference(net.sourceforge.pmd.lang.rule.RuleReference) MockRule(net.sourceforge.pmd.lang.rule.MockRule) MockRule(net.sourceforge.pmd.lang.rule.MockRule) Test(org.junit.Test)

Example 7 with MockRule

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

the class RuleSetTest method testAddRuleSetByReferenceBad.

@Test(expected = RuntimeException.class)
public void testAddRuleSetByReferenceBad() {
    RuleSet set1 = createRuleSetBuilder("ruleset1").addRule(new MockRule("name", "desc", "msg", "rulesetname")).build();
    createRuleSetBuilder("ruleset2").addRule(new MockRule("name2", "desc", "msg", "rulesetname")).addRuleSetByReference(set1, false).build();
}
Also used : MockRule(net.sourceforge.pmd.lang.rule.MockRule) Test(org.junit.Test)

Example 8 with MockRule

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

the class RuleSetTest method testAddRuleSet.

@Test
public void testAddRuleSet() {
    RuleSet set1 = createRuleSetBuilder("ruleset1").addRule(new MockRule("name", "desc", "msg", "rulesetname")).build();
    RuleSet set2 = createRuleSetBuilder("ruleset2").addRule(new MockRule("name2", "desc", "msg", "rulesetname")).addRuleSet(set1).build();
    assertEquals("ruleset size wrong", 2, set2.size());
}
Also used : MockRule(net.sourceforge.pmd.lang.rule.MockRule) Test(org.junit.Test)

Example 9 with MockRule

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

the class RuleSetTest method testGetRuleByName.

@Test
public void testGetRuleByName() {
    MockRule mock = new MockRule("name", "desc", "msg", "rulesetname");
    RuleSet rs = new RuleSetFactory().createSingleRuleRuleSet(mock);
    assertEquals("unable to fetch rule by name", mock, rs.getRuleByName("name"));
}
Also used : MockRule(net.sourceforge.pmd.lang.rule.MockRule) Test(org.junit.Test)

Example 10 with MockRule

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

the class RuleSetTest method testNoDFA.

@Test
public void testNoDFA() {
    MockRule mock = new MockRule("name", "desc", "msg", "rulesetname");
    mock.setLanguage(LanguageRegistry.getLanguage(DummyLanguageModule.NAME));
    RuleSet rs = new RuleSetFactory().createSingleRuleRuleSet(mock);
    assertFalse(rs.usesDFA(LanguageRegistry.getLanguage(DummyLanguageModule.NAME)));
}
Also used : MockRule(net.sourceforge.pmd.lang.rule.MockRule) Test(org.junit.Test)

Aggregations

MockRule (net.sourceforge.pmd.lang.rule.MockRule)25 Test (org.junit.Test)24 DummyNode (net.sourceforge.pmd.lang.ast.DummyNode)10 ParametricRuleViolation (net.sourceforge.pmd.lang.rule.ParametricRuleViolation)7 RuleReference (net.sourceforge.pmd.lang.rule.RuleReference)6 Node (net.sourceforge.pmd.lang.ast.Node)5 StringProperty (net.sourceforge.pmd.properties.StringProperty)3 Renderer (net.sourceforge.pmd.renderers.Renderer)2 XMLRenderer (net.sourceforge.pmd.renderers.XMLRenderer)2 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 XPathRule (net.sourceforge.pmd.lang.rule.XPathRule)1 RuleFactory (net.sourceforge.pmd.rules.RuleFactory)1 Metric (net.sourceforge.pmd.stat.Metric)1 Ignore (org.junit.Ignore)1 Element (org.w3c.dom.Element)1