Refactor RuleSet creation
- RuleSet is now immutable - RuleSets are created through a RuleSetBuilder - RuleSetBuilder is accessed solely from RuleSetFactory - RuleSetFactory can now either parse XMLs for rule set creation, or create single rule rulesets
This commit is contained in:
@ -8,15 +8,15 @@ import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.StringReader;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import junit.framework.JUnit4TestAdapter;
|
||||
import net.sourceforge.pmd.lang.LanguageRegistry;
|
||||
import net.sourceforge.pmd.lang.java.JavaLanguageModule;
|
||||
import net.sourceforge.pmd.testframework.RuleTst;
|
||||
import net.sourceforge.pmd.testframework.TestDescriptor;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
public class ExcludeLinesTest extends RuleTst {
|
||||
private Rule rule;
|
||||
@ -41,8 +41,7 @@ import org.junit.Test;
|
||||
ctx.setReport(r);
|
||||
ctx.setSourceCodeFilename("n/a");
|
||||
ctx.setLanguageVersion(LanguageRegistry.getLanguage(JavaLanguageModule.NAME).getDefaultVersion());
|
||||
RuleSet rules = new RuleSet();
|
||||
rules.addRule(rule);
|
||||
RuleSet rules = new RuleSetFactory().createSingleRuleRuleSet(rule);
|
||||
p.getSourceCodeProcessor().processSourceCode(new StringReader(TEST3), new RuleSets(rules), ctx);
|
||||
assertTrue(r.isEmpty());
|
||||
assertEquals(r.getSuppressedRuleViolations().size(), 1);
|
||||
|
@ -1,34 +0,0 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
package net.sourceforge.pmd.cli;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.PrintStream;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class XPathCLITest {
|
||||
|
||||
@Test
|
||||
public void runXPath() throws Exception {
|
||||
PrintStream oldOut = System.out;
|
||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
System.setOut(new PrintStream(output));
|
||||
|
||||
try {
|
||||
XPathCLI.main(new String[] {
|
||||
"-xpath",
|
||||
"//ClassOrInterfaceDeclaration",
|
||||
"-filename",
|
||||
"src/test/java/net/sourceforge/pmd/cli/XPathCLITest.java"
|
||||
});
|
||||
System.out.flush();
|
||||
} finally {
|
||||
System.setOut(oldOut);
|
||||
}
|
||||
|
||||
Assert.assertTrue(output.toString("UTF-8").startsWith("Match at line "));
|
||||
}
|
||||
}
|
@ -9,11 +9,15 @@ import java.io.StringReader;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import net.sourceforge.pmd.PMD;
|
||||
import net.sourceforge.pmd.PropertyDescriptor;
|
||||
import net.sourceforge.pmd.Report;
|
||||
import net.sourceforge.pmd.RuleContext;
|
||||
import net.sourceforge.pmd.RuleSet;
|
||||
import net.sourceforge.pmd.RuleSetFactory;
|
||||
import net.sourceforge.pmd.RuleSets;
|
||||
import net.sourceforge.pmd.RuleViolation;
|
||||
import net.sourceforge.pmd.lang.LanguageRegistry;
|
||||
@ -30,9 +34,6 @@ import net.sourceforge.pmd.lang.rule.xpath.SaxonXPathRuleQuery;
|
||||
import net.sourceforge.pmd.lang.rule.xpath.XPathRuleQuery;
|
||||
import net.sourceforge.pmd.testframework.RuleTst;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author daniels
|
||||
*/
|
||||
@ -56,8 +57,7 @@ import org.junit.Test;
|
||||
Report report = new Report();
|
||||
ctx.setReport(report);
|
||||
ctx.setSourceCodeFilename("n/a");
|
||||
RuleSet rules = new RuleSet();
|
||||
rules.addRule(rule);
|
||||
RuleSet rules = new RuleSetFactory().createSingleRuleRuleSet(rule);
|
||||
p.getSourceCodeProcessor().processSourceCode(new StringReader(TEST1), new RuleSets(rules), ctx);
|
||||
RuleViolation rv = report.iterator().next();
|
||||
assertEquals("a", rv.getDescription());
|
||||
@ -75,8 +75,7 @@ import org.junit.Test;
|
||||
Report report = new Report();
|
||||
ctx.setReport(report);
|
||||
ctx.setSourceCodeFilename("n/a");
|
||||
RuleSet rules = new RuleSet();
|
||||
rules.addRule(rule);
|
||||
RuleSet rules = new RuleSetFactory().createSingleRuleRuleSet(rule);
|
||||
p.getSourceCodeProcessor().processSourceCode(new StringReader(TEST2), new RuleSets(rules), ctx);
|
||||
RuleViolation rv = report.iterator().next();
|
||||
assertEquals(3, rv.getBeginLine());
|
||||
|
Reference in New Issue
Block a user