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

	@Test
	public void test() throws Exception {
		Method m = classToTest.getDeclaredMethod("m", Integer.class);
		Integer result = (Integer) m.invoke(instanceOfClass, 0);
		assertEquals(Integer.valueOf(2), result);
	}
	
	@Test
	public void testDouble() throws Exception {
		Method m = classToTest.getDeclaredMethod("m", Double.class);
		Double result = (Double) m.invoke(instanceOfClass, 0.0);
		assertEquals(Double.valueOf(2.0), result);
	}
	
	@Test
	public void testLong() throws Exception {
		Method m = classToTest.getDeclaredMethod("m", Long.class);
		Long result = (Long) m.invoke(instanceOfClass, 0l);
		assertEquals(Long.valueOf(2l), result);
	}

}
