Skip to content

Commit

Permalink
issue252: correcting a few tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomassetti committed Apr 13, 2016
1 parent ef5f06e commit 417be92
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
Expand Up @@ -35,13 +35,9 @@
import com.github.javaparser.ast.body.Parameter;
import com.github.javaparser.ast.body.TypeDeclaration;
import com.github.javaparser.ast.body.VariableDeclarator;
import com.github.javaparser.ast.expr.AnnotationExpr;
import com.github.javaparser.ast.expr.ArrayCreationExpr;
import com.github.javaparser.ast.expr.ConditionalExpr;
import com.github.javaparser.ast.expr.LambdaExpr;
import com.github.javaparser.ast.expr.MethodReferenceExpr;
import com.github.javaparser.ast.expr.ObjectCreationExpr;
import com.github.javaparser.ast.expr.*;
import com.github.javaparser.ast.stmt.BlockStmt;
import com.github.javaparser.ast.stmt.ExpressionStmt;
import com.github.javaparser.ast.stmt.ReturnStmt;
import com.github.javaparser.ast.stmt.Statement;
import org.jbehave.core.annotations.Given;
Expand Down Expand Up @@ -165,9 +161,12 @@ public void thenLambdaInStatementInMethodInClassBody(int statementPosition, int
@Then("lambda in method call in statement $statementPosition in method $methodPosition in class $classPosition body is \"$expectedBody\"")
public void thenLambdaInMethodCallInStatementInMethodInClassBody(int statementPosition, int methodPosition, int classPosition,
String expectedBody) {
Statement statement = getStatementInMethodInClass(statementPosition, methodPosition, classPosition);
LambdaExpr lambdaExpr = (LambdaExpr) statement.getChildrenNodes().get(0).getChildrenNodes().get(1).getChildrenNodes().get(1)
.getChildrenNodes().get(1).getChildrenNodes().get(2);
ExpressionStmt statement = (ExpressionStmt) getStatementInMethodInClass(statementPosition, methodPosition, classPosition);
VariableDeclarationExpr variableDeclarationExpr = (VariableDeclarationExpr) statement.getExpression();
VariableDeclarator variableDeclarator = variableDeclarationExpr.getVars().get(0);
MethodCallExpr methodCallExpr = (MethodCallExpr) variableDeclarator.getInit();
CastExpr castExpr = (CastExpr) methodCallExpr.getArgs().get(0);
LambdaExpr lambdaExpr = (LambdaExpr) castExpr.getExpr();
assertThat(lambdaExpr.getBody().toString(), is(expectedBody));
}

Expand Down Expand Up @@ -212,18 +211,18 @@ public void thenLambdaInStatementInMethodInClassIsParentOfContainedParameter(int
@Then("method reference in statement $statementPosition in method $methodPosition in class $classPosition scope is $expectedName")
public void thenMethodReferenceInStatementInMethodInClassIsScope(int statementPosition, int methodPosition,
int classPosition, String expectedName) {
Statement statementUnderTest = getStatementInMethodInClass(statementPosition, methodPosition, classPosition);
MethodReferenceExpr methodReferenceUnderTest =
(MethodReferenceExpr) statementUnderTest.getChildrenNodes().get(0).getChildrenNodes().get(2);
ExpressionStmt statementUnderTest = (ExpressionStmt)getStatementInMethodInClass(statementPosition, methodPosition, classPosition);
assertEquals(1, ASTHelper.getNodesByType(statementUnderTest, MethodReferenceExpr.class).size());
MethodReferenceExpr methodReferenceUnderTest = ASTHelper.getNodesByType(statementUnderTest, MethodReferenceExpr.class).get(0);
assertThat(methodReferenceUnderTest.getScope().toString(), is(expectedName));
}

@Then("method reference in statement $statementPosition in method $methodPosition in class $classPosition identifier is $expectedName")
public void thenMethodReferenceInStatementInMethodInClassIdentifierIsCompareByAge(int statementPosition, int methodPosition,
int classPosition, String expectedName) {
Statement statementUnderTest = getStatementInMethodInClass(statementPosition, methodPosition, classPosition);
MethodReferenceExpr methodReferenceUnderTest =
(MethodReferenceExpr) statementUnderTest.getChildrenNodes().get(0).getChildrenNodes().get(2);
assertEquals(1, ASTHelper.getNodesByType(statementUnderTest, MethodReferenceExpr.class).size());
MethodReferenceExpr methodReferenceUnderTest = ASTHelper.getNodesByType(statementUnderTest, MethodReferenceExpr.class).get(0);
assertThat(methodReferenceUnderTest.getIdentifier(), is(expectedName));
}

Expand Down
Expand Up @@ -69,7 +69,7 @@ class /*Comment1*/ A {
}
When the class is parsed by the Java parser
Then class 1 is not commented
Then class 1 orphan comment 1 is "Comment1"
Then class 1 orphan comment 1 is "Comment2"


Scenario: A Class With Line Comments in Multiple Methods is parsed by the Java Parser
Expand Down
Expand Up @@ -152,7 +152,7 @@ Then field 1 in class 1 contains annotation 1 value is ""http://someURL.org/""
Then all nodes refer to their parent


Scenario: A class with a Lambdas is parsed by the Java Parser
Scenario: A class with a Lambda is parsed by the Java Parser

Given a CompilationUnit
When the following source is parsed:
Expand Down
Expand Up @@ -73,4 +73,4 @@ Given a CompilationUnit
Given a VoidVisitorAdapter with a visit method that asserts sensible line positions
When the "JavaConcepts.java" is parsed
When the CompilationUnit is visited by the PositionTestVisitor
Then the total number of nodes visited is 1338
Then the total number of nodes visited is 1425

0 comments on commit 417be92

Please sign in to comment.