From 7ced6338cb3f14cabe58681811367b00997b83b4 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Fri, 6 Nov 2020 16:34:32 +0100 Subject: [PATCH] Add Test case for FamilyOfGenerics --- .../FamilyOfGeneratedGenericsTest.java | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java diff --git a/src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java b/src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java new file mode 100644 index 00000000..c4cbeb93 --- /dev/null +++ b/src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java @@ -0,0 +1,68 @@ +package insertGenerics; + +import de.dhbwstuttgart.bytecode.constraint.TPHConstraint; +import de.dhbwstuttgart.bytecode.gGenericsAli.ClassConstraint; +import de.dhbwstuttgart.bytecode.gGenericsAli.FamilyOfGeneratedGenerics; +import de.dhbwstuttgart.bytecode.gGenericsAli.MethodConstraint; +import de.dhbwstuttgart.bytecode.gGenericsAli.PositionFinder; +import junit.framework.TestCase; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +public class FamilyOfGeneratedGenericsTest extends TestCase { + + public void testIdentityMethod(){ + /* + Example method: + A id(B i) return i; + gives constraint: B <. A, which is a method constraint + */ + + List inputConstraints = new ArrayList<>(); + inputConstraints.add(new TPHConstraint("B", "A", TPHConstraint.Relation.EXTENDS)); + + HashMap tphPositions = new HashMap<>(); + tphPositions.put("A", PositionFinder.Position.METHOD); + tphPositions.put("B", PositionFinder.Position.METHOD); + + List classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions); + assertTrue(classConstraints.isEmpty()); + + /* + MethodConstraints should be the same as the input constraint + */ + List methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(inputConstraints, tphPositions); + assertTrue(methodConstraints.size() == 1); + assertTrue(methodConstraints.get(0).getLeft().equals("B")); + assertTrue(methodConstraints.get(0).getRight().equals("A")); + } + + public void testClassField(){ + /* + class Example{ + A f; + B fReturn(){ + return f; + } + } + gives constraint: A <. B, which is a method constraint + */ + + List inputConstraints = new ArrayList<>(); + inputConstraints.add(new TPHConstraint("A", "B", TPHConstraint.Relation.EXTENDS)); + + HashMap tphPositions = new HashMap<>(); + tphPositions.put("A", PositionFinder.Position.METHOD); + tphPositions.put("B", PositionFinder.Position.FIELD); + + /* + ClassConstraints should be the same as the input constraint + */ + List classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions); + assertTrue(classConstraints.size() == 1); + assertTrue(classConstraints.get(0).getLeft().equals("A")); + assertTrue(classConstraints.get(0).getRight().equals("B")); + } +} \ No newline at end of file