View Javadoc
1 /*** 2 * BSD-style license; for more info see http://pmd.sourceforge.net/license.html 3 */ 4 package test.net.sourceforge.pmd.testframework; 5 6 import junit.framework.TestCase; 7 import net.sourceforge.pmd.PMD; 8 import net.sourceforge.pmd.Report; 9 import net.sourceforge.pmd.Rule; 10 import net.sourceforge.pmd.RuleContext; 11 import net.sourceforge.pmd.RuleSet; 12 13 import java.io.StringReader; 14 15 public class RuleTst extends TestCase { 16 17 public void runTestFromString(String code, int expectedResults, Rule rule) throws Throwable { 18 assertEquals(expectedResults, processUsingStringReader(code, rule).size()); 19 } 20 21 public void runTestFromString(String code, Rule rule, Report report) throws Throwable { 22 PMD p = new PMD(); 23 RuleContext ctx = new RuleContext(); 24 ctx.setReport(report); 25 ctx.setSourceCodeFilename("n/a"); 26 RuleSet rules = new RuleSet(); 27 rules.addRule(rule); 28 p.processFile(new StringReader(code), rules, ctx); 29 } 30 31 private Report processUsingStringReader(String code, Rule rule) throws Throwable { 32 Report report = new Report(); 33 runTestFromString(code, rule, report); 34 return report; 35 } 36 }

This page was automatically generated by Maven