Skip to content

Commit

Permalink
added StringConstantExpressionTest
Browse files Browse the repository at this point in the history
  • Loading branch information
nbauma109 committed May 21, 2023
1 parent bdf8dcd commit 4d9f9ec
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/test/java/StringConstantExpressionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import org.jd.core.v1.model.javasyntax.expression.StringConstantExpression;
import org.jd.core.v1.model.javasyntax.type.ObjectType;
import org.jd.core.v1.service.converter.classfiletojavasyntax.visitor.TestVisitor;
import org.junit.Assert;
import org.junit.Test;

public class StringConstantExpressionTest {

@Test
public void testStringConstantExpression() {
// Arrange
int lineNumber = 10;
String string = "Hello, World!";
TestVisitor visitor = new TestVisitor();

// Act
StringConstantExpression expression = new StringConstantExpression(lineNumber, string);
expression.accept(visitor);

// Assert
Assert.assertEquals(lineNumber, expression.getLineNumber());
Assert.assertEquals(string, expression.getStringValue());
Assert.assertEquals(ObjectType.TYPE_STRING, expression.getType());
Assert.assertTrue(expression.isStringConstantExpression());
Assert.assertEquals(1, visitor.getStringConstantExpressionCount());

// Test toString method
String expectedToString = "StringConstantExpression{\"Hello, World!\"}";
Assert.assertEquals(expectedToString, expression.toString());

// Test copyTo method
int newLineNumber = 20;
StringConstantExpression copiedExpression = (StringConstantExpression) expression.copyTo(newLineNumber);
Assert.assertEquals(newLineNumber, copiedExpression.getLineNumber());
Assert.assertEquals(string, copiedExpression.getStringValue());
}
}

0 comments on commit 4d9f9ec

Please sign in to comment.