From 24bbce8265c5dda0517e49701dfbd8909a46592d Mon Sep 17 00:00:00 2001 From: Victorious3 Date: Tue, 21 Feb 2023 14:04:53 +0100 Subject: [PATCH] Fix test cases for new inputs --- .../bytecode/JavaTXSignatureAttribute.java | 2 + src/test/java/targetast/TestComplete.java | 44 ++++++++----------- 2 files changed, 21 insertions(+), 25 deletions(-) create mode 100644 src/main/java/de/dhbwstuttgart/bytecode/JavaTXSignatureAttribute.java diff --git a/src/main/java/de/dhbwstuttgart/bytecode/JavaTXSignatureAttribute.java b/src/main/java/de/dhbwstuttgart/bytecode/JavaTXSignatureAttribute.java new file mode 100644 index 00000000..30f08a8a --- /dev/null +++ b/src/main/java/de/dhbwstuttgart/bytecode/JavaTXSignatureAttribute.java @@ -0,0 +1,2 @@ +package de.dhbwstuttgart.bytecode;public class JavaTXSignatureAttribute { +} diff --git a/src/test/java/targetast/TestComplete.java b/src/test/java/targetast/TestComplete.java index 4cbe231a..9d7e9159 100644 --- a/src/test/java/targetast/TestComplete.java +++ b/src/test/java/targetast/TestComplete.java @@ -407,7 +407,7 @@ public class TestComplete { var instance = tph4.getDeclaredConstructor().newInstance(); var m = tph4.getDeclaredMethod("m", Object.class, Object.class); - // public N m(O var1, P var2) + // public N m(O var1, N var2) { var paraTypes = m.getGenericParameterTypes(); var typeParaTypes = m.getTypeParameters(); @@ -415,8 +415,9 @@ public class TestComplete { assertEquals(Object.class, N.getBounds()[0]); var O = Arrays.stream(typeParaTypes).filter(t -> t.equals(paraTypes[0])).findFirst().get(); - var P = Arrays.stream(typeParaTypes).filter(t -> t.equals(paraTypes[1])).findFirst().get(); - assertEquals(N, P.getBounds()[0]); + var N2 = Arrays.stream(typeParaTypes).filter(t -> t.equals(paraTypes[1])).findFirst().get(); + assertEquals(N, N2); + assertEquals(N.getBounds()[0], Object.class); assertEquals(O.getBounds()[0], Object.class); var m2 = tph4.getDeclaredMethod("m2", Object.class); @@ -465,18 +466,15 @@ public class TestComplete { var instance = tph5.getDeclaredConstructor().newInstance(); var m = tph5.getDeclaredMethod("m", Object.class, Object.class); - // public void m(N var1, O var2) + // public void m(O var1, P var2) var paraTypes = m.getGenericParameterTypes(); var typeParaTypes = m.getTypeParameters(); - var N = Arrays.stream(typeParaTypes).filter(t -> t.equals(paraTypes[0])).findFirst().get(); + var P = Arrays.stream(typeParaTypes).filter(t -> t.equals(paraTypes[0])).findFirst().get(); var O = Arrays.stream(typeParaTypes).filter(t -> t.equals(paraTypes[1])).findFirst().get(); - var PT = N.getBounds()[0]; - assertEquals(PT, O.getBounds()[0]); - - var P = Arrays.stream(typeParaTypes).filter(t -> t.equals(PT)).findFirst().get(); - assertEquals(Object.class, P.getBounds()[0]); + assertEquals(P.getBounds()[0], Object.class); + assertEquals(O.getBounds()[0], Object.class); var m2 = tph5.getDeclaredMethod("m2", Object.class); @@ -496,7 +494,7 @@ public class TestComplete { var classToTest = classFiles.get("Tph7"); var instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); - //public DZU m(DZL, DZM); + // public N m(O var1, N var2) Method m = classToTest.getDeclaredMethod("m", Object.class, Object.class); //System.out.println(m.toString()); @@ -510,27 +508,23 @@ public class TestComplete { //Typeparameters are extracted from the argumenttypes //Conditions for the extracted typeparameters are set - //paraTypes[0] = DLZ + //paraTypes[0] = O var boundFstArg = Arrays.stream(typeParaTypes) .filter(x -> x.equals(paraTypes[0])).findFirst().get().getBounds(); - //Bound of DLZ has to be Object + //Bound of O has to be Object assertEquals(Object.class, Arrays.stream(boundFstArg).findFirst().get()); - //paraTypes[0] = DZM - var boundSndArg = Arrays.stream(typeParaTypes) - .filter(x -> x.equals(paraTypes[1])).findFirst().get().getBounds(); + //paraTypes[1] = N + var N = Arrays.stream(typeParaTypes) + .filter(x -> x.equals(paraTypes[1])).findFirst().get(); + var boundSndArg = N.getBounds(); - //Bound of DZM has to be the return type of m - assertEquals(Arrays.stream(boundSndArg).findFirst().get(), m.getGenericReturnType()); + //Bound of H has to be Object + assertEquals(Object.class, Arrays.stream(boundSndArg).findFirst().get()); - //Bound of the bound of DZM - var boundBoundSndArg = Arrays.stream(typeParaTypes).filter(x -> x.equals(Arrays.stream(boundSndArg) - .findFirst().get())).findFirst().get().getBounds(); - - //boundBoundSndArg have to be a type variable (type of the local variable c) - assertEquals(true, Arrays.stream(boundBoundSndArg).findFirst().get() instanceof TypeVariable); - m.getGenericParameterTypes(); + //N has to be the return type of m + assertEquals(N, m.getGenericReturnType()); //public DZU m2(DZU); Method m2 = classToTest.getDeclaredMethod("m2", Object.class);