forked from phoedos/pmd
Update java/PMDTaskTest to use mocked rules
This commit is contained in:
@ -27,21 +27,20 @@ public class PMDTaskTest extends AbstractAntTestHelper {
|
|||||||
@Test
|
@Test
|
||||||
public void testNoFormattersValidation() {
|
public void testNoFormattersValidation() {
|
||||||
executeTarget("testNoFormattersValidation");
|
executeTarget("testNoFormattersValidation");
|
||||||
assertOutputContaining("Fields should be declared at the top of the class");
|
assertOutputContaining("Violation from test-rset-1.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNestedRuleset() {
|
public void testNestedRuleset() {
|
||||||
executeTarget("testNestedRuleset");
|
executeTarget("testNestedRuleset");
|
||||||
assertOutputContaining("Avoid really long methods");
|
assertOutputContaining("Violation from test-rset-1.xml");
|
||||||
assertOutputContaining("Fields should be declared at the");
|
assertOutputContaining("Violation from test-rset-2.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFormatterWithProperties() {
|
public void testFormatterWithProperties() {
|
||||||
executeTarget("testFormatterWithProperties");
|
executeTarget("testFormatterWithProperties");
|
||||||
assertOutputContaining("Avoid really long methods");
|
assertOutputContaining("Violation from test-rset-1.xml");
|
||||||
assertOutputContaining("Fields should be declared at the");
|
|
||||||
assertOutputContaining("link_prefix");
|
assertOutputContaining("link_prefix");
|
||||||
assertOutputContaining("line_prefix");
|
assertOutputContaining("line_prefix");
|
||||||
}
|
}
|
||||||
@ -49,42 +48,40 @@ public class PMDTaskTest extends AbstractAntTestHelper {
|
|||||||
@Test
|
@Test
|
||||||
public void testAbstractNames() {
|
public void testAbstractNames() {
|
||||||
executeTarget("testAbstractNames");
|
executeTarget("testAbstractNames");
|
||||||
assertOutputContaining("Avoid really long methods");
|
assertOutputContaining("Violation from test-rset-1.xml");
|
||||||
assertOutputContaining("Fields should be declared at the");
|
assertOutputContaining("Violation from test-rset-2.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAbstractNamesInNestedRuleset() {
|
public void testAbstractNamesInNestedRuleset() {
|
||||||
executeTarget("testAbstractNamesInNestedRuleset");
|
executeTarget("testAbstractNamesInNestedRuleset");
|
||||||
assertOutputContaining("Avoid really long methods");
|
assertOutputContaining("Violation from test-rset-1.xml");
|
||||||
assertOutputContaining("Fields should be declared at the");
|
assertOutputContaining("Violation from test-rset-2.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCommaInRulesetfiles() {
|
public void testCommaInRulesetfiles() {
|
||||||
executeTarget("testCommaInRulesetfiles");
|
executeTarget("testCommaInRulesetfiles");
|
||||||
assertOutputContaining("Avoid really long methods");
|
assertOutputContaining("Violation from test-rset-1.xml");
|
||||||
assertOutputContaining("Fields should be declared at the");
|
assertOutputContaining("Violation from test-rset-2.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRelativeRulesets() {
|
public void testRelativeRulesets() {
|
||||||
executeTarget("testRelativeRulesets");
|
executeTarget("testRelativeRulesets");
|
||||||
assertOutputContaining("Avoid really long methods");
|
assertOutputContaining("Violation from test-rset-1.xml");
|
||||||
assertOutputContaining("Fields should be declared at the");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRelativeRulesetsInRulesetfiles() {
|
public void testRelativeRulesetsInRulesetfiles() {
|
||||||
executeTarget("testRelativeRulesetsInRulesetfiles");
|
executeTarget("testRelativeRulesetsInRulesetfiles");
|
||||||
assertOutputContaining("Avoid really long methods");
|
assertOutputContaining("Violation from test-rset-1.xml");
|
||||||
assertOutputContaining("Fields should be declared at");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExplicitRuleInRuleSet() {
|
public void testExplicitRuleInRuleSet() {
|
||||||
executeTarget("testExplicitRuleInRuleSet");
|
executeTarget("testExplicitRuleInRuleSet");
|
||||||
assertOutputContaining("Avoid really long methods");
|
assertOutputContaining("Violation from test-rset-1.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -166,14 +163,14 @@ public class PMDTaskTest extends AbstractAntTestHelper {
|
|||||||
@Test
|
@Test
|
||||||
public void testMissingCacheLocation() {
|
public void testMissingCacheLocation() {
|
||||||
executeTarget("testMissingCacheLocation");
|
executeTarget("testMissingCacheLocation");
|
||||||
assertOutputContaining("Avoid really long methods");
|
assertOutputContaining("Violation from test-rset-1.xml");
|
||||||
assertContains(buildRule.getLog(), "This analysis could be faster");
|
assertContains(buildRule.getLog(), "This analysis could be faster");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAnalysisCache() {
|
public void testAnalysisCache() {
|
||||||
executeTarget("testAnalysisCache");
|
executeTarget("testAnalysisCache");
|
||||||
assertOutputContaining("Avoid really long methods");
|
assertOutputContaining("Violation from test-rset-1.xml");
|
||||||
assertDoesntContain(buildRule.getLog(), "This analysis could be faster");
|
assertDoesntContain(buildRule.getLog(), "This analysis could be faster");
|
||||||
|
|
||||||
assertTrue(currentTempFile().exists());
|
assertTrue(currentTempFile().exists());
|
||||||
@ -183,7 +180,7 @@ public class PMDTaskTest extends AbstractAntTestHelper {
|
|||||||
@Test
|
@Test
|
||||||
public void testDisableIncrementalAnalysis() {
|
public void testDisableIncrementalAnalysis() {
|
||||||
executeTarget("testDisableIncrementalAnalysis");
|
executeTarget("testDisableIncrementalAnalysis");
|
||||||
assertOutputContaining("Avoid really long methods");
|
assertOutputContaining("Violation from test-rset-1.xml");
|
||||||
assertDoesntContain(buildRule.getLog(), "This analysis could be faster");
|
assertDoesntContain(buildRule.getLog(), "This analysis could be faster");
|
||||||
|
|
||||||
assertFalse(currentTempFile().exists());
|
assertFalse(currentTempFile().exists());
|
||||||
|
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.sourceforge.pmd.lang.java.rule;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import net.sourceforge.pmd.RuleContext;
|
||||||
|
import net.sourceforge.pmd.lang.ast.Node;
|
||||||
|
import net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId;
|
||||||
|
import net.sourceforge.pmd.lang.java.ast.JavaNode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Clément Fournier
|
||||||
|
*/
|
||||||
|
public class DummyJavaRule extends AbstractJavaRule {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void apply(List<? extends Node> nodes, RuleContext ctx) {
|
||||||
|
for (Node node : nodes) {
|
||||||
|
apply(node, ctx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void apply(Node node, RuleContext ctx) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class DummyRuleOneViolationPerFile extends DummyJavaRule {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void apply(Node node, RuleContext ctx) {
|
||||||
|
ctx.addViolation(node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class DummyRulePrintsVars extends DummyJavaRule {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void apply(Node node, RuleContext ctx) {
|
||||||
|
((JavaNode) node).jjtAccept(this, ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object visit(ASTVariableDeclaratorId node, Object data) {
|
||||||
|
asCtx(data).addViolation(node, node.getName());
|
||||||
|
return super.visit(node, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -6,8 +6,8 @@
|
|||||||
|
|
||||||
<target name="testNestedRuleset">
|
<target name="testNestedRuleset">
|
||||||
<pmd>
|
<pmd>
|
||||||
<ruleset>${pmd.home}/src/main/resources/category/java/codestyle.xml</ruleset>
|
<ruleset>${pmd.home}/src/test/resources/rulesets/testing/test-rset-1.xml</ruleset>
|
||||||
<ruleset>${pmd.home}/src/main/resources/category/java/design.xml</ruleset>
|
<ruleset>${pmd.home}/src/test/resources/rulesets/testing/test-rset-2.xml</ruleset>
|
||||||
<formatter type="text" toConsole="true"/>
|
<formatter type="text" toConsole="true"/>
|
||||||
<fileset dir="${pmd.home}/src/test/resources/ant/java">
|
<fileset dir="${pmd.home}/src/test/resources/ant/java">
|
||||||
<include name="*.java"/>
|
<include name="*.java"/>
|
||||||
@ -17,8 +17,8 @@
|
|||||||
|
|
||||||
<target name="testFormatterWithProperties">
|
<target name="testFormatterWithProperties">
|
||||||
<pmd>
|
<pmd>
|
||||||
<ruleset>${pmd.home}/src/main/resources/category/java/codestyle.xml</ruleset>
|
<ruleset>${pmd.home}/src/test/resources/rulesets/testing/test-rset-1.xml</ruleset>
|
||||||
<ruleset>${pmd.home}/src/main/resources/category/java/design.xml</ruleset>
|
<ruleset>${pmd.home}/src/test/resources/rulesets/testing/test-rset-2.xml</ruleset>
|
||||||
<formatter type="summaryhtml" toConsole="true">
|
<formatter type="summaryhtml" toConsole="true">
|
||||||
<param name="linkPrefix" value="link_prefix"/>
|
<param name="linkPrefix" value="link_prefix"/>
|
||||||
<param name="linePrefix" value="line_prefix"/>
|
<param name="linePrefix" value="line_prefix"/>
|
||||||
@ -30,7 +30,7 @@
|
|||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="testAbstractNames">
|
<target name="testAbstractNames">
|
||||||
<pmd rulesetfiles="category/java/codestyle.xml,category/java/design.xml">
|
<pmd rulesetfiles="rulesets/testing/test-rset-1.xml,rulesets/testing/test-rset-2.xml">
|
||||||
<formatter type="text" toConsole="true"/>
|
<formatter type="text" toConsole="true"/>
|
||||||
<fileset dir="${pmd.home}/src/test/resources/ant/java">
|
<fileset dir="${pmd.home}/src/test/resources/ant/java">
|
||||||
<include name="*.java"/>
|
<include name="*.java"/>
|
||||||
@ -40,8 +40,8 @@
|
|||||||
|
|
||||||
<target name="testAbstractNamesInNestedRuleset">
|
<target name="testAbstractNamesInNestedRuleset">
|
||||||
<pmd>
|
<pmd>
|
||||||
<ruleset>category/java/codestyle.xml</ruleset>
|
<ruleset>rulesets/testing/test-rset-1.xml</ruleset>
|
||||||
<ruleset>category/java/design.xml</ruleset>
|
<ruleset>rulesets/testing/test-rset-2.xml</ruleset>
|
||||||
<formatter type="text" toConsole="true"/>
|
<formatter type="text" toConsole="true"/>
|
||||||
<fileset dir="${pmd.home}/src/test/resources/ant/java">
|
<fileset dir="${pmd.home}/src/test/resources/ant/java">
|
||||||
<include name="*.java"/>
|
<include name="*.java"/>
|
||||||
@ -50,7 +50,7 @@
|
|||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="testCommaInRulesetfiles">
|
<target name="testCommaInRulesetfiles">
|
||||||
<pmd rulesetfiles="${pmd.home}/src/main/resources/category/java/codestyle.xml,${pmd.home}/src/main/resources/category/java/design.xml">
|
<pmd rulesetfiles="${pmd.home}/src/test/resources/rulesets/testing/test-rset-1.xml,${pmd.home}/src/test/resources/rulesets/testing/test-rset-2.xml">
|
||||||
<formatter type="text" toConsole="true"/>
|
<formatter type="text" toConsole="true"/>
|
||||||
<fileset dir="${pmd.home}/src/test/resources/ant/java">
|
<fileset dir="${pmd.home}/src/test/resources/ant/java">
|
||||||
<include name="*.java"/>
|
<include name="*.java"/>
|
||||||
@ -61,7 +61,7 @@
|
|||||||
<target name="testRelativeRulesets">
|
<target name="testRelativeRulesets">
|
||||||
<pmd>
|
<pmd>
|
||||||
<ruleset>custom_ruleset.xml</ruleset>
|
<ruleset>custom_ruleset.xml</ruleset>
|
||||||
<ruleset>category/java/codestyle.xml</ruleset>
|
<ruleset>rulesets/testing/test-rset-1.xml</ruleset>
|
||||||
<formatter type="text" toConsole="true"/>
|
<formatter type="text" toConsole="true"/>
|
||||||
<fileset dir="${pmd.home}/src/test/resources/ant/java">
|
<fileset dir="${pmd.home}/src/test/resources/ant/java">
|
||||||
<include name="*.java"/>
|
<include name="*.java"/>
|
||||||
@ -70,7 +70,7 @@
|
|||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="testRelativeRulesetsInRulesetfiles">
|
<target name="testRelativeRulesetsInRulesetfiles">
|
||||||
<pmd rulesetfiles="custom_ruleset.xml,src/main/resources/category/java/codestyle.xml">
|
<pmd rulesetfiles="custom_ruleset.xml,src/test/resources/rulesets/testing/test-rset-1.xml">
|
||||||
<formatter type="text" toConsole="true"/>
|
<formatter type="text" toConsole="true"/>
|
||||||
<fileset dir="${pmd.home}/src/test/resources/ant/java">
|
<fileset dir="${pmd.home}/src/test/resources/ant/java">
|
||||||
<include name="*.java"/>
|
<include name="*.java"/>
|
||||||
@ -79,7 +79,7 @@
|
|||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="testNoFormattersValidation">
|
<target name="testNoFormattersValidation">
|
||||||
<pmd rulesetfiles="${pmd.home}/src/main/resources/category/java/codestyle.xml">
|
<pmd rulesetfiles="${pmd.home}/src/test/resources/rulesets/testing/test-rset-1.xml">
|
||||||
<fileset dir="${pmd.home}/src/test/resources/ant/java">
|
<fileset dir="${pmd.home}/src/test/resources/ant/java">
|
||||||
<include name="*.java"/>
|
<include name="*.java"/>
|
||||||
</fileset>
|
</fileset>
|
||||||
@ -87,7 +87,7 @@
|
|||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="testExplicitRuleInRuleSet">
|
<target name="testExplicitRuleInRuleSet">
|
||||||
<pmd rulesetfiles="src/main/resources/category/java/design.xml/ExcessiveMethodLength">
|
<pmd rulesetfiles="src/test/resources/rulesets/testing/test-rset-1.xml/DummyRuleWithAViolationPerFile">
|
||||||
<formatter type="text" toConsole="true"/>
|
<formatter type="text" toConsole="true"/>
|
||||||
<fileset dir="${pmd.home}/src/test/resources/ant/java">
|
<fileset dir="${pmd.home}/src/test/resources/ant/java">
|
||||||
<include name="*.java"/>
|
<include name="*.java"/>
|
||||||
@ -111,7 +111,7 @@
|
|||||||
<target name="testFormatterEncodingWithXML">
|
<target name="testFormatterEncodingWithXML">
|
||||||
<!-- source encoding is cp1252 -->
|
<!-- source encoding is cp1252 -->
|
||||||
<pmd encoding="cp1252">
|
<pmd encoding="cp1252">
|
||||||
<ruleset>category/java/bestpractices.xml</ruleset>
|
<ruleset>rulesets/testing/test-rset-3.xml</ruleset>
|
||||||
<!--
|
<!--
|
||||||
<formatter type="xml" toConsole="true"/>
|
<formatter type="xml" toConsole="true"/>
|
||||||
-->
|
-->
|
||||||
@ -128,7 +128,7 @@
|
|||||||
<target name="testFormatterEncodingWithXMLConsole">
|
<target name="testFormatterEncodingWithXMLConsole">
|
||||||
<!-- source encoding is cp1252 -->
|
<!-- source encoding is cp1252 -->
|
||||||
<pmd encoding="cp1252">
|
<pmd encoding="cp1252">
|
||||||
<ruleset>category/java/bestpractices.xml</ruleset>
|
<ruleset>rulesets/testing/test-rset-3.xml</ruleset>
|
||||||
<formatter type="xml" toConsole="true">
|
<formatter type="xml" toConsole="true">
|
||||||
<!-- specifying a encoding here will override the console encoding.
|
<!-- specifying a encoding here will override the console encoding.
|
||||||
The output might have junk characters in it.
|
The output might have junk characters in it.
|
||||||
@ -145,7 +145,7 @@
|
|||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="testAnalysisCache">
|
<target name="testAnalysisCache">
|
||||||
<pmd rulesetfiles="src/main/resources/category/java/design.xml/ExcessiveMethodLength" cacheLocation="${tmpfile}">
|
<pmd rulesetfiles="src/test/resources/rulesets/testing/test-rset-1.xml/DummyRuleWithAViolationPerFile" cacheLocation="${tmpfile}">
|
||||||
<formatter type="xml" toConsole="true"/>
|
<formatter type="xml" toConsole="true"/>
|
||||||
<fileset dir="${pmd.home}/src/test/resources/ant/java">
|
<fileset dir="${pmd.home}/src/test/resources/ant/java">
|
||||||
<include name="*.java"/>
|
<include name="*.java"/>
|
||||||
@ -154,7 +154,7 @@
|
|||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="testMissingCacheLocation">
|
<target name="testMissingCacheLocation">
|
||||||
<pmd rulesetfiles="src/main/resources/category/java/design.xml/ExcessiveMethodLength">
|
<pmd rulesetfiles="src/test/resources/rulesets/testing/test-rset-1.xml/DummyRuleWithAViolationPerFile">
|
||||||
<formatter type="xml" toConsole="true"/>
|
<formatter type="xml" toConsole="true"/>
|
||||||
<fileset dir="${pmd.home}/src/test/resources/ant/java">
|
<fileset dir="${pmd.home}/src/test/resources/ant/java">
|
||||||
<include name="*.java"/>
|
<include name="*.java"/>
|
||||||
@ -163,7 +163,7 @@
|
|||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="testDisableIncrementalAnalysis">
|
<target name="testDisableIncrementalAnalysis">
|
||||||
<pmd rulesetfiles="src/main/resources/category/java/design.xml/ExcessiveMethodLength" noCache="true" cacheLocation="${tmpfile}">
|
<pmd rulesetfiles="src/test/resources/rulesets/testing/test-rset-1.xml/DummyRuleWithAViolationPerFile" noCache="true" cacheLocation="${tmpfile}">
|
||||||
<formatter type="xml" toConsole="true"/>
|
<formatter type="xml" toConsole="true"/>
|
||||||
<fileset dir="${pmd.home}/src/test/resources/ant/java">
|
<fileset dir="${pmd.home}/src/test/resources/ant/java">
|
||||||
<include name="*.java"/>
|
<include name="*.java"/>
|
||||||
|
40
pmd-java/src/test/resources/rulesets/testing/test-rset-1.xml
Normal file
40
pmd-java/src/test/resources/rulesets/testing/test-rset-1.xml
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<ruleset name="Test Ruleset" xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
|
||||||
|
|
||||||
|
<description>
|
||||||
|
Ruleset used by test RuleSetReferenceIdTest
|
||||||
|
</description>
|
||||||
|
|
||||||
|
<rule name="DummyRuleNoViolation"
|
||||||
|
language="java"
|
||||||
|
since="1.0"
|
||||||
|
message="Test Rule 1"
|
||||||
|
class="net.sourceforge.pmd.lang.java.rule.DummyJavaRule">
|
||||||
|
<description>
|
||||||
|
Just for test
|
||||||
|
</description>
|
||||||
|
<priority>3</priority>
|
||||||
|
<example>
|
||||||
|
<![CDATA[
|
||||||
|
]]>
|
||||||
|
</example>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<rule name="DummyRuleWithAViolationPerFile"
|
||||||
|
language="java"
|
||||||
|
since="1.0"
|
||||||
|
message="Violation from test-rset-1.xml"
|
||||||
|
class="net.sourceforge.pmd.lang.java.rule.DummyJavaRule$DummyRuleOneViolationPerFile">
|
||||||
|
<description>
|
||||||
|
Just for test
|
||||||
|
</description>
|
||||||
|
<priority>3</priority>
|
||||||
|
<example>
|
||||||
|
<![CDATA[
|
||||||
|
]]>
|
||||||
|
</example>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
</ruleset>
|
25
pmd-java/src/test/resources/rulesets/testing/test-rset-2.xml
Normal file
25
pmd-java/src/test/resources/rulesets/testing/test-rset-2.xml
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<ruleset name="Test Ruleset" xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
|
||||||
|
|
||||||
|
<description>
|
||||||
|
Ruleset used by test RuleSetReferenceIdTest
|
||||||
|
</description>
|
||||||
|
|
||||||
|
<rule name="DummyRuleWithAViolationPerFile"
|
||||||
|
language="java"
|
||||||
|
since="1.0"
|
||||||
|
message="Violation from test-rset-2.xml"
|
||||||
|
class="net.sourceforge.pmd.lang.java.rule.DummyJavaRule$DummyRuleOneViolationPerFile">
|
||||||
|
<description>
|
||||||
|
Just for test
|
||||||
|
</description>
|
||||||
|
<priority>3</priority>
|
||||||
|
<example>
|
||||||
|
<![CDATA[
|
||||||
|
]]>
|
||||||
|
</example>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
</ruleset>
|
25
pmd-java/src/test/resources/rulesets/testing/test-rset-3.xml
Normal file
25
pmd-java/src/test/resources/rulesets/testing/test-rset-3.xml
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<ruleset name="Test Ruleset" xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
|
||||||
|
|
||||||
|
<description>
|
||||||
|
Ruleset used by test RuleSetReferenceIdTest
|
||||||
|
</description>
|
||||||
|
|
||||||
|
<rule name="DummyRuleWithAViolationPerFile"
|
||||||
|
language="java"
|
||||||
|
since="1.0"
|
||||||
|
message="Violation from test-rset-3.xml: name {0}"
|
||||||
|
class="net.sourceforge.pmd.lang.java.rule.DummyJavaRule$DummyRulePrintsVars">
|
||||||
|
<description>
|
||||||
|
Just for test
|
||||||
|
</description>
|
||||||
|
<priority>3</priority>
|
||||||
|
<example>
|
||||||
|
<![CDATA[
|
||||||
|
]]>
|
||||||
|
</example>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
</ruleset>
|
@ -5,15 +5,18 @@
|
|||||||
package net.sourceforge.pmd.ant;
|
package net.sourceforge.pmd.ant;
|
||||||
|
|
||||||
import static java.io.File.separator;
|
import static java.io.File.separator;
|
||||||
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
|
import static org.hamcrest.Matchers.containsString;
|
||||||
|
import static org.hamcrest.Matchers.not;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.apache.tools.ant.BuildFileRule;
|
import org.apache.tools.ant.BuildFileRule;
|
||||||
import org.apache.tools.ant.Project;
|
import org.apache.tools.ant.Project;
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
|
import org.junit.contrib.java.lang.system.SystemErrRule;
|
||||||
import org.junit.rules.TemporaryFolder;
|
import org.junit.rules.TemporaryFolder;
|
||||||
|
|
||||||
|
|
||||||
@ -33,6 +36,9 @@ public abstract class AbstractAntTestHelper {
|
|||||||
@Rule
|
@Rule
|
||||||
public final BuildFileRule buildRule = new BuildFileRule();
|
public final BuildFileRule buildRule = new BuildFileRule();
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public final SystemErrRule systemErrRule = new SystemErrRule().muteForSuccessfulTests();
|
||||||
|
|
||||||
protected String pathToTestScript;
|
protected String pathToTestScript;
|
||||||
protected String antTestScriptFilename;
|
protected String antTestScriptFilename;
|
||||||
public String mvnWorkaround;
|
public String mvnWorkaround;
|
||||||
@ -85,21 +91,20 @@ public abstract class AbstractAntTestHelper {
|
|||||||
|
|
||||||
public void executeTarget(String target) {
|
public void executeTarget(String target) {
|
||||||
buildRule.executeTarget(target);
|
buildRule.executeTarget(target);
|
||||||
|
System.err.println(buildRule.getLog());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void assertOutputContaining(String text) {
|
public void assertOutputContaining(String text) {
|
||||||
assertContains(buildRule.getOutput(), text);
|
assertThat(buildRule.getOutput(), containsString(text));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void assertContains(String text, String toFind) {
|
public void assertContains(String text, String toFind) {
|
||||||
Assert.assertTrue("Expected to find \"" + toFind + "\", but it's missing",
|
assertThat(text, containsString(toFind));
|
||||||
text.contains(toFind));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void assertDoesntContain(String text, String toFind) {
|
public void assertDoesntContain(String text, String toFind) {
|
||||||
Assert.assertTrue("Expected no occurrence of \"" + toFind + "\", but found at least one",
|
assertThat(text, not(containsString(toFind)));
|
||||||
!text.contains(toFind));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user