Fix pmd warnings
This commit is contained in:
1 parent
bf79114682
commit
3a1940d5a0
8 files changed
+20
-21
No files matched your search
+2
-2
@@ -10,7 +10,7 @@ import java.util.List;
|
||||
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTMethodCall;
|
||||
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRulechainRule;
|
||||
import net.sourceforge.pmd.lang.java.rule.internal.JUnitRuleUtil;
|
||||
import net.sourceforge.pmd.lang.java.rule.internal.TestFrameworksUtil;
|
||||
import net.sourceforge.pmd.lang.java.types.TypeTestUtil.InvocationMatcher;
|
||||
|
||||
public class JUnitAssertionsShouldIncludeMessageRule extends AbstractJavaRulechainRule {
|
||||
@@ -37,7 +37,7 @@ public class JUnitAssertionsShouldIncludeMessageRule extends AbstractJavaRulecha
|
||||
|
||||
@Override
|
||||
public Object visit(ASTMethodCall node, Object data) {
|
||||
if (JUnitRuleUtil.isCallOnAssertionContainer(node)) {
|
||||
if (TestFrameworksUtil.isCallOnAssertionContainer(node)) {
|
||||
for (InvocationMatcher check : checks) {
|
||||
if (check.matchesCall(node)) {
|
||||
addViolation(data, node);
|
||||
|
||||
+3
-3
@@ -8,7 +8,7 @@ import net.sourceforge.pmd.lang.java.ast.ASTBlock;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTMethodCall;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRulechainRule;
|
||||
import net.sourceforge.pmd.lang.java.rule.internal.JUnitRuleUtil;
|
||||
import net.sourceforge.pmd.lang.java.rule.internal.TestFrameworksUtil;
|
||||
import net.sourceforge.pmd.properties.PropertyDescriptor;
|
||||
import net.sourceforge.pmd.properties.PropertyFactory;
|
||||
import net.sourceforge.pmd.properties.constraints.NumericConstraints;
|
||||
@@ -31,9 +31,9 @@ public class JUnitTestContainsTooManyAssertsRule extends AbstractJavaRulechainRu
|
||||
@Override
|
||||
public Object visit(ASTMethodDeclaration method, Object data) {
|
||||
ASTBlock body = method.getBody();
|
||||
if (body != null && JUnitRuleUtil.isTestMethod(method)) {
|
||||
if (body != null && TestFrameworksUtil.isTestMethod(method)) {
|
||||
int assertCount = body.descendants(ASTMethodCall.class)
|
||||
.filter(JUnitRuleUtil::isProbableAssertCall)
|
||||
.filter(TestFrameworksUtil::isProbableAssertCall)
|
||||
.count();
|
||||
if (assertCount > getProperty(MAX_ASSERTS)) {
|
||||
addViolation(data, method);
|
||||
|
||||
+4
-4
@@ -8,7 +8,7 @@ import net.sourceforge.pmd.lang.java.ast.ASTBlock;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTMethodCall;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRulechainRule;
|
||||
import net.sourceforge.pmd.lang.java.rule.internal.JUnitRuleUtil;
|
||||
import net.sourceforge.pmd.lang.java.rule.internal.TestFrameworksUtil;
|
||||
|
||||
public class JUnitTestsShouldIncludeAssertRule extends AbstractJavaRulechainRule {
|
||||
|
||||
@@ -21,10 +21,10 @@ public class JUnitTestsShouldIncludeAssertRule extends AbstractJavaRulechainRule
|
||||
public Object visit(ASTMethodDeclaration method, Object data) {
|
||||
ASTBlock body = method.getBody();
|
||||
if (body != null
|
||||
&& JUnitRuleUtil.isJUnitMethod(method)
|
||||
&& !JUnitRuleUtil.isExpectAnnotated(method)
|
||||
&& TestFrameworksUtil.isJUnitMethod(method)
|
||||
&& !TestFrameworksUtil.isExpectAnnotated(method)
|
||||
&& body.descendants(ASTMethodCall.class)
|
||||
.none(JUnitRuleUtil::isProbableAssertCall)) {
|
||||
.none(TestFrameworksUtil::isProbableAssertCall)) {
|
||||
addViolation(data, method);
|
||||
}
|
||||
return data;
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.java.rule.bestpractices;
|
||||
|
||||
import static net.sourceforge.pmd.lang.java.rule.internal.JUnitRuleUtil.isJUnitMethod;
|
||||
import static net.sourceforge.pmd.lang.java.rule.internal.TestFrameworksUtil.isJUnitMethod;
|
||||
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTBlock;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTExpressionStatement;
|
||||
|
||||
+2
-2
@@ -8,7 +8,7 @@ package net.sourceforge.pmd.lang.java.rule.errorprone;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRulechainRule;
|
||||
import net.sourceforge.pmd.lang.java.rule.internal.JUnitRuleUtil;
|
||||
import net.sourceforge.pmd.lang.java.rule.internal.TestFrameworksUtil;
|
||||
|
||||
public class JUnitSpellingRule extends AbstractJavaRulechainRule {
|
||||
|
||||
@@ -18,7 +18,7 @@ public class JUnitSpellingRule extends AbstractJavaRulechainRule {
|
||||
|
||||
@Override
|
||||
public Object visit(ASTClassOrInterfaceDeclaration node, Object data) {
|
||||
if (JUnitRuleUtil.isJUnit3Class(node)) {
|
||||
if (TestFrameworksUtil.isJUnit3Class(node)) {
|
||||
node.getDeclarations(ASTMethodDeclaration.class)
|
||||
.filter(this::isViolation)
|
||||
.forEach(it -> addViolation(data, it));
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.java.rule.errorprone;
|
||||
|
||||
import static net.sourceforge.pmd.lang.java.rule.internal.JUnitRuleUtil.isJUnit3Class;
|
||||
import static net.sourceforge.pmd.lang.java.rule.internal.TestFrameworksUtil.isJUnit3Class;
|
||||
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration;
|
||||
|
||||
+3
-3
@@ -4,12 +4,12 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.java.rule.errorprone;
|
||||
|
||||
import static net.sourceforge.pmd.lang.java.rule.internal.JUnitRuleUtil.isJUnit3Class;
|
||||
import static net.sourceforge.pmd.lang.java.rule.internal.TestFrameworksUtil.isJUnit3Class;
|
||||
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRulechainRule;
|
||||
import net.sourceforge.pmd.lang.java.rule.internal.JUnitRuleUtil;
|
||||
import net.sourceforge.pmd.lang.java.rule.internal.TestFrameworksUtil;
|
||||
|
||||
public class TestClassWithoutTestCasesRule extends AbstractJavaRulechainRule {
|
||||
|
||||
@@ -22,7 +22,7 @@ public class TestClassWithoutTestCasesRule extends AbstractJavaRulechainRule {
|
||||
if (isJUnit3Class(node)) {
|
||||
boolean hasTests =
|
||||
node.getDeclarations(ASTMethodDeclaration.class)
|
||||
.any(JUnitRuleUtil::isJunit3MethodSignature);
|
||||
.any(TestFrameworksUtil::isJunit3MethodSignature);
|
||||
|
||||
if (!hasTests) {
|
||||
addViolation(data, node);
|
||||
|
||||
+4
-5
@@ -18,13 +18,12 @@ import net.sourceforge.pmd.lang.java.types.JTypeMirror;
|
||||
import net.sourceforge.pmd.lang.java.types.TypeTestUtil;
|
||||
|
||||
/**
|
||||
* Utilities for junit-related rules.
|
||||
* Utilities for rules related to test frameworks (Junit, TestNG, etc).
|
||||
*/
|
||||
public final class JUnitRuleUtil {
|
||||
public final class TestFrameworksUtil {
|
||||
|
||||
private static final String JUNIT3_CLASS_NAME = "junit.framework.TestCase";
|
||||
private static final String JUNIT4_TEST_ANNOT = "org.junit.Test";
|
||||
private static final String JUNIT5_TEST_ANNOT = "org.junit.jupiter.api.Test";
|
||||
|
||||
private static final String TESTNG_TEST_ANNOT = "org.testng.annotations.Test";
|
||||
|
||||
@@ -42,7 +41,7 @@ public final class JUnitRuleUtil {
|
||||
"org.testng.Assert",
|
||||
"junit.framework.TestCase");
|
||||
|
||||
private JUnitRuleUtil() {
|
||||
private TestFrameworksUtil() {
|
||||
// utility class
|
||||
}
|
||||
|
||||
@@ -148,7 +147,7 @@ public final class JUnitRuleUtil {
|
||||
*/
|
||||
public static boolean isExpectAnnotated(ASTMethodDeclaration method) {
|
||||
return method.getDeclaredAnnotations()
|
||||
.filter(JUnitRuleUtil::isJunit4TestAnnotation)
|
||||
.filter(TestFrameworksUtil::isJunit4TestAnnotation)
|
||||
.flatMap(ASTAnnotation::getMembers)
|
||||
.any(it -> "expected".equals(it.getName()));
|
||||
|
||||
Reference in new issue
Block a user