This is an automated email from the ASF dual-hosted git repository. adangel pushed a commit to branch pmd7 in repository https://gitbox.apache.org/repos/asf/maven-pmd-plugin.git
commit a8db48594833a597ab04fc7c50074d28e30d52f8 Author: Andreas Dangel <adan...@apache.org> AuthorDate: Fri Jun 10 11:42:49 2022 +0200 Add separate testcase to detect deprecated rules --- .../org/apache/maven/plugins/pmd/RuleSetTest.java | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/src/test/java/org/apache/maven/plugins/pmd/RuleSetTest.java b/src/test/java/org/apache/maven/plugins/pmd/RuleSetTest.java new file mode 100644 index 0000000..3aea015 --- /dev/null +++ b/src/test/java/org/apache/maven/plugins/pmd/RuleSetTest.java @@ -0,0 +1,51 @@ +package org.apache.maven.plugins.pmd; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import junit.framework.TestCase; +import net.sourceforge.pmd.PMDConfiguration; +import net.sourceforge.pmd.RuleSetLoader; + +public class RuleSetTest extends TestCase { + + private RuleSetLoader ruleSetLoader = RuleSetLoader.fromPmdConfig(new PMDConfiguration()).warnDeprecated(true); + + public void setUp() { + CapturingPrintStream.init( true ); + } + + public void testDefaultRuleset() { + ruleSetLoader.loadFromResource("rulesets/java/maven-pmd-plugin-default.xml"); + assertNoDeprecatedRules( CapturingPrintStream.getOutput() ); + } + + public void testMavenRuleset() { + ruleSetLoader.loadFromResource("rulesets/maven.xml"); + assertNoDeprecatedRules( CapturingPrintStream.getOutput() ); + } + + private void assertNoDeprecatedRules( String output ) + { + // there must be no warnings (like deprecated rules) in the log output + assertFalse( output.contains( "deprecated Rule name" ) ); + assertFalse( output.contains( "Discontinue using Rule name" ) ); + assertFalse( output.contains( "is referenced multiple times" ) ); + } +}