Simplify the rules even more

This commit is contained in:
Andreas Dangel
2019-03-25 19:56:47 +01:00
parent db3b211d8f
commit 2958f83517
2 changed files with 13 additions and 16 deletions

View File

@@ -4,8 +4,6 @@
package net.sourceforge.pmd.lang.apex.rule.bestpractices;
import java.util.Locale;
import net.sourceforge.pmd.lang.apex.ast.ASTMethodCallExpression;
import net.sourceforge.pmd.lang.apex.rule.AbstractApexUnitTestRule;
@@ -17,14 +15,9 @@ public class ApexAssertionsShouldIncludeMessageRule extends AbstractApexUnitTest
@Override
public Object visit(ASTMethodCallExpression node, Object data) {
String methodName = node.getFullMethodName().toLowerCase(Locale.ROOT);
if (!ASSERT.equalsIgnoreCase(methodName)
&& !ASSERT_EQUALS.equalsIgnoreCase(methodName)
&& !ASSERT_NOT_EQUALS.equalsIgnoreCase(methodName)) {
return data;
}
if (ASSERT.equalsIgnoreCase(methodName)
&& node.jjtGetNumChildren() == 2) {
String methodName = node.getFullMethodName();
if (ASSERT.equalsIgnoreCase(methodName) && node.jjtGetNumChildren() == 2) {
addViolationWithMessage(data, node,
"''{0}'' should have 2 parameters.",
new Object[] { ASSERT });

View File

@@ -4,17 +4,23 @@
package net.sourceforge.pmd.lang.apex.rule.bestpractices;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import net.sourceforge.pmd.lang.apex.ast.ASTMethod;
import net.sourceforge.pmd.lang.apex.ast.ASTMethodCallExpression;
import net.sourceforge.pmd.lang.apex.rule.AbstractApexUnitTestRule;
public class ApexUnitTestMethodShouldHaveIsTestAnnotationRule extends AbstractApexUnitTestRule {
private static final String ASSERT = "system.assert";
private static final String ASSERT_EQUALS = "system.assertequals";
private static final String ASSERT_NOT_EQUALS = "system.assertnotequals";
private static final Set<String> ASSERT_METHODS = new HashSet<>();
static {
ASSERT_METHODS.add("system.assert");
ASSERT_METHODS.add("system.assertequals");
ASSERT_METHODS.add("system.assertnotequals");
}
@Override
public Object visit(final ASTMethod node, final Object data) {
@@ -30,9 +36,7 @@ public class ApexUnitTestMethodShouldHaveIsTestAnnotationRule extends AbstractAp
String assertMethodName;
for (ASTMethodCallExpression assertMethodCall : methodCallList) {
assertMethodName = assertMethodCall.getFullMethodName().toLowerCase(Locale.ROOT);
if (ASSERT.equalsIgnoreCase(assertMethodName)
|| ASSERT_EQUALS.equalsIgnoreCase(assertMethodName)
|| ASSERT_NOT_EQUALS.equalsIgnoreCase(assertMethodName)) {
if (ASSERT_METHODS.contains(assertMethodName)) {
addViolationWithMessage(data, testMethod,
"''{0}'' method should have @IsTest annotation.",
new Object[] { testMethod.getImage() });