forked from JavaTX/JavaCompilerCore
Add Test case for FamilyOfGenerics
This commit is contained in:
parent
b91aadf24a
commit
7ced6338cb
@ -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<TPHConstraint> inputConstraints = new ArrayList<>();
|
||||
inputConstraints.add(new TPHConstraint("B", "A", TPHConstraint.Relation.EXTENDS));
|
||||
|
||||
HashMap<String, PositionFinder.Position> tphPositions = new HashMap<>();
|
||||
tphPositions.put("A", PositionFinder.Position.METHOD);
|
||||
tphPositions.put("B", PositionFinder.Position.METHOD);
|
||||
|
||||
List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions);
|
||||
assertTrue(classConstraints.isEmpty());
|
||||
|
||||
/*
|
||||
MethodConstraints should be the same as the input constraint
|
||||
*/
|
||||
List<MethodConstraint> 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<TPHConstraint> inputConstraints = new ArrayList<>();
|
||||
inputConstraints.add(new TPHConstraint("A", "B", TPHConstraint.Relation.EXTENDS));
|
||||
|
||||
HashMap<String, PositionFinder.Position> 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<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions);
|
||||
assertTrue(classConstraints.size() == 1);
|
||||
assertTrue(classConstraints.get(0).getLeft().equals("A"));
|
||||
assertTrue(classConstraints.get(0).getRight().equals("B"));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user