From f1f028f0b92214b423bd69a5811758823e2b4ff7 Mon Sep 17 00:00:00 2001 From: Etienne Zink Date: Sun, 20 Mar 2022 16:42:12 +0100 Subject: [PATCH] =?UTF-8?q?Hinzuf=C3=BCgen=20von=20equals()=20und=20hashCo?= =?UTF-8?q?de()=20Tests=20zu=20IntermediateRefTypeTest=20und=20Intermediat?= =?UTF-8?q?eGenericTypeTest.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../types/IntermediateInnerType.java | 1 - .../types/IntermediateGenericTypeTest.java | 17 +++++++++++++++++ .../types/IntermediateRefTypeTest.java | 19 +++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/dhbwstuttgart/intermediate/types/IntermediateInnerType.java b/src/main/java/de/dhbwstuttgart/intermediate/types/IntermediateInnerType.java index a83c974f..f10fe157 100644 --- a/src/main/java/de/dhbwstuttgart/intermediate/types/IntermediateInnerType.java +++ b/src/main/java/de/dhbwstuttgart/intermediate/types/IntermediateInnerType.java @@ -4,6 +4,5 @@ package de.dhbwstuttgart.intermediate.types; * Only Java types which can be used as an inner type, have a descriptor definition. */ public abstract class IntermediateInnerType extends IntermediateType { - public abstract String getDescriptor(); } diff --git a/src/test/java/intermediate/types/IntermediateGenericTypeTest.java b/src/test/java/intermediate/types/IntermediateGenericTypeTest.java index 3663faae..3c711c4e 100644 --- a/src/test/java/intermediate/types/IntermediateGenericTypeTest.java +++ b/src/test/java/intermediate/types/IntermediateGenericTypeTest.java @@ -8,6 +8,7 @@ import org.junit.Test; import org.objectweb.asm.Type; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; public class IntermediateGenericTypeTest { @@ -23,6 +24,8 @@ public class IntermediateGenericTypeTest { private static String rExtendsSDescriptor; private static IntermediateGenericType rExtendsS; + private static IntermediateGenericType rSame; + @BeforeClass public static void StartUp(){ tSignature = "TT;"; @@ -37,6 +40,8 @@ public class IntermediateGenericTypeTest { rExtendsSSignature = "TR;"; rExtendsSDescriptor = sExtendsStringDescriptor; rExtendsS = new IntermediateGenericType("R", sExtendsString); + + rSame = new IntermediateGenericType("R", sExtendsString); } @Test @@ -56,4 +61,16 @@ public class IntermediateGenericTypeTest { @Test public void DescriptorTest_TExtendsS(){ assertEquals(rExtendsSDescriptor, rExtendsS.getDescriptor()); } + + @Test + public void HashCodeTest_Succeed() { assertEquals(rSame.hashCode(), rExtendsS.hashCode());} + + @Test + public void HashCodeTest_Fail() { assertNotEquals(rSame.hashCode(), t.hashCode()); } + + @Test + public void EqualsTest_Succeed() { assertEquals(rSame, rExtendsS); } + + @Test + public void EqualsTest_Fail() { assertNotEquals(rSame, t); } } diff --git a/src/test/java/intermediate/types/IntermediateRefTypeTest.java b/src/test/java/intermediate/types/IntermediateRefTypeTest.java index b03a988e..bc287a78 100644 --- a/src/test/java/intermediate/types/IntermediateRefTypeTest.java +++ b/src/test/java/intermediate/types/IntermediateRefTypeTest.java @@ -11,6 +11,7 @@ import java.util.Arrays; import java.util.List; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; public class IntermediateRefTypeTest { @@ -26,6 +27,8 @@ public class IntermediateRefTypeTest { private static String voidDescriptor; private static IntermediateRefType typeToTest_void; + private static IntermediateRefType typeToTest_ListOfIntegerSame; + @BeforeClass public static void StartUp(){ integerSignature = "Ljava/lang/Integer;"; @@ -41,6 +44,10 @@ public class IntermediateRefTypeTest { voidSignature = "V"; voidDescriptor = "V"; typeToTest_void = new IntermediateRefType(new JavaClassName("void")); + + typeToTest_ListOfIntegerSame = new IntermediateRefType( + new JavaClassName(Type.getInternalName(List.class)), + Arrays.asList(typeToTest_Integer)); } @Test @@ -68,4 +75,16 @@ public class IntermediateRefTypeTest { public void DescriptorTest_Void(){ assertEquals(voidDescriptor, typeToTest_void.getDescriptor()); } + + @Test + public void HashCodeTest_Succeed() { assertEquals(typeToTest_ListOfIntegerSame.hashCode(), typeToTest_ListOfInteger.hashCode());} + + @Test + public void HashCodeTest_Fail() { assertNotEquals(typeToTest_ListOfIntegerSame.hashCode(), typeToTest_Integer.hashCode()); } + + @Test + public void EqualsTest_Succeed() { assertEquals(typeToTest_ListOfIntegerSame, typeToTest_ListOfInteger); } + + @Test + public void EqualsTest_Fail() { assertNotEquals(typeToTest_ListOfIntegerSame, typeToTest_Integer); } }