Skip to content

Commit

Permalink
added LambdaFormalParametersExpressionTest
Browse files Browse the repository at this point in the history
  • Loading branch information
nbauma109 committed May 21, 2023
1 parent c885595 commit 7b94e52
Showing 1 changed file with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package org.jd.core.v1.model.javasyntax.expression;

import org.jd.core.v1.model.javasyntax.declaration.BaseFormalParameter;
import org.jd.core.v1.model.javasyntax.declaration.FormalParameter;
import org.jd.core.v1.model.javasyntax.statement.BaseStatement;
import org.jd.core.v1.model.javasyntax.statement.ReturnExpressionStatement;
import org.jd.core.v1.model.javasyntax.type.ObjectType;
import org.jd.core.v1.model.javasyntax.type.Type;
import org.jd.core.v1.service.converter.classfiletojavasyntax.visitor.TestVisitor;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;

public class LambdaFormalParametersExpressionTest {

@Test
public void testLambdaFormalParametersExpression() {
// Arrange
Type type = ObjectType.TYPE_OBJECT;
Expression returnExpression = new IntegerConstantExpression(1);
BaseStatement statement = new ReturnExpressionStatement(returnExpression);
BaseFormalParameter baseFormalParameter = new FormalParameter(ObjectType.TYPE_INTEGER, "x");
int lineNumber = 10;

// Act
LambdaFormalParametersExpression lambdaFormalParametersExpression = new LambdaFormalParametersExpression(lineNumber, type, baseFormalParameter, statement);

// Assert
assertEquals(lineNumber, lambdaFormalParametersExpression.getLineNumber());
assertEquals(type, lambdaFormalParametersExpression.getType());
assertEquals(baseFormalParameter, lambdaFormalParametersExpression.getFormalParameters());
assertEquals(statement, lambdaFormalParametersExpression.getStatements());

// Act & Assert
LambdaFormalParametersExpression copy = (LambdaFormalParametersExpression) lambdaFormalParametersExpression.copyTo(lineNumber + 1);
assertEquals(lambdaFormalParametersExpression.getType(), copy.getType());
assertEquals(lambdaFormalParametersExpression.getFormalParameters(), copy.getFormalParameters());
assertEquals(lambdaFormalParametersExpression.getStatements(), copy.getStatements());
assertNotEquals(lambdaFormalParametersExpression.getLineNumber(), copy.getLineNumber());

// Test accept method
TestVisitor visitor = new TestVisitor();
lambdaFormalParametersExpression.accept(visitor);
assertEquals(1, visitor.getLambdaFormalParametersExpressionCount());

// Test toString method
String expectedToString = "LambdaFormalParametersExpression{" + baseFormalParameter + " -> " + statement + "}";
assertEquals(expectedToString, lambdaFormalParametersExpression.toString());
}
}

0 comments on commit 7b94e52

Please sign in to comment.