Hinzufügen von Tests von OLFun und OLFun2.

This commit is contained in:
Etienne Zink 2022-03-30 13:38:50 +02:00
parent f03d3f5e64
commit 4c0fb34c00
5 changed files with 52 additions and 22 deletions

View File

@ -21,7 +21,7 @@ public interface FunNUtilities {
RefTypeOrTPHOrWildcardOrGeneric getReturnType(List<RefTypeOrTPHOrWildcardOrGeneric> list); RefTypeOrTPHOrWildcardOrGeneric getReturnType(List<RefTypeOrTPHOrWildcardOrGeneric> list);
@Deprecated @Deprecated
public static boolean writeClassFile(String className, byte[] bytecode, File directory) { static boolean writeClassFile(String className, byte[] bytecode, File directory) {
try (FileOutputStream output = new FileOutputStream(new File(directory , className + CONSTANTS.EXTENSIONCLASS))){ try (FileOutputStream output = new FileOutputStream(new File(directory , className + CONSTANTS.EXTENSIONCLASS))){
output.write(bytecode); output.write(bytecode);
output.flush(); output.flush();

View File

@ -4,7 +4,6 @@ import java.io.File;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.URL; import java.net.URL;
import java.net.URLClassLoader; import java.net.URLClassLoader;
import java.util.function.Function;
import general.TestCleanUp; import general.TestCleanUp;
import org.junit.*; import org.junit.*;
@ -24,8 +23,9 @@ public class OLFun2Test {
private static ClassLoader loader; private static ClassLoader loader;
private static Class<?> classToTest; private static Class<?> classToTest;
private static Class<?> classFun1IntInt; private static Class<?> classFun1IntInt;
private static Class<?> classFun1IntDouble;
private static Class<?> classFun1DoubleDouble; private static Class<?> classFun1DoubleDouble;
private static Class<?> classFun1StringString; private static Class<?> classFun1DoubleInt;
private static String generatedByteCodeDirectory = System.getProperty("user.dir") + "/src/test/resources/testBytecode/generatedBC/"; private static String generatedByteCodeDirectory = System.getProperty("user.dir") + "/src/test/resources/testBytecode/generatedBC/";
@ -40,30 +40,37 @@ public class OLFun2Test {
loader = new URLClassLoader(new URL[] {new URL("file://"+generatedByteCodeDirectory)}); loader = new URLClassLoader(new URL[] {new URL("file://"+generatedByteCodeDirectory)});
classToTest = loader.loadClass("OLFun2"); classToTest = loader.loadClass("OLFun2");
classFun1IntInt = loader.loadClass("Fun1$$Ljava$lang$Integer$_$Ljava$lang$Integer$_$"); classFun1IntInt = loader.loadClass("Fun1$$Ljava$lang$Integer$_$Ljava$lang$Integer$_$");
classFun1IntDouble = loader.loadClass("Fun1$$Ljava$lang$Integer$_$Ljava$lang$Double$_$");
classFun1DoubleDouble = loader.loadClass("Fun1$$Ljava$lang$Double$_$Ljava$lang$Double$_$"); classFun1DoubleDouble = loader.loadClass("Fun1$$Ljava$lang$Double$_$Ljava$lang$Double$_$");
classFun1StringString = loader.loadClass("Fun1$$Ljava$lang$String$_$Ljava$lang$String$_$"); classFun1DoubleInt = loader.loadClass("Fun1$$Ljava$lang$Double$_$Ljava$lang$Integer$_$");
} }
@Test @Test
public void mExistsWithInteger() throws Exception{ public void mExistsWithIntegerInteger() throws Exception{
Method m = classToTest.getDeclaredMethod("m", classFun1IntInt); Method m = classToTest.getDeclaredMethod("m", classFun1IntInt);
assertNotNull(m); assertNotNull(m);
} }
@Test @Test
public void mExistsWithDouble() throws Exception{ public void mExistsWithIntegerDouble() throws Exception{
Method m = classToTest.getDeclaredMethod("m", classFun1DoubleDouble); Method m = classToTest.getDeclaredMethod("m", classFun1IntDouble);
assertNotNull(m); assertNotNull(m);
} }
@Test @Test
public void mExistsWithString() throws Exception{ public void mExistsWithDoubleInteger() throws Exception{
Method m = classToTest.getDeclaredMethod("m", classFun1StringString); Method m = classToTest.getDeclaredMethod("m", classFun1DoubleInt);
assertNotNull(m);
}
@Test
public void mExistsWithDoubleDouble() throws Exception{
Method m = classToTest.getDeclaredMethod("m", classFun1DoubleDouble);
assertNotNull(m); assertNotNull(m);
} }
//@AfterClass //@AfterClass
public static void cleanUp(){ public static void cleanUp() {
TestCleanUp.cleanUpDirectory(new File(generatedByteCodeDirectory), f -> f.getName().contains(".class")); TestCleanUp.cleanUpDirectory(new File(generatedByteCodeDirectory), f -> f.getName().contains(".class"));
} }
} }

View File

@ -23,8 +23,11 @@ public class OLFunTest {
private static ClassLoader loader; private static ClassLoader loader;
private static Class<?> classToTest; private static Class<?> classToTest;
private static Class<?> classFun1IntInt; private static Class<?> classFun1IntInt;
private static Class<?> classFun1IntDouble;
private static Class<?> classFun1DoubleDouble; private static Class<?> classFun1DoubleDouble;
private static Class<?> classFun1StringString; private static Class<?> classFun1DoubleInt;
private static Class<?> classFun1StringInt;
private static Class<?> classFun1StringDouble;
private static String generatedByteCodeDirectory = System.getProperty("user.dir") + "/src/test/resources/testBytecode/generatedBC/"; private static String generatedByteCodeDirectory = System.getProperty("user.dir") + "/src/test/resources/testBytecode/generatedBC/";
@ -39,25 +42,46 @@ public class OLFunTest {
loader = new URLClassLoader(new URL[] {new URL("file://"+generatedByteCodeDirectory)}); loader = new URLClassLoader(new URL[] {new URL("file://"+generatedByteCodeDirectory)});
classToTest = loader.loadClass("OLFun"); classToTest = loader.loadClass("OLFun");
classFun1IntInt = loader.loadClass("Fun1$$Ljava$lang$Integer$_$Ljava$lang$Integer$_$"); classFun1IntInt = loader.loadClass("Fun1$$Ljava$lang$Integer$_$Ljava$lang$Integer$_$");
classFun1IntDouble = loader.loadClass("Fun1$$Ljava$lang$Integer$_$Ljava$lang$Double$_$");
classFun1DoubleDouble = loader.loadClass("Fun1$$Ljava$lang$Double$_$Ljava$lang$Double$_$"); classFun1DoubleDouble = loader.loadClass("Fun1$$Ljava$lang$Double$_$Ljava$lang$Double$_$");
classFun1StringString = loader.loadClass("Fun1$$Ljava$lang$String$_$Ljava$lang$String$_$"); classFun1DoubleInt = loader.loadClass("Fun1$$Ljava$lang$Double$_$Ljava$lang$Integer$_$");
classFun1StringInt = loader.loadClass("Fun1$$Ljava$lang$String$_$Ljava$lang$Integer$_$");
classFun1StringDouble = loader.loadClass("Fun1$$Ljava$lang$String$_$Ljava$lang$Double$_$");
} }
@Test @Test
public void mExistsWithInteger() throws Exception{ public void mExistsWithIntegerInteger() throws Exception{
Method m = classToTest.getDeclaredMethod("m", classFun1IntInt ,Integer.class); Method m = classToTest.getDeclaredMethod("m", classFun1IntInt, Integer.class);
assertNotNull(m); assertNotNull(m);
} }
@Test @Test
public void mExistsWithDouble() throws Exception{ public void mExistsWithIntegerDouble() throws Exception{
Method m = classToTest.getDeclaredMethod("m", classFun1DoubleDouble ,Double.class); Method m = classToTest.getDeclaredMethod("m", classFun1IntDouble, Integer.class);
assertNotNull(m); assertNotNull(m);
} }
@Test @Test
public void mExistsWithString() throws Exception{ public void mExistsWithDoubleInteger() throws Exception{
Method m = classToTest.getDeclaredMethod("m", classFun1StringString ,String.class); Method m = classToTest.getDeclaredMethod("m", classFun1DoubleInt, Double.class);
assertNotNull(m);
}
@Test
public void mExistsWithDoubleDouble() throws Exception{
Method m = classToTest.getDeclaredMethod("m", classFun1DoubleDouble, Double.class);
assertNotNull(m);
}
@Test
public void mExistsWithStringInteger() throws Exception{
Method m = classToTest.getDeclaredMethod("m", classFun1StringInt, String.class);
assertNotNull(m);
}
@Test
public void mExistsWithStringDouble() throws Exception{
Method m = classToTest.getDeclaredMethod("m", classFun1StringDouble, String.class);
assertNotNull(m); assertNotNull(m);
} }

View File

@ -6,8 +6,7 @@ import java.lang.Boolean;
public class OLFun { public class OLFun {
//f = x -> {return x + x;};
m(f, x) { m(f, x) {
x = f.apply(x+x); var y = f.apply(x + x) + 1;
} }
} }

View File

@ -6,8 +6,8 @@ import java.lang.Boolean;
public class OLFun2 { public class OLFun2 {
x;
m(f){ m(f){
x = f.apply(x + x) var x = 1;
var y = f.apply(x + x) + 1;
} }
} }