Skip to content

Commit

Permalink
added ParenthesesExpressionTest
Browse files Browse the repository at this point in the history
  • Loading branch information
nbauma109 committed May 21, 2023
1 parent 60c88dd commit b927174
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public ParenthesesExpression(Expression expression) {

public ParenthesesExpression(int lineNumber, Expression expression) {
super(lineNumber);
this.expression = expression;
this.setExpression(expression);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.jd.core.v1.model.javasyntax.expression;

import org.jd.core.v1.model.javasyntax.type.PrimitiveType;
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.assertTrue;

public class ParenthesesExpressionTest {

@Test
public void testParenthesesExpression() {
// Test constructor with Expression
Expression expression = new IntegerConstantExpression(1, 10);
ParenthesesExpression parenthesesExpression = new ParenthesesExpression(expression);

assertTrue(parenthesesExpression.getExpression() instanceof IntegerConstantExpression);
assertTrue(parenthesesExpression.getType() instanceof PrimitiveType);

// Test constructor with lineNumber and Expression
ParenthesesExpression parenthesesExpressionWithLineNumber = new ParenthesesExpression(2, expression);
assertTrue(parenthesesExpressionWithLineNumber.getExpression() instanceof IntegerConstantExpression);
assertEquals(2, parenthesesExpressionWithLineNumber.getLineNumber());

// Test the copyTo method
Expression copiedExpression = parenthesesExpression.copyTo(3);
assertEquals(3, copiedExpression.getLineNumber());
assertTrue(copiedExpression instanceof ParenthesesExpression);

// Test the accept method with a simple visitor
TestVisitor visitor = new TestVisitor();
copiedExpression.accept(visitor);
assertEquals(1, visitor.getParenthesesExpressionCount());
}
}

0 comments on commit b927174

Please sign in to comment.