Hinzufügen von equals() und hashCode() Tests zu IntermediateRefTypeTest und IntermediateGenericTypeTest.

This commit is contained in:
Etienne Zink 2022-03-20 16:42:12 +01:00
parent 8b58259fe0
commit f1f028f0b9
3 changed files with 36 additions and 1 deletions

View File

@ -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();
}

View File

@ -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); }
}

View File

@ -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); }
}