Skip to content

Commit 0ee8dd9

Browse files
committed
[java] Fix rule tests
1 parent d6b0068 commit 0ee8dd9

5 files changed

Lines changed: 14 additions & 10 deletions

File tree

‎pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/TestClassWithoutTestCasesRule.java‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ private boolean isTestClassByPattern(ASTClassOrInterfaceDeclaration node) {
5353
return false;
5454
}
5555

56-
return testClassPattern.matcher(node.getBinaryName()).find();
56+
if (node.isAbstract() || node.isInterface()) {
57+
return false;
58+
}
59+
60+
String fullName = node.getCanonicalName();
61+
return fullName != null && testClassPattern.matcher(fullName).find();
5762
}
5863
}

‎pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/internal/TestFrameworksUtil.java‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@
1010

1111
import net.sourceforge.pmd.lang.java.ast.ASTAnnotation;
1212
import net.sourceforge.pmd.lang.java.ast.ASTAnyTypeDeclaration;
13-
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceBody;
1413
import net.sourceforge.pmd.lang.java.ast.ASTMethodCall;
1514
import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration;
1615
import net.sourceforge.pmd.lang.java.ast.AccessNode.Visibility;
1716
import net.sourceforge.pmd.lang.java.ast.JModifier;
18-
import net.sourceforge.pmd.lang.java.ast.JavaNode;
1917
import net.sourceforge.pmd.lang.java.symbols.JClassSymbol;
2018
import net.sourceforge.pmd.lang.java.symbols.JTypeDeclSymbol;
2119
import net.sourceforge.pmd.lang.java.types.JTypeMirror;

‎pmd-java/src/main/resources/category/java/performance.xml‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ If you want to copy/move elements inside the _same_ array (e.g. shift the elemen
8383
<property name="xpath">
8484
<value>
8585
<![CDATA[
86-
//(ForStatement[ForUpdate//(UnaryExpression[@Operator='++'] | AssignmentExpression[@Operator = '+='][NumericLiteral[@Image = '1']])]
86+
//(ForStatement[ForUpdate//(UnaryExpression[@Operator=('++','--')] | AssignmentExpression[@Operator = ('+=', '-=')][NumericLiteral[@Image = '1']])]
8787
| WhileStatement | DoStatement)
8888
[not(.//ContinueStatement)]
8989
[not(.//BreakStatement)]
@@ -93,10 +93,10 @@ If you want to copy/move elements inside the _same_ array (e.g. shift the elemen
9393
(: no nested arrays or method calls as array index :)
9494
[count(ArrayAccess[not(.//ArrayAccess)]
9595
[not(.//MethodCall)])=2]
96-
(: array names must be different :)
97-
[count(distinct-values(ArrayAccess/VariableAccess[1]/@Name)) = 2]
9896
(: array index must be same :)
99-
[count(distinct-values(ArrayAccess/VariableAccess[2]/@Name)) = 1]
97+
[distinct-values(ArrayAccess[1]/(VariableAccess[2]|InfixExpression//VariableAccess)/@Name)
98+
= distinct-values(ArrayAccess[2]/(VariableAccess[2]|InfixExpression//VariableAccess)/@Name)
99+
]
100100
)=1]
101101
]]>
102102
</value>
@@ -655,7 +655,7 @@ ArrayList is a much better Collection implementation than Vector if thread-safe
655655
<property name="xpath">
656656
<value>
657657
<![CDATA[
658-
//ConstructorCall/ClassOrInterfaceType[pmd-java:typeIsExactly('java.util.Vector')]
658+
//ConstructorCall/ClassOrInterfaceType[pmd-java:typeIsExactly('java.util.Vector') or pmd-java:typeIsExactly('Vector')]
659659
]]>
660660
</value>
661661
</property>

‎pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/TestClassWithoutTestCases.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public class FooTest {
119119
import static org.junit.Assert.*;
120120
import org.junit.Test;
121121
122-
class YourTest {}
122+
abstract class YourTest {}
123123
public class MyTest extends YourTest {
124124
125125
@Test

‎pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/performance/xml/AvoidArrayLoops.xml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,9 @@ class AvoidArrayLoops {
368368
<test-code>
369369
<description>Shifting left and right #2692</description>
370370
<expected-problems>2</expected-problems>
371-
<expected-linenumbers>9,19</expected-linenumbers>
371+
<expected-linenumbers>10,20</expected-linenumbers>
372372
<code><![CDATA[
373+
import java.util.Arrays;
373374
class Scratch {
374375
public static void main(String[] args) {
375376
int[] ints;

0 commit comments

Comments
 (0)