From 1895862dca68163c6375fa07c108534a9090c138 Mon Sep 17 00:00:00 2001 From: nbauma109 Date: Sun, 21 May 2023 18:05:29 +0200 Subject: [PATCH] added TypeArgumentToTypeVisitorTest --- .../TypeArgumentToTypeVisitorTest.java | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/test/java/org/jd/core/v1/service/converter/classfiletojavasyntax/visitor/TypeArgumentToTypeVisitorTest.java diff --git a/src/test/java/org/jd/core/v1/service/converter/classfiletojavasyntax/visitor/TypeArgumentToTypeVisitorTest.java b/src/test/java/org/jd/core/v1/service/converter/classfiletojavasyntax/visitor/TypeArgumentToTypeVisitorTest.java new file mode 100644 index 0000000..d42edf8 --- /dev/null +++ b/src/test/java/org/jd/core/v1/service/converter/classfiletojavasyntax/visitor/TypeArgumentToTypeVisitorTest.java @@ -0,0 +1,71 @@ +package org.jd.core.v1.service.converter.classfiletojavasyntax.visitor; + +import org.jd.core.v1.model.javasyntax.type.DiamondTypeArgument; +import org.jd.core.v1.model.javasyntax.type.GenericType; +import org.jd.core.v1.model.javasyntax.type.ObjectType; +import org.jd.core.v1.model.javasyntax.type.PrimitiveType; +import org.jd.core.v1.model.javasyntax.type.TypeArguments; +import org.jd.core.v1.model.javasyntax.type.WildcardExtendsTypeArgument; +import org.jd.core.v1.model.javasyntax.type.WildcardSuperTypeArgument; +import org.jd.core.v1.model.javasyntax.type.WildcardTypeArgument; +import org.jd.core.v1.service.converter.classfiletojavasyntax.util.TypeMaker; +import org.junit.Test; + +import java.util.Arrays; + +import static org.junit.Assert.assertEquals; + +public class TypeArgumentToTypeVisitorTest { + + @Test + public void testTypeArgumentToTypeVisitor() { + // Arrange + TypeArgumentToTypeVisitor visitor = new TypeArgumentToTypeVisitor(); + visitor.init(); + + // Act & Assert - PrimitiveType + PrimitiveType primitiveType = PrimitiveType.TYPE_INT; + primitiveType.accept(visitor); + assertEquals(primitiveType, visitor.getType()); + + // Act & Assert - ObjectType + ObjectType objectType = ObjectType.TYPE_STRING; + objectType.accept(visitor); + assertEquals(objectType, visitor.getType()); + + // Act & Assert - InnerObjectType + ObjectType innerObjectType = new TypeMaker().makeFromInternalTypeName("java/util/Map$Entry"); + innerObjectType.accept(visitor); + assertEquals(innerObjectType, visitor.getType()); + + // Act & Assert - GenericType + GenericType genericType = new GenericType("T"); + genericType.accept(visitor); + assertEquals(genericType, visitor.getType()); + + // Act & Assert - WildcardExtendsTypeArgument + WildcardExtendsTypeArgument wildcardExtendsTypeArgument = new WildcardExtendsTypeArgument(ObjectType.TYPE_OBJECT); + wildcardExtendsTypeArgument.accept(visitor); + assertEquals(ObjectType.TYPE_OBJECT, visitor.getType()); + + // Act & Assert - WildcardSuperTypeArgument + WildcardSuperTypeArgument wildcardSuperTypeArgument = new WildcardSuperTypeArgument(ObjectType.TYPE_OBJECT); + wildcardSuperTypeArgument.accept(visitor); + assertEquals(ObjectType.TYPE_OBJECT, visitor.getType()); + + // Act & Assert - DiamondTypeArgument + DiamondTypeArgument diamondTypeArgument = DiamondTypeArgument.DIAMOND; + diamondTypeArgument.accept(visitor); + assertEquals(ObjectType.TYPE_OBJECT, visitor.getType()); + + // Act & Assert - WildcardTypeArgument + WildcardTypeArgument wildcardTypeArgument = WildcardTypeArgument.WILDCARD_TYPE_ARGUMENT; + wildcardTypeArgument.accept(visitor); + assertEquals(ObjectType.TYPE_OBJECT, visitor.getType()); + + // Act & Assert - TypeArguments + TypeArguments typeArguments = new TypeArguments(Arrays.asList(ObjectType.TYPE_OBJECT)); + typeArguments.accept(visitor); + assertEquals(ObjectType.TYPE_UNDEFINED_OBJECT, visitor.getType()); + } +}