📄 ruletst.java
字号:
/** * BSD-style license; for more info see http://pmd.sourceforge.net/license.html*/package test.net.sourceforge.pmd.testframework;import junit.framework.TestCase;import net.sourceforge.pmd.PMD;import net.sourceforge.pmd.Report;import net.sourceforge.pmd.Rule;import net.sourceforge.pmd.RuleContext;import net.sourceforge.pmd.RuleSet;import net.sourceforge.pmd.RuleSetFactory;import net.sourceforge.pmd.RuleSetNotFoundException;import java.io.StringReader;public class RuleTst extends TestCase { public void runTestFromString(String code, int expectedResults, Rule rule) throws Throwable { assertEquals(expectedResults, processUsingStringReader(code, rule).size()); } public Rule findRule(String rs, String r) throws RuleSetNotFoundException { return new RuleSetFactory().createRuleSet(rs).getRuleByName(r); } public void runTestFromString(String code, Rule rule, Report report) throws Throwable { PMD p = new PMD(); RuleContext ctx = new RuleContext(); ctx.setReport(report); ctx.setSourceCodeFilename("n/a"); RuleSet rules = new RuleSet(); rules.addRule(rule); p.processFile(new StringReader(code), rules, ctx); } private Report processUsingStringReader(String code, Rule rule) throws Throwable { Report report = new Report(); runTestFromString(code, rule, report); return report; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -