JavaTXCompilerInJavaTXNoMaven/tests/targetast/PutTest.java
2024-05-02 23:04:07 +02:00

60 lines
1.8 KiB
Java

package targetast;
import de.dhbwstuttgart.environment.ByteArrayClassLoader;
import org.junit.BeforeClass;
import org.junit.Test;
import java.lang.reflect.Method;
import java.util.Stack;
import java.util.Vector;
import static org.junit.Assert.assertEquals;
public class PutTest {
private static Class<?> classToTest;
private static Object instanceOfClass;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
var classFiles = TestCodegen.generateClassFiles(new ByteArrayClassLoader(), "Put.jav");
classToTest = classFiles.get("Put");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
}
@Test
public void testPutElementVector() throws Exception {
Method m = classToTest.getDeclaredMethod("putElement", Object.class, Vector.class);
Vector<Integer> v_invoke = new Vector<>();
m.invoke(instanceOfClass, 5, v_invoke);
Vector<Integer> v = new Vector<>();
v.add(5);
assertEquals(v, v_invoke);
}
@Test
public void testPutElementStack() throws Exception {
Method m = classToTest.getDeclaredMethod("putElement", Object.class, Stack.class);
Stack<Integer> s_invoke = new Stack<>();
m.invoke(instanceOfClass, 5, s_invoke);
assertEquals(new Integer(5), s_invoke.pop());
}
@Test
public void testMainVector() throws Exception {
Method m = classToTest.getDeclaredMethod("main", Object.class, Vector.class);
Vector<Integer> v_invoke = new Vector<>();
m.invoke(instanceOfClass, 6, v_invoke);
Vector<Integer> v = new Vector<>();
v.add(6);
assertEquals(v, v_invoke);
}
@Test
public void testMainStack() throws Exception {
Method m = classToTest.getDeclaredMethod("main", Object.class, Stack.class);
Stack<Integer> s_invoke = new Stack<>();
m.invoke(instanceOfClass, 6, s_invoke);
assertEquals(new Integer(6), s_invoke.pop());
}
}