-
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 18, 2023
1 parent
6730466
commit 59fe6aa
Showing
12 changed files
with
718 additions
and
11 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
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
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
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
65 changes: 65 additions & 0 deletions
65
src/test/java/org/jd/core/v1/model/javasyntax/expression/ArrayVariableInitializerTest.java
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,65 @@ | ||
package org.jd.core.v1.model.javasyntax.expression; | ||
|
||
import org.jd.core.v1.model.javasyntax.declaration.ArrayVariableInitializer; | ||
import org.jd.core.v1.model.javasyntax.declaration.ExpressionVariableInitializer; | ||
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 ArrayVariableInitializerTest { | ||
private static final int LINE_NUMBER = 1; | ||
private static final Type TEST_TYPE = ObjectType.TYPE_STRING; | ||
|
||
@Test | ||
public void testArrayVariableInitializer() { | ||
Expression expression1 = new IntegerConstantExpression(1, 42); | ||
Expression expression2 = new StringConstantExpression(2, "Hello"); | ||
|
||
ExpressionVariableInitializer variableInitializer1 = new ExpressionVariableInitializer(expression1); | ||
ExpressionVariableInitializer variableInitializer2 = new ExpressionVariableInitializer(expression2); | ||
|
||
ArrayVariableInitializer arrayInitializer1 = new ArrayVariableInitializer(TEST_TYPE); | ||
arrayInitializer1.add(variableInitializer1); | ||
arrayInitializer1.add(variableInitializer2); | ||
|
||
ArrayVariableInitializer arrayInitializer2 = new ArrayVariableInitializer(TEST_TYPE); | ||
arrayInitializer2.add(variableInitializer1); | ||
arrayInitializer2.add(variableInitializer2); | ||
|
||
assertEquals(2, arrayInitializer1.size()); | ||
assertEquals(variableInitializer1, arrayInitializer1.get(0)); | ||
assertEquals(variableInitializer2, arrayInitializer1.get(1)); | ||
assertEquals(TEST_TYPE, arrayInitializer1.getType()); | ||
assertEquals(1, arrayInitializer1.getLineNumber()); | ||
|
||
assertEquals(arrayInitializer1, arrayInitializer2); // Same elements | ||
assertEquals(arrayInitializer2, arrayInitializer1); // Reversed order | ||
assertNotEquals(arrayInitializer1, null); | ||
assertNotEquals(arrayInitializer1, "Not an ArrayVariableInitializer"); | ||
assertEquals(arrayInitializer1, arrayInitializer1); | ||
|
||
TestVisitor visitor = new TestVisitor(); | ||
arrayInitializer1.accept(visitor); | ||
assertEquals(1, visitor.getArrayVariableInitializerCount()); | ||
|
||
int hashCode1 = arrayInitializer1.hashCode(); | ||
int hashCode2 = arrayInitializer2.hashCode(); | ||
assertEquals(hashCode1, hashCode2); | ||
} | ||
|
||
@Test | ||
public void testAcceptWithTestVisitor() { | ||
TestVisitor visitor = new TestVisitor(); | ||
|
||
ArrayVariableInitializer arrayInitializer = new ArrayVariableInitializer(TEST_TYPE); | ||
NewInitializedArray newInitializedArray = new NewInitializedArray(LINE_NUMBER, TEST_TYPE, arrayInitializer); | ||
|
||
newInitializedArray.accept(visitor); | ||
|
||
assertEquals(1, visitor.getNewInitializedArrayCount()); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
src/test/java/org/jd/core/v1/model/javasyntax/expression/BaseExpressionTest.java
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,64 @@ | ||
package org.jd.core.v1.model.javasyntax.expression; | ||
|
||
import org.jd.core.v1.model.javasyntax.type.ObjectType; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
|
||
public class BaseExpressionTest implements BaseExpression { | ||
|
||
@Override | ||
public void accept(ExpressionVisitor visitor) {} | ||
|
||
@Test | ||
public void test() { | ||
assertFalse(isArrayExpression()); | ||
assertFalse(isBinaryOperatorExpression()); | ||
assertFalse(isBooleanExpression()); | ||
assertFalse(isCastExpression()); | ||
assertFalse(isConstructorInvocationExpression()); | ||
assertFalse(isDoubleConstantExpression()); | ||
assertFalse(isFieldReferenceExpression()); | ||
assertFalse(isFloatConstantExpression()); | ||
assertFalse(isIntegerConstantExpression()); | ||
assertFalse(isLengthExpression()); | ||
assertFalse(isLocalVariableReferenceExpression()); | ||
assertFalse(isLongConstantExpression()); | ||
assertFalse(isMethodInvocationExpression()); | ||
assertFalse(isNew()); | ||
assertFalse(isNewArray()); | ||
assertFalse(isNewExpression()); | ||
assertFalse(isNewInitializedArray()); | ||
assertFalse(isNullExpression()); | ||
assertFalse(isObjectTypeReferenceExpression()); | ||
assertFalse(isPostOperatorExpression()); | ||
assertFalse(isPreOperatorExpression()); | ||
assertFalse(isStringConstantExpression()); | ||
assertFalse(isSuperConstructorInvocationExpression()); | ||
assertFalse(isSuperExpression()); | ||
assertFalse(isTernaryOperatorExpression()); | ||
assertFalse(isThisExpression()); | ||
|
||
assertEquals(NoExpression.NO_EXPRESSION, getDimensionExpressionList()); | ||
assertEquals(NoExpression.NO_EXPRESSION, getParameters()); | ||
assertEquals(NoExpression.NO_EXPRESSION, getCondition()); | ||
assertEquals(NoExpression.NO_EXPRESSION, getExpression()); | ||
assertEquals(NoExpression.NO_EXPRESSION, getTrueExpression()); | ||
assertEquals(NoExpression.NO_EXPRESSION, getFalseExpression()); | ||
assertEquals(NoExpression.NO_EXPRESSION, getIndex()); | ||
assertEquals(NoExpression.NO_EXPRESSION, getLeftExpression()); | ||
assertEquals(NoExpression.NO_EXPRESSION, getRightExpression()); | ||
|
||
assertEquals("", getDescriptor()); | ||
assertEquals(0D, getDoubleValue(), 0.00001D); | ||
assertEquals(0F, getFloatValue(), 0.00001F); | ||
assertEquals(0, getIntegerValue()); | ||
assertEquals("", getInternalTypeName()); | ||
assertEquals(0L, getLongValue()); | ||
assertEquals("", getName()); | ||
assertEquals(ObjectType.TYPE_UNDEFINED_OBJECT, getObjectType()); | ||
assertEquals("", getOperator()); | ||
assertEquals("", getStringValue()); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
src/test/java/org/jd/core/v1/model/javasyntax/expression/FieldReferenceExpressionTest.java
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,57 @@ | ||
package org.jd.core.v1.model.javasyntax.expression; | ||
|
||
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.assertTrue; | ||
|
||
public class FieldReferenceExpressionTest { | ||
|
||
@Test | ||
public void testFieldReferenceExpression() { | ||
Type type = ObjectType.TYPE_STRING; | ||
Expression expression = new ThisExpression(2, type); | ||
String internalTypeName = "java.lang.String"; | ||
String name = "length"; | ||
String descriptor = "I"; | ||
|
||
FieldReferenceExpression fieldReferenceExpression = new FieldReferenceExpression(type, expression, internalTypeName, name, descriptor); | ||
|
||
// Getters | ||
assertEquals(type, fieldReferenceExpression.getType()); | ||
assertEquals(expression, fieldReferenceExpression.getExpression()); | ||
assertEquals(internalTypeName, fieldReferenceExpression.getInternalTypeName()); | ||
assertEquals(name, fieldReferenceExpression.getName()); | ||
assertEquals(descriptor, fieldReferenceExpression.getDescriptor()); | ||
assertTrue(fieldReferenceExpression.isFieldReferenceExpression()); | ||
assertEquals("FieldReferenceExpression{type=" + type + ", expression=" + expression + ", name=" + name + ", descriptor=" + descriptor + "}", fieldReferenceExpression.toString()); | ||
|
||
// Setters | ||
Expression newExpression = new FieldReferenceExpression(3, type, null, internalTypeName, name, descriptor); | ||
fieldReferenceExpression.setExpression(newExpression); | ||
fieldReferenceExpression.setName("newName"); | ||
|
||
assertEquals(newExpression, fieldReferenceExpression.getExpression()); | ||
assertEquals("newName", fieldReferenceExpression.getName()); | ||
|
||
// Accept method | ||
TestVisitor testVisitor = new TestVisitor(); | ||
fieldReferenceExpression.accept(testVisitor); | ||
|
||
assertEquals(1, testVisitor.getFieldReferenceExpressionCount()); | ||
|
||
// Copy method | ||
FieldReferenceExpression copiedExpression = (FieldReferenceExpression) fieldReferenceExpression.copyTo(4); | ||
assertEquals(4, copiedExpression.getLineNumber()); | ||
assertEquals(type, copiedExpression.getType()); | ||
assertEquals(newExpression, copiedExpression.getExpression()); | ||
assertEquals(internalTypeName, copiedExpression.getInternalTypeName()); | ||
assertEquals("newName", copiedExpression.getName()); | ||
assertEquals(descriptor, copiedExpression.getDescriptor()); | ||
assertTrue(copiedExpression.isFieldReferenceExpression()); | ||
assertEquals("FieldReferenceExpression{type=" + type + ", expression=" + newExpression + ", name=newName, descriptor=" + descriptor + "}", copiedExpression.toString()); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/test/java/org/jd/core/v1/model/javasyntax/expression/NewArrayTest.java
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,47 @@ | ||
package org.jd.core.v1.model.javasyntax.expression; | ||
|
||
import org.jd.core.v1.model.javasyntax.type.Type; | ||
import org.jd.core.v1.service.converter.classfiletojavasyntax.visitor.TestVisitor; | ||
import org.jd.core.v1.model.javasyntax.type.ObjectType; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class NewArrayTest { | ||
private static final int LINE_NUMBER = 1; | ||
private static final Type TEST_TYPE = ObjectType.TYPE_OBJECT; | ||
|
||
@Test | ||
public void testNewArray() { | ||
BaseExpression dimensionExpressionList = new IntegerConstantExpression(LINE_NUMBER, 0); | ||
NewArray newArray = new NewArray(LINE_NUMBER, TEST_TYPE, dimensionExpressionList); | ||
|
||
assertTrue(newArray.isEmptyNewArray()); | ||
assertSame(dimensionExpressionList, newArray.getDimensionExpressionList()); | ||
|
||
BaseExpression newDimensionExpressionList = new IntegerConstantExpression(LINE_NUMBER, 1); | ||
newArray.setDimensionExpressionList(newDimensionExpressionList); | ||
|
||
assertFalse(newArray.isEmptyNewArray()); | ||
assertSame(newDimensionExpressionList, newArray.getDimensionExpressionList()); | ||
|
||
assertEquals(0, newArray.getPriority()); | ||
assertTrue(newArray.isNewArray()); | ||
assertTrue(newArray.isNew()); | ||
|
||
String expectedString = "NewArray{" + TEST_TYPE + "}"; | ||
assertEquals(expectedString, newArray.toString()); | ||
|
||
int newLineNumber = 2; | ||
Expression copiedNewArray = newArray.copyTo(newLineNumber); | ||
|
||
assertTrue(copiedNewArray instanceof NewArray); | ||
assertEquals(newLineNumber, copiedNewArray.getLineNumber()); | ||
assertEquals(TEST_TYPE, ((NewArray) copiedNewArray).getType()); | ||
assertSame(newDimensionExpressionList, ((NewArray) copiedNewArray).getDimensionExpressionList()); | ||
|
||
TestVisitor testVisitor = new TestVisitor(); | ||
newArray.accept(testVisitor); | ||
assertEquals(1, testVisitor.getNewArrayCount()); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
src/test/java/org/jd/core/v1/model/javasyntax/expression/NewExpressionTest.java
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,71 @@ | ||
package org.jd.core.v1.model.javasyntax.expression; | ||
|
||
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.assertFalse; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class NewExpressionTest { | ||
|
||
@Test | ||
public void testNewExpression() { | ||
int lineNumber = 1; | ||
Type type = ObjectType.TYPE_STRING; | ||
String descriptor = "Ljava/lang/String;"; | ||
boolean varArgs = true; | ||
boolean diamondPossible = false; | ||
|
||
NewExpression newExpression = new NewExpression(lineNumber, (ObjectType) type, descriptor, varArgs, diamondPossible); | ||
|
||
// Getters | ||
assertEquals(lineNumber, newExpression.getLineNumber()); | ||
assertEquals(type, newExpression.getObjectType()); | ||
assertEquals(type, newExpression.getType()); | ||
assertEquals(descriptor, newExpression.getDescriptor()); | ||
assertNull(newExpression.getParameters()); | ||
assertNull(newExpression.getBodyDeclaration()); | ||
assertTrue(newExpression.isVarArgs()); | ||
assertFalse(newExpression.isDiamondPossible()); | ||
assertTrue(newExpression.isNewExpression()); | ||
assertTrue(newExpression.isNew()); | ||
assertEquals("NewExpression{new " + type + "}", newExpression.toString()); | ||
|
||
// Setters | ||
BaseExpression parameters = new IntegerConstantExpression(2, 42); | ||
newExpression.setParameters(parameters); | ||
newExpression.setDiamondPossible(true); | ||
newExpression.setQualifier(new ThisExpression(3, type)); | ||
|
||
assertEquals(parameters, newExpression.getParameters()); | ||
assertTrue(newExpression.isDiamondPossible()); | ||
assertNotNull(newExpression.getQualifier()); | ||
|
||
// Accept method | ||
TestVisitor testVisitor = new TestVisitor(); | ||
newExpression.accept(testVisitor); | ||
|
||
assertEquals(1, testVisitor.getNewExpressionCount()); | ||
|
||
// Copy method | ||
NewExpression copiedExpression = (NewExpression) newExpression.copyTo(4); | ||
assertEquals(4, copiedExpression.getLineNumber()); | ||
assertEquals(type, copiedExpression.getType()); | ||
assertEquals(descriptor, copiedExpression.getDescriptor()); | ||
assertNull(copiedExpression.getParameters()); | ||
assertNull(copiedExpression.getBodyDeclaration()); | ||
assertTrue(copiedExpression.isVarArgs()); | ||
assertTrue(copiedExpression.isDiamondPossible()); | ||
assertTrue(copiedExpression.isNewExpression()); | ||
assertEquals("NewExpression{new " + type + "}", copiedExpression.toString()); | ||
|
||
// Priority | ||
assertEquals(0, newExpression.getPriority()); | ||
} | ||
|
||
} |
Oops, something went wrong.