diff --git a/src/main/java/org/jd/core/v1/model/javasyntax/type/ObjectType.java b/src/main/java/org/jd/core/v1/model/javasyntax/type/ObjectType.java index b4bcf70..eea5f81 100644 --- a/src/main/java/org/jd/core/v1/model/javasyntax/type/ObjectType.java +++ b/src/main/java/org/jd/core/v1/model/javasyntax/type/ObjectType.java @@ -255,8 +255,7 @@ public boolean isTypeArgumentAssignableFrom(TypeMaker typeMaker, Map, dimension=1}", ObjectType.TYPE_CLASS_WILDCARD.createType(1).toString()); + } + + @Test + public void testUndefinedObjectTypeToString() { + assertEquals("UndefinedObjectType", ObjectType.TYPE_UNDEFINED_OBJECT.toString()); + } + + @Test + public void testConstructors() { + ObjectType objectType1 = new ObjectType("I", 1); + assertEquals("I", objectType1.getInternalName()); + assertEquals(1, objectType1.getDimension()); + + ObjectType objectType3 = new ObjectType("java/lang/String", "java.lang.String", "String", 2); + assertEquals("java/lang/String", objectType3.getInternalName()); + assertEquals(2, objectType3.getDimension()); + } + + @Test + public void testCreateDescriptor() { + ObjectType objectType1 = new ObjectType("I", 1); + assertEquals("[I", objectType1.getDescriptor()); + + ObjectType objectType2 = new ObjectType("I", 3); + assertEquals("[[[I", objectType2.getDescriptor()); + } + + @Test + public void testCreateType() { + ObjectType objectType1 = (ObjectType) ObjectType.TYPE_BOOLEAN.createType(0); + assertEquals(ObjectType.TYPE_BOOLEAN, objectType1); + + ObjectType objectType2 = (ObjectType) ObjectType.TYPE_BOOLEAN.createType(1); + assertNotEquals(ObjectType.TYPE_BOOLEAN, objectType2); + } + + @Test + public void testRawEquals() { + assertTrue(ObjectType.TYPE_BOOLEAN.rawEquals(ObjectType.TYPE_BOOLEAN)); + assertFalse(ObjectType.TYPE_BOOLEAN.rawEquals(ObjectType.TYPE_BYTE)); + assertFalse(ObjectType.TYPE_BOOLEAN.rawEquals(null)); + assertFalse(ObjectType.TYPE_BOOLEAN.rawEquals(PrimitiveType.TYPE_BOOLEAN)); + assertFalse(ObjectType.TYPE_BOOLEAN.rawEquals(ObjectType.TYPE_BOOLEAN.createType(1))); + assertTrue(ObjectType.TYPE_CLASS_WILDCARD.rawEquals(ObjectType.TYPE_CLASS.createType(ObjectType.TYPE_OBJECT))); + } + + @Test + public void testIsTypeArgumentAssignableFrom() { + assertTrue(ObjectType.TYPE_BOOLEAN.isTypeArgumentAssignableFrom(null, null, null, ObjectType.TYPE_BOOLEAN)); + assertFalse(ObjectType.TYPE_BOOLEAN.isTypeArgumentAssignableFrom(null, null, null, ObjectType.TYPE_BYTE)); + } + + @Test(expected = IllegalArgumentException.class) + public void testConstructorWithNullInternalName() { + new ObjectType(null, "java.lang.Integer", "Integer"); + } + + @Test(expected = IllegalArgumentException.class) + public void testConstructorWithInternalNameEndingWithSemicolon() { + new ObjectType("Ljava/lang/Integer;", "java.lang.Integer", "Integer"); + } + + @Test + public void testCreateTypeWithPrimitiveTypeAndZeroDimension() { + ObjectType objectType = new ObjectType("I", 1); + BaseType baseType = objectType.createType(0); + assertTrue(baseType.isPrimitiveType()); + assertEquals(PrimitiveType.TYPE_INT, baseType); + } + + @Test + public void testCreateTypeWithPrimitiveTypeAndDimension() { + ObjectType objectType = new ObjectType("I", 1); + BaseType baseType = objectType.createType(1); + assertTrue(baseType.isObjectType()); + assertEquals("I", baseType.getInternalName()); + } + + @Test + public void testEqualsForJavaLangClassWithWildcardTypeArguments() { + ObjectType objectType1 = new ObjectType("java/lang/Class", "java.lang.Class", "Class", WildcardTypeArgument.WILDCARD_TYPE_ARGUMENT, 0); + ObjectType objectType2 = new ObjectType("java/lang/Class", "java.lang.Class", "Class", WildcardTypeArgument.WILDCARD_TYPE_ARGUMENT, 0); + ObjectType objectType3 = new ObjectType("java/lang/Class", "java.lang.Class", "Class", Collections.emptySet(), 0); + ObjectType objectType4 = new ObjectType("java/lang/Class", "java.lang.Class", "Class", Collections.emptySet(), 0); + ObjectType objectType5 = new ObjectType("java/lang/Class", "java.lang.Class", "Class", (TypeArgument) null, 0); + + assertEquals(objectType1, objectType2); + assertEquals(objectType1, objectType3); + assertEquals(objectType3, objectType4); + assertEquals(objectType5, objectType1); + assertEquals(objectType1, objectType5); + assertEquals(objectType3, objectType5); + assertEquals(objectType5, objectType5); + assertNotEquals(objectType1, objectType5.createType(ObjectType.TYPE_OBJECT)); + assertNotEquals(objectType5.createType(ObjectType.TYPE_OBJECT), objectType1); + } + + + @Test + public void testGetInnerTypeNames() { + ObjectType objectType = new ObjectType("java/lang/Class", "java.lang.Class", "Class", Collections.singleton("InnerType"), 0); + assertEquals(Collections.singleton("InnerType"), objectType.getInnerTypeNames()); + } + +}