Move MockRule into test sources
This commit is contained in:
@ -36,7 +36,6 @@ import org.xml.sax.SAXException;
|
||||
import net.sourceforge.pmd.RuleSet.RuleSetBuilder;
|
||||
import net.sourceforge.pmd.lang.Language;
|
||||
import net.sourceforge.pmd.lang.LanguageRegistry;
|
||||
import net.sourceforge.pmd.lang.rule.MockRule;
|
||||
import net.sourceforge.pmd.lang.rule.RuleReference;
|
||||
import net.sourceforge.pmd.lang.rule.XPathRule;
|
||||
import net.sourceforge.pmd.rules.RuleFactory;
|
||||
@ -697,13 +696,6 @@ public class RuleSetFactory {
|
||||
+ ". PMD " + PMDVersion.getNextMajorRelease()
|
||||
+ " will remove support for this deprecated Rule name usage.");
|
||||
}
|
||||
} else if (referencedRule instanceof MockRule) {
|
||||
if (LOG.isLoggable(Level.WARNING)) {
|
||||
LOG.warning("Discontinue using Rule name " + otherRuleSetReferenceId
|
||||
+ " as it has been removed from PMD and no longer functions."
|
||||
+ " PMD " + PMDVersion.getNextMajorRelease()
|
||||
+ " will remove support for this Rule.");
|
||||
}
|
||||
} else {
|
||||
if (LOG.isLoggable(Level.WARNING)) {
|
||||
LOG.warning("Discontinue using Rule name " + otherRuleSetReferenceId
|
||||
|
@ -31,16 +31,18 @@ import net.sourceforge.pmd.Report.ProcessingError;
|
||||
import net.sourceforge.pmd.RuleSet.RuleSetBuilder;
|
||||
import net.sourceforge.pmd.lang.Dummy2LanguageModule;
|
||||
import net.sourceforge.pmd.lang.DummyLanguageModule;
|
||||
import net.sourceforge.pmd.lang.Language;
|
||||
import net.sourceforge.pmd.lang.LanguageRegistry;
|
||||
import net.sourceforge.pmd.lang.ast.DummyNode;
|
||||
import net.sourceforge.pmd.lang.ast.DummyRoot;
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
import net.sourceforge.pmd.lang.rule.MockRule;
|
||||
import net.sourceforge.pmd.lang.rule.RuleReference;
|
||||
import net.sourceforge.pmd.lang.rule.RuleTargetSelector;
|
||||
|
||||
public class RuleSetTest {
|
||||
|
||||
private final Language dummyLang = LanguageRegistry.getLanguage(DummyLanguageModule.NAME);
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void testRuleSetRequiresName() {
|
||||
new RuleSetBuilder(new Random().nextLong())
|
||||
@ -169,7 +171,7 @@ public class RuleSetTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApply0Rules() throws Exception {
|
||||
public void testApply0Rules() {
|
||||
RuleSet ruleset = createRuleSetBuilder("ruleset").build();
|
||||
verifyRuleSet(ruleset, 0, new HashSet<RuleViolation>());
|
||||
}
|
||||
@ -241,25 +243,23 @@ public class RuleSetTest {
|
||||
|
||||
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")));
|
||||
RuleSet.applies(rule, dummyLang.getVersion("1.5")));
|
||||
|
||||
rule.setMinimumLanguageVersion(LanguageRegistry.getLanguage(DummyLanguageModule.NAME).getVersion("1.5"));
|
||||
rule.setMinimumLanguageVersion(dummyLang.getVersion("1.5"));
|
||||
assertTrue("Same language with valid min only should apply",
|
||||
RuleSet.applies(rule, LanguageRegistry.getLanguage(DummyLanguageModule.NAME).getVersion("1.5")));
|
||||
RuleSet.applies(rule, dummyLang.getVersion("1.5")));
|
||||
|
||||
rule.setMaximumLanguageVersion(LanguageRegistry.getLanguage(DummyLanguageModule.NAME).getVersion("1.6"));
|
||||
rule.setMaximumLanguageVersion(dummyLang.getVersion("1.6"));
|
||||
assertTrue("Same language with valid min and max should apply",
|
||||
RuleSet.applies(rule, LanguageRegistry.getLanguage(DummyLanguageModule.NAME).getVersion("1.5")));
|
||||
RuleSet.applies(rule, dummyLang.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")));
|
||||
RuleSet.applies(rule, dummyLang.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")));
|
||||
RuleSet.applies(rule, dummyLang.getVersion("1.7")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -404,7 +404,6 @@ public class RuleSetTest {
|
||||
|
||||
Rule rule = new FooRule();
|
||||
rule.setName("FooRule1");
|
||||
rule.setLanguage(LanguageRegistry.getLanguage(DummyLanguageModule.NAME));
|
||||
RuleSet ruleSet1 = createRuleSetBuilder("RuleSet1")
|
||||
.addRule(rule)
|
||||
.build();
|
||||
@ -420,7 +419,7 @@ public class RuleSetTest {
|
||||
Report r = new Report();
|
||||
ctx.setReport(r);
|
||||
ctx.setSourceCodeFile(file);
|
||||
ctx.setLanguageVersion(LanguageRegistry.getLanguage(DummyLanguageModule.NAME).getDefaultVersion());
|
||||
ctx.setLanguageVersion(dummyLang.getDefaultVersion());
|
||||
ruleSets.apply(makeCompilationUnits(), ctx);
|
||||
assertEquals("Violations", 2, r.getViolations().size());
|
||||
|
||||
@ -442,7 +441,6 @@ public class RuleSetTest {
|
||||
public void copyConstructorDeepCopies() {
|
||||
Rule rule = new FooRule();
|
||||
rule.setName("FooRule1");
|
||||
rule.setLanguage(LanguageRegistry.getLanguage(DummyLanguageModule.NAME));
|
||||
RuleSet ruleSet1 = createRuleSetBuilder("RuleSet1")
|
||||
.addRule(rule)
|
||||
.build();
|
||||
@ -495,7 +493,7 @@ public class RuleSetTest {
|
||||
.build();
|
||||
RuleContext context = new RuleContext();
|
||||
context.setReport(new Report());
|
||||
context.setLanguageVersion(LanguageRegistry.getLanguage(DummyLanguageModule.NAME).getDefaultVersion());
|
||||
context.setLanguageVersion(dummyLang.getDefaultVersion());
|
||||
context.setSourceCodeFile(new File(RuleSetTest.class.getName() + ".ruleExceptionShouldBeReported"));
|
||||
context.setIgnoreExceptions(true); // the default
|
||||
ruleset.apply(makeCompilationUnits(), context);
|
||||
@ -519,7 +517,7 @@ public class RuleSetTest {
|
||||
.build();
|
||||
RuleContext context = new RuleContext();
|
||||
context.setReport(new Report());
|
||||
context.setLanguageVersion(LanguageRegistry.getLanguage(DummyLanguageModule.NAME).getDefaultVersion());
|
||||
context.setLanguageVersion(dummyLang.getDefaultVersion());
|
||||
context.setSourceCodeFile(new File(RuleSetTest.class.getName() + ".ruleExceptionShouldBeThrownIfNotIgnored"));
|
||||
context.setIgnoreExceptions(false);
|
||||
ruleset.apply(makeCompilationUnits(), context);
|
||||
@ -540,7 +538,7 @@ public class RuleSetTest {
|
||||
}).build();
|
||||
RuleContext context = new RuleContext();
|
||||
context.setReport(new Report());
|
||||
context.setLanguageVersion(LanguageRegistry.getLanguage(DummyLanguageModule.NAME).getDefaultVersion());
|
||||
context.setLanguageVersion(dummyLang.getDefaultVersion());
|
||||
context.setSourceCodeFile(new File(RuleSetTest.class.getName() + ".ruleExceptionShouldBeReported"));
|
||||
context.setIgnoreExceptions(true); // the default
|
||||
ruleset.apply(makeCompilationUnits(), context);
|
||||
@ -581,7 +579,7 @@ public class RuleSetTest {
|
||||
}).build();
|
||||
RuleContext context = new RuleContext();
|
||||
context.setReport(new Report());
|
||||
context.setLanguageVersion(LanguageRegistry.getLanguage(DummyLanguageModule.NAME).getDefaultVersion());
|
||||
context.setLanguageVersion(dummyLang.getDefaultVersion());
|
||||
context.setSourceCodeFile(new File(RuleSetTest.class.getName() + ".ruleExceptionShouldBeReported"));
|
||||
context.setIgnoreExceptions(true); // the default
|
||||
RuleSets rulesets = new RuleSets(ruleset);
|
||||
@ -595,4 +593,24 @@ public class RuleSetTest {
|
||||
assertEquals("There should be a violation", 1, context.getReport().getViolations().size());
|
||||
}
|
||||
|
||||
|
||||
class MockRule extends net.sourceforge.pmd.lang.rule.MockRule {
|
||||
|
||||
MockRule() {
|
||||
super();
|
||||
setLanguage(dummyLang);
|
||||
}
|
||||
|
||||
MockRule(String name, String description, String message, String ruleSetName, RulePriority priority) {
|
||||
super(name, description, message, ruleSetName, priority);
|
||||
setLanguage(dummyLang);
|
||||
}
|
||||
|
||||
MockRule(String name, String description, String message, String ruleSetName) {
|
||||
super(name, description, message, ruleSetName);
|
||||
setLanguage(dummyLang);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/**
|
||||
/*
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
@ -8,7 +8,6 @@ import static net.sourceforge.pmd.properties.constraints.NumericConstraints.inRa
|
||||
|
||||
import net.sourceforge.pmd.RuleContext;
|
||||
import net.sourceforge.pmd.RulePriority;
|
||||
import net.sourceforge.pmd.lang.LanguageRegistry;
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
import net.sourceforge.pmd.properties.PropertyFactory;
|
||||
|
||||
@ -18,17 +17,11 @@ import net.sourceforge.pmd.properties.PropertyFactory;
|
||||
* functional Rule is not needed. For example, during unit testing, or as an
|
||||
* editable surrogate used by IDE plugins. The Language of this Rule defaults to
|
||||
* Java.
|
||||
*
|
||||
* @deprecated This is not a supported API. You need the pmd-test module
|
||||
* on your classpath, or pmd-core's test sources. This will be removed
|
||||
* in 7.0.0
|
||||
*/
|
||||
@Deprecated
|
||||
public class MockRule extends AbstractRule {
|
||||
|
||||
public MockRule() {
|
||||
super();
|
||||
setLanguage(LanguageRegistry.getLanguage("Dummy"));
|
||||
definePropertyDescriptor(PropertyFactory.intProperty("testIntProperty").desc("testIntProperty").require(inRange(1, 100)).defaultValue(1).build());
|
||||
}
|
||||
|
Reference in New Issue
Block a user