use of net.sourceforge.pmd.lang.apex.ast.ASTStatement in project pmd by pmd.
the class ApexUnitTestClassShouldHaveAssertsRule method checkForAssertStatements.
private Object checkForAssertStatements(ApexNode<?> node, Object data) {
final List<ASTBlockStatement> blockStatements = node.findDescendantsOfType(ASTBlockStatement.class);
final List<ASTStatement> statements = new ArrayList<>();
final List<ASTMethodCallExpression> methodCalls = new ArrayList<>();
for (ASTBlockStatement blockStatement : blockStatements) {
statements.addAll(blockStatement.findDescendantsOfType(ASTStatement.class));
methodCalls.addAll(blockStatement.findDescendantsOfType(ASTMethodCallExpression.class));
}
boolean isAssertFound = false;
for (final ASTMethodCallExpression methodCallExpression : methodCalls) {
if (ASSERT_METHODS.contains(methodCallExpression.getFullMethodName().toLowerCase(Locale.ROOT))) {
isAssertFound = true;
break;
}
}
if (!isAssertFound) {
addViolation(data, node);
}
return data;
}
Aggregations