modified: ../../java/targetast/TestComplete.java

Test Tph7.jav in integriert.
This commit is contained in:
pl@gohorb.ba-horb.de 2022-08-08 15:24:46 +02:00
parent d54cd5e20a
commit c933160dcb

View File

@ -4,6 +4,9 @@ import de.dhbwstuttgart.target.ByteArrayClassLoader;
import org.junit.Ignore;
import org.junit.Test;
import java.lang.reflect.Method;
import java.lang.reflect.TypeVariable;
import java.util.Arrays;
import java.util.Vector;
import static org.junit.Assert.*;
@ -372,13 +375,73 @@ public class TestComplete {
var m = tph5.getDeclaredMethod("m", Object.class, Object.class);
}
@Test
public void tph7Test() throws Exception {
var classFiles = generateClassFiles("Tph7.jav", new ByteArrayClassLoader());
var tph5 = classFiles.get("Tph7");
var instance = tph5.getDeclaredConstructor().newInstance();
public void Tph7Test() throws Exception {
var classFiles = TestCodegen.generateClassFiles("Tph7.jav", new ByteArrayClassLoader());
var classToTest = classFiles.get("Tph7");
var instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
//public <DZN, DZL, DZU extends DZN, DZM extends DZU> DZU m(DZL, DZM);
Method m = classToTest.getDeclaredMethod("m", Object.class, Object.class);
//System.out.println(m.toString());
//Argumenttypes of the method m
var paraTypes = m.getGenericParameterTypes();
//Typeparameters of the method m
var typeParaTypes = m.getTypeParameters();
//Typeparameters are extracted from the argumenttypes
//Conditions for the extracted typeparameters are set
//paraTypes[0] = DLZ
var boundFstArg = Arrays.stream(typeParaTypes)
.filter(x -> x.equals(paraTypes[0])).findFirst().get().getBounds();
//Bound of DLZ 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();
//Bound of DZM has to be the return type of m
assertEquals(Arrays.stream(boundSndArg).findFirst().get(), m.getGenericReturnType());
//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();
//public <DZU> DZU m2(DZU);
Method m2 = classToTest.getDeclaredMethod("m2", Object.class);
//Argumenttypes of the method m2
var paraTypesm2 = m2.getGenericParameterTypes();
//Typeparameters of the method m2
var typeParaTypesm2 = m2.getTypeParameters();
//Typeparameters are extracted from the argumenttypes
//Conditions for the extracted typeparameters are set
//paraTypes[0] = DZU
var fstArgm2 = Arrays.stream(typeParaTypesm2)
.filter(x -> x.equals(paraTypesm2[0])).findFirst().get();
//Bound of DZU has to be Object
assertEquals(Object.class, Arrays.stream(fstArgm2.getBounds()).findFirst().get());
//DZU has to be the return type of m
assertEquals(fstArgm2, m2.getGenericReturnType());
}
@Test
public void typedIdTest() throws Exception {
var classFiles = generateClassFiles("TypedID.jav", new ByteArrayClassLoader());