Merge branch 'checksum-aware' of https://github.com/Monits/pmd into pr-145

This commit is contained in:
Andreas Dangel
2016-12-23 18:21:50 +01:00
14 changed files with 599 additions and 618 deletions
@@ -32,7 +32,7 @@ public class ExcludeLinesTest extends RuleTst {
}
@Test
public void testAlternateMarker() throws PMDException {
public void testAlternateMarker() throws Exception {
PMD p = new PMD();
p.getConfiguration().setSuppressMarker("FOOBAR");
RuleContext ctx = new RuleContext();
@@ -40,8 +40,7 @@ public class ExcludeLinesTest extends RuleTst {
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,31 +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 "));
}
}
@@ -14,11 +14,11 @@ import org.junit.Before;
import org.junit.Test;
import net.sourceforge.pmd.PMD;
import net.sourceforge.pmd.PMDException;
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;
@@ -50,7 +50,7 @@ public class XPathRuleTest extends RuleTst {
}
@Test
public void testPluginname() throws PMDException {
public void testPluginname() throws Exception {
rule.setXPath("//VariableDeclaratorId[string-length(@Image) < 3]");
rule.setMessage("{0}");
PMD p = new PMD();
@@ -58,15 +58,14 @@ public class XPathRuleTest extends RuleTst {
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());
}
@Test
public void testVariables() throws PMDException {
public void testVariables() throws Exception {
rule.setXPath("//VariableDeclaratorId[@Image=$var]");
rule.setMessage("Avoid vars");
StringProperty varDescriptor = new StringProperty("var", "Test var", null, 1.0f);
@@ -77,8 +76,7 @@ public class XPathRuleTest extends RuleTst {
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());