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 PreIncTest {
	private static Class<?> classToTest;
	private static Object instanceOfClass;
	
	@BeforeAll
	public static void setUpBeforeClass() throws Exception {
		var classFiles = TestCodegen.generateClassFiles(TestCodegen.createClassLoader(), "PreInc.jav");
		classToTest = classFiles.get("PreInc");
		instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
	}

	@Test
	public void testM() throws Exception {
		Method m = classToTest.getDeclaredMethod("m");
		Integer res = (Integer) m.invoke(instanceOfClass);
		assertEquals(Integer.valueOf(1), res);
	}
	
	@Test
	public void testM2() throws Exception {
		Method m = classToTest.getDeclaredMethod("m2");
		Integer res = (Integer) m.invoke(instanceOfClass);
		assertEquals(Integer.valueOf(1), res);
	}
	
	@Test
	public void testD() throws Exception {
		Method m = classToTest.getDeclaredMethod("d");
		Integer res = (Integer) m.invoke(instanceOfClass);
		assertEquals(Integer.valueOf(-1), res);
	}
	
	@Test
	public void testD2() throws Exception {
		Method m = classToTest.getDeclaredMethod("d2");
		Integer res = (Integer) m.invoke(instanceOfClass);
		assertEquals(Integer.valueOf(-1), res);
	}

}
