-
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.
Merge pull request #35 from nbauma109/bind-types-to-types-visitor-test
added BindTypesToTypesVisitorTest
- Loading branch information
Showing
3 changed files
with
107 additions
and
4 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
100 changes: 100 additions & 0 deletions
100
.../core/v1/service/converter/classfiletojavasyntax/visitor/BindTypesToTypesVisitorTest.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,100 @@ | ||
package org.jd.core.v1.service.converter.classfiletojavasyntax.visitor; | ||
|
||
import org.jd.core.v1.model.javasyntax.type.BaseType; | ||
import org.jd.core.v1.model.javasyntax.type.GenericType; | ||
import org.jd.core.v1.model.javasyntax.type.InnerObjectType; | ||
import org.jd.core.v1.model.javasyntax.type.ObjectType; | ||
import org.jd.core.v1.model.javasyntax.type.TypeArgument; | ||
import org.jd.core.v1.model.javasyntax.type.WildcardTypeArgument; | ||
import org.jd.core.v1.service.converter.classfiletojavasyntax.util.TypeMaker; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class BindTypesToTypesVisitorTest { | ||
private BindTypesToTypesVisitor visitor; | ||
private Map<String, TypeArgument> bindings; | ||
private TypeMaker typeMaker; | ||
|
||
@Before | ||
public void setup() { | ||
visitor = new BindTypesToTypesVisitor(); | ||
bindings = new HashMap<>(); | ||
typeMaker = new TypeMaker(); | ||
visitor.setBindings(bindings); | ||
} | ||
|
||
@Test | ||
public void visitGenericTypeWhenTypeArgumentIsNull() { | ||
// Given | ||
GenericType genericType = new GenericType("Test", 0); | ||
bindings.put("Test", null); | ||
|
||
// When | ||
visitor.init(); | ||
genericType.accept(visitor); | ||
|
||
// Then | ||
BaseType result = visitor.getType(); | ||
assertEquals(ObjectType.TYPE_OBJECT.createType(0), result); | ||
} | ||
|
||
@Test | ||
public void visitGenericTypeWhenTypeArgumentIsWildcard() { | ||
// Given | ||
GenericType genericType = new GenericType("Test", 0); | ||
bindings.put("Test", WildcardTypeArgument.WILDCARD_TYPE_ARGUMENT); | ||
|
||
// When | ||
visitor.init(); | ||
genericType.accept(visitor); | ||
|
||
// Then | ||
BaseType result = visitor.getType(); | ||
assertEquals(ObjectType.TYPE_OBJECT.createType(0), result); | ||
} | ||
|
||
@Test | ||
public void visitGenericTypeWhenTypeArgumentIsNotWildcardNorNull() { | ||
// Given | ||
GenericType genericType = new GenericType("Test", 0); | ||
ObjectType typeArgument = ObjectType.TYPE_OBJECT; | ||
bindings.put("Test", typeArgument); | ||
|
||
// When | ||
visitor.init(); | ||
genericType.accept(visitor); | ||
|
||
// Then | ||
BaseType result = visitor.getType(); | ||
|
||
// Assuming that result is equivalent to what | ||
// typeArgumentToTypeVisitor.getType() returns, with increased dimension | ||
assertEquals(typeArgument.createType(0 + genericType.getDimension()), result); | ||
} | ||
|
||
@Test | ||
public void visitInnerObjectTypeWhenResultIsNotEqualOuterTypeAndTypeArgumentsIsNotWildcardNorNull() { | ||
// Given | ||
ObjectType outerType = typeMaker.makeFromInternalTypeName("OuterType<T>"); | ||
InnerObjectType innerObjectType = (InnerObjectType) typeMaker.makeFromInternalTypeName("OuterType<T>$InnerType<U>"); | ||
|
||
outerType.accept(visitor); | ||
|
||
// When | ||
visitor.init(); | ||
innerObjectType.accept(visitor); | ||
|
||
// Then | ||
BaseType result = visitor.getType(); | ||
|
||
// Assuming that when typeArguments is not WildcardTypeArgument or null and | ||
// result is not equal to outerType, | ||
// the result is a new InnerObjectType with the same typeArguments | ||
assertEquals(innerObjectType, result); | ||
} | ||
} |