modified: src/test/java/insertGenerics/FamilyOfGeneratedGenericsTest.java

This commit is contained in:
AluAli 2020-12-04 16:44:46 +01:00
parent c2f0368d2e
commit d671e74fcf

View File

@ -31,7 +31,7 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
/* /*
MethodConstraints should be the same as the input constraint MethodConstraints should be the same as the input constraint
*//* */
List<MethodConstraint> methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(inputConstraints, tphPositions); List<MethodConstraint> methodConstraints = FamilyOfGeneratedGenerics.getMethodConstraints(inputConstraints, tphPositions);
assertTrue(methodConstraints.size() == 1); assertTrue(methodConstraints.size() == 1);
assertTrue(methodConstraints.get(0).getLeft().equals("B")); assertTrue(methodConstraints.get(0).getLeft().equals("B"));
@ -39,7 +39,7 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
} }
public void testClassField(){ public void testClassField(){
*//* /*
class Example{ class Example{
A f; A f;
B fReturn(){ B fReturn(){
@ -47,18 +47,20 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
} }
} }
gives constraint: A <. B, which is a class constraint gives constraint: A <. B, which is a class constraint
*//* */
List<TPHConstraint> inputConstraints = new ArrayList<>(); List<TPHConstraint> inputConstraints = new ArrayList<>();
inputConstraints.add(new TPHConstraint("A", "B", TPHConstraint.Relation.EXTENDS)); inputConstraints.add(new TPHConstraint("A", "B", TPHConstraint.Relation.EXTENDS));
HashMap<String, PairTphMethod<PositionFinder.Position, String>> tphPositions = new HashMap<>(); HashMap<String, PairTphMethod<PositionFinder.Position, String>> tphPositions = new HashMap<>();
tphPositions.put("A", PositionFinder.Position.FIELD); PairTphMethod<PositionFinder.Position, String> posOfA = new PairTphMethod<>(PositionFinder.Position.FIELD, null);
tphPositions.put("B", PositionFinder.Position.METHOD); tphPositions.put("A", posOfA);
PairTphMethod<PositionFinder.Position, String> posOfB = new PairTphMethod<>(PositionFinder.Position.METHOD, "fReturn");
tphPositions.put("B", posOfB);
*//* /*
ClassConstraints should not be the same as the input constraint ClassConstraints should not be the same as the input constraint
*//* */
List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions); List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions);
System.out.println(classConstraints); System.out.println(classConstraints);
assertTrue(classConstraints.size() == 2); assertTrue(classConstraints.size() == 2);
@ -67,7 +69,7 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
} }
public void testSecondLineOfClassConstraints() { public void testSecondLineOfClassConstraints() {
*//* /*
class Example() { class Example() {
A a; A a;
B b = a; B b = a;
@ -81,7 +83,7 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
return e; return e;
} }
} }
*//* */
List<TPHConstraint> inputConstraints = new ArrayList<>(); List<TPHConstraint> inputConstraints = new ArrayList<>();
inputConstraints.add(new TPHConstraint("A", "B", TPHConstraint.Relation.EXTENDS)); inputConstraints.add(new TPHConstraint("A", "B", TPHConstraint.Relation.EXTENDS));
@ -91,12 +93,19 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
inputConstraints.add(new TPHConstraint("E", "D", TPHConstraint.Relation.EXTENDS)); inputConstraints.add(new TPHConstraint("E", "D", TPHConstraint.Relation.EXTENDS));
HashMap<String, PairTphMethod<PositionFinder.Position, String>> tphPositions = new HashMap<>(); HashMap<String, PairTphMethod<PositionFinder.Position, String>> tphPositions = new HashMap<>();
tphPositions.put("A", PositionFinder.Position.FIELD); PairTphMethod<PositionFinder.Position, String> posOfA = new PairTphMethod<>(PositionFinder.Position.FIELD, null);
tphPositions.put("B", PositionFinder.Position.FIELD); PairTphMethod<PositionFinder.Position, String> posOfB = new PairTphMethod<>(PositionFinder.Position.FIELD, null);
tphPositions.put("C", PositionFinder.Position.METHOD); PairTphMethod<PositionFinder.Position, String> posOfC = new PairTphMethod<>(PositionFinder.Position.METHOD, "anyMethod");
tphPositions.put("F", PositionFinder.Position.METHOD); PairTphMethod<PositionFinder.Position, String> posOfD = new PairTphMethod<>(PositionFinder.Position.METHOD, "otherMethod");
tphPositions.put("D", PositionFinder.Position.METHOD); PairTphMethod<PositionFinder.Position, String> posOfE = new PairTphMethod<>(PositionFinder.Position.METHOD, "otherMethod");
tphPositions.put("E", PositionFinder.Position.METHOD); PairTphMethod<PositionFinder.Position, String> posOfF = new PairTphMethod<>(PositionFinder.Position.METHOD, "anyMethod");
tphPositions.put("A", posOfA);
tphPositions.put("B", posOfB);
tphPositions.put("C", posOfC);
tphPositions.put("F", posOfF);
tphPositions.put("D", posOfD);
tphPositions.put("E", posOfE);
List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions); List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions);
System.out.println(classConstraints); System.out.println(classConstraints);
@ -106,7 +115,7 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
} }
public void testTPHsAndGenerics() { public void testTPHsAndGenerics() {
*//* /*
class TPHsAndGenerics { class TPHsAndGenerics {
Fun1<A,B> id = x -> x; Fun1<A,B> id = x -> x;
C id2 (D x) { C id2 (D x) {
@ -120,7 +129,7 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
return b; return b;
} }
} }
*//* */
List<TPHConstraint> inputConstraints = new ArrayList<>(); List<TPHConstraint> inputConstraints = new ArrayList<>();
inputConstraints.add(new TPHConstraint("A","B", TPHConstraint.Relation.EXTENDS)); inputConstraints.add(new TPHConstraint("A","B", TPHConstraint.Relation.EXTENDS));
@ -132,23 +141,34 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
inputConstraints.add(new TPHConstraint("J","H", TPHConstraint.Relation.EXTENDS)); inputConstraints.add(new TPHConstraint("J","H", TPHConstraint.Relation.EXTENDS));
HashMap<String, PairTphMethod<PositionFinder.Position, String>> tphPositions = new HashMap<>(); HashMap<String, PairTphMethod<PositionFinder.Position, String>> tphPositions = new HashMap<>();
tphPositions.put("A", PositionFinder.Position.FIELD); PairTphMethod<PositionFinder.Position, String> posOfA = new PairTphMethod<>(PositionFinder.Position.FIELD, null);
tphPositions.put("B", PositionFinder.Position.FIELD); PairTphMethod<PositionFinder.Position, String> posOfB = new PairTphMethod<>(PositionFinder.Position.FIELD, null);
tphPositions.put("C", PositionFinder.Position.METHOD); PairTphMethod<PositionFinder.Position, String> posOfC = new PairTphMethod<>(PositionFinder.Position.METHOD, "id2");
tphPositions.put("D", PositionFinder.Position.METHOD); PairTphMethod<PositionFinder.Position, String> posOfD = new PairTphMethod<>(PositionFinder.Position.METHOD, "id2");
tphPositions.put("E", PositionFinder.Position.METHOD); PairTphMethod<PositionFinder.Position, String> posOfE = new PairTphMethod<>(PositionFinder.Position.METHOD, "m");
tphPositions.put("F", PositionFinder.Position.METHOD); PairTphMethod<PositionFinder.Position, String> posOfF = new PairTphMethod<>(PositionFinder.Position.METHOD, "m");
tphPositions.put("G", PositionFinder.Position.METHOD); PairTphMethod<PositionFinder.Position, String> posOfG = new PairTphMethod<>(PositionFinder.Position.METHOD, "m");
tphPositions.put("H", PositionFinder.Position.METHOD); PairTphMethod<PositionFinder.Position, String> posOfH = new PairTphMethod<>(PositionFinder.Position.METHOD, "m2");
tphPositions.put("I", PositionFinder.Position.METHOD); PairTphMethod<PositionFinder.Position, String> posOfI = new PairTphMethod<>(PositionFinder.Position.METHOD, "m2");
tphPositions.put("J", PositionFinder.Position.METHOD); PairTphMethod<PositionFinder.Position, String> posOfJ = new PairTphMethod<>(PositionFinder.Position.METHOD, "m2");
tphPositions.put("A", posOfA);
tphPositions.put("B", posOfB);
tphPositions.put("C", posOfC);
tphPositions.put("D", posOfD);
tphPositions.put("E", posOfE);
tphPositions.put("F", posOfF);
tphPositions.put("G", posOfG);
tphPositions.put("H", posOfH);
tphPositions.put("I", posOfI);
tphPositions.put("J", posOfJ);
List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions); List<ClassConstraint> classConstraints = FamilyOfGeneratedGenerics.getClassConstraints(inputConstraints, tphPositions);
System.out.println(classConstraints); System.out.println(classConstraints);
assertFalse(classConstraints.isEmpty()); assertFalse(classConstraints.isEmpty());
assertTrue(classConstraints.size() == 3); assertTrue(classConstraints.size() == 3);
}*/ }
public void testPositionConverter() { public void testPositionConverter() {
@ -160,7 +180,7 @@ public class FamilyOfGeneratedGenericsTest extends TestCase {
m1.getTphs().add("A"); m1.getTphs().add("A");
MethodAndTPH bla = new MethodAndTPH("bla"); MethodAndTPH bla = new MethodAndTPH("bla");
MethodAndTPH blubb = new MethodAndTPH("blubb"); MethodAndTPH blubb = new MethodAndTPH("blubb");
blubb.getTphs().add("A"); // blubb.getTphs().add("A");
listOfMethodsAndTphs.add(bla); listOfMethodsAndTphs.add(bla);
listOfMethodsAndTphs.add(blubb); listOfMethodsAndTphs.add(blubb);
listOfMethodsAndTphs.add(m1); listOfMethodsAndTphs.add(m1);