-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update java/PMDTaskTest to use mocked rules
- Loading branch information
Showing
7 changed files
with
185 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/DummyJavaRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
pmd-java/src/test/resources/rulesets/testing/test-rset-1.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 changes: 25 additions & 0 deletions
25
pmd-java/src/test/resources/rulesets/testing/test-rset-2.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 changes: 25 additions & 0 deletions
25
pmd-java/src/test/resources/rulesets/testing/test-rset-3.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
Oops, something went wrong.