package bytecode; import static org.junit.Assert.*; import java.io.File; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.URL; import java.net.URLClassLoader; import org.junit.BeforeClass; import org.junit.Test; import de.dhbwstuttgart.core.JavaTXCompiler; public class GreaterThanTest { private static String path; private static File fileToTest; private static JavaTXCompiler compiler; private static ClassLoader loader; private static Class classToTest; private static String pathToClassFile; private static Object instanceOfClass; @BeforeClass public static void setUpBeforeClass() throws Exception { path = System.getProperty("user.dir")+"/test/bytecode/javFiles/GreaterThan.jav"; fileToTest = new File(path); compiler = new JavaTXCompiler(fileToTest); compiler.generateBytecode(); pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/"; loader = new URLClassLoader(new URL[] {new URL("File://"+pathToClassFile)}); classToTest = loader.loadClass("GreaterThan"); instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); } @Test public void testName() { assertEquals("GreaterThan", classToTest.getName()); } public void testIntegers() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { Method gT = classToTest.getDeclaredMethod("gT", Integer.class, Integer.class); Boolean result = (Boolean) gT.invoke(instanceOfClass, 7, 5); assertTrue(result); } @Test public void testIntegers2() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { Method gT = classToTest.getDeclaredMethod("gT", Integer.class, Integer.class); Boolean result = (Boolean) gT.invoke(instanceOfClass, 5, 7); assertFalse(result); } @Test public void testEqIntegers() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { Method gT = classToTest.getDeclaredMethod("gT", Integer.class, Integer.class); Boolean result = (Boolean) gT.invoke(instanceOfClass, 5, 5); assertFalse(result); } @Test public void testLongs() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { Method gT = classToTest.getDeclaredMethod("gT", Long.class, Long.class); Boolean result = (Boolean) gT.invoke(instanceOfClass, 10L,7L); assertTrue(result); }@Test public void testFloats() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { Method gT = classToTest.getDeclaredMethod("gT", Float.class, Float.class); Boolean result = (Boolean) gT.invoke(instanceOfClass, 5F,7F); assertFalse(result); } @Test public void testDoubles() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { Method gT = classToTest.getDeclaredMethod("gT", Double.class, Double.class); Boolean result = (Boolean) gT.invoke(instanceOfClass, 5.0,7.0); assertFalse(result); } @Test public void testLongInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { Method gT = classToTest.getDeclaredMethod("gT", Long.class, Integer.class); Boolean result = (Boolean) gT.invoke(instanceOfClass, 15L,7); assertTrue(result); } @Test public void testFloatInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { Method gT = classToTest.getDeclaredMethod("gT", Float.class, Integer.class); Boolean result = (Boolean) gT.invoke(instanceOfClass, 5F,7); assertFalse(result); } @Test public void testDoubleInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { Method gT = classToTest.getDeclaredMethod("gT", Double.class, Integer.class); Boolean result = (Boolean) gT.invoke(instanceOfClass, 25.0,17); assertTrue(result); } @Test public void testFloatLong() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { Method gT = classToTest.getDeclaredMethod("gT", Float.class, Long.class); Boolean result = (Boolean) gT.invoke(instanceOfClass, 75F,70L); assertTrue(result); } @Test public void testDoubleLong() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { Method gT = classToTest.getDeclaredMethod("gT", Double.class, Long.class); Boolean result = (Boolean) gT.invoke(instanceOfClass, 5.0,7L); assertFalse(result); } @Test public void testEqDoubleFloat() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { Method gT = classToTest.getDeclaredMethod("gT", Double.class, Float.class); Boolean result = (Boolean) gT.invoke(instanceOfClass, 7.0,7F); assertFalse(result); } @Test public void testDoubleFloat() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { Method gT = classToTest.getDeclaredMethod("gT", Double.class, Float.class); Boolean result = (Boolean) gT.invoke(instanceOfClass, 15.0,7F); assertTrue(result); } @Test public void testDoubleFloat3() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { Method gT = classToTest.getDeclaredMethod("gT", Double.class, Float.class); Boolean result = (Boolean) gT.invoke(instanceOfClass, 9.0,17F); assertFalse(result); } }