-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
nbauma109
committed
May 21, 2023
1 parent
bdf8dcd
commit 4d9f9ec
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |