/** * Visits the method invocation to get number of assertion in this test method. * * @param md Visit method declaration in source code. * @return False because we don't look into child nodes. */ public boolean visit(MethodDeclaration md) { if (md.getName() != null) { this.numOfMethods++; if (md.getName().getIdentifier().startsWith("test")) { this.numOfTestMethods++; } else if (isJUnit4Test(md)) { this.numOfTestMethods++; } // Check test method body to look for assertion statement. Block methodBody = md.getBody(); if (methodBody != null && methodBody.statements() != null) { List stmts = methodBody.statements(); this.numOfStatements += stmts.size(); // Looks through all statements in this method body. for (Iterator i = stmts.iterator(); i.hasNext(); ) { Statement stmt = (Statement) i.next(); // NOPMD // MethodInvocation is one kind of expression statement. if (stmt instanceof ExpressionStatement) { ExpressionStatement estmt = (ExpressionStatement) stmt; checkAssertions(estmt); } } } } // No need to visit child nodes anymore. return false; }