package targetast;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.lang.reflect.Method;

import static org.junit.jupiter.api.Assertions.assertEquals;


public class TphTest {

	private static Class<?> classToTest;
	private static Object instanceOfClass;

	@BeforeAll
	public static void setUpBeforeClass() throws Exception {
		var classFiles = TestCodegen.generateClassFiles(TestCodegen.createClassLoader(), "Tph.jav");
		classToTest = classFiles.get("Tph");
		instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
	}

	@Test
	public void test1() throws Exception {
		Method m = classToTest.getDeclaredMethod("m", Object.class, Object.class);
		Object result = m.invoke(instanceOfClass, 1,2);

		assertEquals(1,result);
	}
	
	@Test
	public void test2() throws Exception {
		Method m = classToTest.getDeclaredMethod("m", Object.class, Object.class);
		Object result = m.invoke(instanceOfClass, 1, "sss");
		
		assertEquals(1,result);
	}
	
	@Test
	public void test3() throws Exception {
		Method m = classToTest.getDeclaredMethod("m2", Object.class);
		Object result = m.invoke(instanceOfClass, 2);
		
		assertEquals(2,result);
	}
	
	@Test
	public void test4() throws Exception {
		Method m = classToTest.getDeclaredMethod("m2", Object.class);
		Object result = m.invoke(instanceOfClass,"xxx");
		
		assertEquals("xxx",result);
	}

}
