Some sugar

This commit is contained in:
Clément Fournier
2020-07-30 02:27:55 +02:00
parent 0d881b7271
commit c7d88ec506
22 changed files with 174 additions and 200 deletions

View File

@@ -38,7 +38,9 @@ import net.sourceforge.pmd.PMDException;
import net.sourceforge.pmd.Report;
import net.sourceforge.pmd.Report.GlobalReportBuilder;
import net.sourceforge.pmd.Rule;
import net.sourceforge.pmd.RuleSet;
import net.sourceforge.pmd.RuleSetNotFoundException;
import net.sourceforge.pmd.RuleSets;
import net.sourceforge.pmd.RuleViolation;
import net.sourceforge.pmd.RulesetsFactoryUtils;
import net.sourceforge.pmd.lang.Language;
@@ -99,7 +101,8 @@ public abstract class RuleTst {
*/
public Rule findRule(String ruleSet, String ruleName) {
try {
Rule rule = RulesetsFactoryUtils.defaultFactory().createRuleSets(ruleSet).getRuleByName(ruleName);
List<RuleSet> ruleSets = RulesetsFactoryUtils.defaultFactory().createRuleSets(ruleSet);
Rule rule = new RuleSets(ruleSets).getRuleByName(ruleName);
if (rule == null) {
fail("Rule " + ruleName + " not found in ruleset " + ruleSet);
} else {
@@ -265,6 +268,7 @@ public abstract class RuleTst {
PMDConfiguration config = new PMDConfiguration();
config.setIgnoreIncrementalAnalysis(true);
config.setDefaultLanguageVersion(languageVersion);
config.setThreads(1);
if (isUseAuxClasspath) {
// configure the "auxclasspath" option for unit testing

View File

@@ -8,7 +8,6 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import java.util.Arrays;
@@ -43,6 +42,7 @@ public class RuleTstTest {
when(rule.getLanguage()).thenReturn(dummyLanguage.getLanguage());
when(rule.getName()).thenReturn("test rule");
when(rule.getTargetSelector()).thenReturn(RuleTargetSelector.forRootOnly());
when(rule.deepCopy()).thenReturn(rule);
Report report = ruleTester.runTestFromString("the code", rule, dummyLanguage, false);
@@ -55,7 +55,6 @@ public class RuleTstTest {
verify(rule).apply(any(Node.class), any(RuleContext.class));
verify(rule, times(4)).getName();
verify(rule).getPropertiesByPropertyDescriptor();
verifyNoMoreInteractions(rule);
}
@Test
@@ -63,6 +62,7 @@ public class RuleTstTest {
when(rule.getLanguage()).thenReturn(dummyLanguage.getLanguage());
when(rule.getName()).thenReturn("test rule");
when(rule.getTargetSelector()).thenReturn(RuleTargetSelector.forRootOnly());
when(rule.deepCopy()).thenReturn(rule);
Mockito.doAnswer(new Answer<Void>() {
private RuleViolation createViolation(int beginLine, String message) {