JavaTXCompilerInJavaTX/javatx-src-backup/test/java/targetast/InheritTest.java

106 lines
4.6 KiB
Java

package targetast;
import de.dhbwstuttgart.environment.ByteArrayClassLoader;
import org.junit.BeforeClass;
import org.junit.Test;
import java.lang.reflect.Method;
import java.nio.file.Path;
import java.util.Vector;
import static org.junit.Assert.assertEquals;
public class InheritTest {
private static Class<?> classToTest, classToTestAA, classToTestBB, classToTestCC, classToTestDD;
private static Object instanceOfClass, instanceOfClassAA, instanceOfClassBB, instanceOfClassCC, instanceOfClassDD;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
var classLoader = new ByteArrayClassLoader();
classToTestAA = TestCodegen.generateClassFiles(classLoader, "AA.jav").get("AA");
classToTestBB = TestCodegen.generateClassFiles(classLoader, "BB.jav").get("BB");
classToTestCC = TestCodegen.generateClassFiles(classLoader, "CC.jav").get("CC");
classToTestDD = TestCodegen.generateClassFiles(classLoader, "DD.jav").get("DD");
classToTest = TestCodegen.generateClassFiles(classLoader, "Inherit.jav").get("Inherit");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
instanceOfClassAA = classToTestAA.getDeclaredConstructor().newInstance();
instanceOfClassBB = classToTestBB.getDeclaredConstructor().newInstance();
instanceOfClassCC = classToTestCC.getDeclaredConstructor().newInstance();
instanceOfClassDD = classToTestDD.getDeclaredConstructor().newInstance();
}
@Test
public void testmainAA() throws Exception {
Method m = classToTestAA.getDeclaredMethod("m", Integer.class);
assertEquals(m.invoke(instanceOfClassAA, 5), "AA");
Method main = classToTest.getDeclaredMethod("main", classToTestAA, Integer.class);
assertEquals(main.invoke(instanceOfClass, instanceOfClassAA, 5), "AA");
}
@Test
public void testmainBB() throws Exception {
Method m = classToTestAA.getDeclaredMethod("m", Integer.class);
assertEquals(m.invoke(instanceOfClassBB, 5), "AA");
Method main = classToTest.getDeclaredMethod("main", classToTestAA, Integer.class);
assertEquals(main.invoke(instanceOfClass, instanceOfClassBB, 5), "AA");
}
@Test
public void testmainCC() throws Exception {
Method m = classToTestCC.getDeclaredMethod("m", Integer.class);
assertEquals(m.invoke(instanceOfClassCC, 5), "CC");
Method main = classToTest.getDeclaredMethod("main", classToTestCC, Integer.class);
assertEquals(main.invoke(instanceOfClass, instanceOfClassCC, 5), "CC");
}
@Test
public void testmainDD() throws Exception {
Method m = classToTestCC.getDeclaredMethod("m", Integer.class);
assertEquals(m.invoke(instanceOfClassDD, 5), "CC");
Method main = classToTest.getDeclaredMethod("main", classToTestCC, Integer.class);
assertEquals(main.invoke(instanceOfClass, instanceOfClassDD, 5), "CC");
}
@Test
public void testmainVectorAA() throws Exception {
Method m = classToTestAA.getDeclaredMethod("m", Integer.class);
assertEquals(m.invoke(instanceOfClassAA, 5), "AA");
Vector v = new Vector<>();
v.add(instanceOfClassAA);
Method main = classToTest.getDeclaredMethod("main", Vector.class, Integer.class);
assertEquals(main.invoke(instanceOfClass, v, 5), "AA");
}
@Test
public void testmainVectorBB() throws Exception {
Method m = classToTestAA.getDeclaredMethod("m", Integer.class);
assertEquals(m.invoke(instanceOfClassBB, 5), "AA");
Vector v = new Vector<>();
v.add(instanceOfClassBB);
Method main = classToTest.getDeclaredMethod("main", Vector.class, Integer.class);
assertEquals(main.invoke(instanceOfClass, v, 5), "AA");
}
@Test
public void testmainVectorCC() throws Exception {
Method m = classToTestCC.getDeclaredMethod("m", Integer.class);
assertEquals(m.invoke(instanceOfClassCC, 5), "CC");
Vector v = new Vector<>();
v.add(instanceOfClassCC);
Method main = classToTest.getDeclaredMethod("main", Vector.class, Integer.class);
assertEquals(main.invoke(instanceOfClass, v, 5), "CC");
}
@Test
public void testmainVectorDD() throws Exception {
Method m = classToTestCC.getDeclaredMethod("m", Integer.class);
assertEquals(m.invoke(instanceOfClassDD, 5), "CC");
Vector v = new Vector<>();
v.add(instanceOfClassDD);
Method main = classToTest.getDeclaredMethod("main", Vector.class, Integer.class);
assertEquals(main.invoke(instanceOfClass, v, 5), "CC");
}
}