diff --git a/src/main/java/de/dhbwstuttgart/bytecode/funN/FunNUtilities.java b/src/main/java/de/dhbwstuttgart/bytecode/funN/FunNUtilities.java index 7ae4da4d..039b4a14 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/funN/FunNUtilities.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/funN/FunNUtilities.java @@ -21,7 +21,7 @@ public interface FunNUtilities { RefTypeOrTPHOrWildcardOrGeneric getReturnType(List list); @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))){ output.write(bytecode); output.flush(); diff --git a/src/test/java/bytecode/OLFun2Test.java b/src/test/java/bytecode/OLFun2Test.java index 6ec8701b..72ccbc4a 100644 --- a/src/test/java/bytecode/OLFun2Test.java +++ b/src/test/java/bytecode/OLFun2Test.java @@ -4,7 +4,6 @@ import java.io.File; import java.lang.reflect.Method; import java.net.URL; import java.net.URLClassLoader; -import java.util.function.Function; import general.TestCleanUp; import org.junit.*; @@ -24,8 +23,9 @@ public class OLFun2Test { private static ClassLoader loader; private static Class classToTest; private static Class classFun1IntInt; + private static Class classFun1IntDouble; 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/"; @@ -40,30 +40,37 @@ public class OLFun2Test { loader = new URLClassLoader(new URL[] {new URL("file://"+generatedByteCodeDirectory)}); classToTest = loader.loadClass("OLFun2"); 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$_$"); - classFun1StringString = loader.loadClass("Fun1$$Ljava$lang$String$_$Ljava$lang$String$_$"); + classFun1DoubleInt = loader.loadClass("Fun1$$Ljava$lang$Double$_$Ljava$lang$Integer$_$"); } @Test - public void mExistsWithInteger() throws Exception{ + public void mExistsWithIntegerInteger() throws Exception{ Method m = classToTest.getDeclaredMethod("m", classFun1IntInt); assertNotNull(m); } @Test - public void mExistsWithDouble() throws Exception{ - Method m = classToTest.getDeclaredMethod("m", classFun1DoubleDouble); + public void mExistsWithIntegerDouble() throws Exception{ + Method m = classToTest.getDeclaredMethod("m", classFun1IntDouble); assertNotNull(m); } @Test - public void mExistsWithString() throws Exception{ - Method m = classToTest.getDeclaredMethod("m", classFun1StringString); + public void mExistsWithDoubleInteger() throws Exception{ + Method m = classToTest.getDeclaredMethod("m", classFun1DoubleInt); + assertNotNull(m); + } + + @Test + public void mExistsWithDoubleDouble() throws Exception{ + Method m = classToTest.getDeclaredMethod("m", classFun1DoubleDouble); assertNotNull(m); } //@AfterClass - public static void cleanUp(){ + public static void cleanUp() { TestCleanUp.cleanUpDirectory(new File(generatedByteCodeDirectory), f -> f.getName().contains(".class")); } } diff --git a/src/test/java/bytecode/OLFunTest.java b/src/test/java/bytecode/OLFunTest.java index d1910e07..9408e5a8 100644 --- a/src/test/java/bytecode/OLFunTest.java +++ b/src/test/java/bytecode/OLFunTest.java @@ -23,8 +23,11 @@ public class OLFunTest { private static ClassLoader loader; private static Class classToTest; private static Class classFun1IntInt; + private static Class classFun1IntDouble; 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/"; @@ -39,25 +42,46 @@ public class OLFunTest { loader = new URLClassLoader(new URL[] {new URL("file://"+generatedByteCodeDirectory)}); classToTest = loader.loadClass("OLFun"); 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$_$"); - 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 - public void mExistsWithInteger() throws Exception{ - Method m = classToTest.getDeclaredMethod("m", classFun1IntInt ,Integer.class); + public void mExistsWithIntegerInteger() throws Exception{ + Method m = classToTest.getDeclaredMethod("m", classFun1IntInt, Integer.class); assertNotNull(m); } @Test - public void mExistsWithDouble() throws Exception{ - Method m = classToTest.getDeclaredMethod("m", classFun1DoubleDouble ,Double.class); + public void mExistsWithIntegerDouble() throws Exception{ + Method m = classToTest.getDeclaredMethod("m", classFun1IntDouble, Integer.class); assertNotNull(m); } @Test - public void mExistsWithString() throws Exception{ - Method m = classToTest.getDeclaredMethod("m", classFun1StringString ,String.class); + public void mExistsWithDoubleInteger() throws Exception{ + 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); } diff --git a/src/test/resources/bytecode/javFiles/OLFun.jav b/src/test/resources/bytecode/javFiles/OLFun.jav index adf8c6a8..d7d796f1 100644 --- a/src/test/resources/bytecode/javFiles/OLFun.jav +++ b/src/test/resources/bytecode/javFiles/OLFun.jav @@ -6,8 +6,7 @@ import java.lang.Boolean; public class OLFun { - //f = x -> {return x + x;}; m(f, x) { - x = f.apply(x+x); + var y = f.apply(x + x) + 1; } } \ No newline at end of file diff --git a/src/test/resources/bytecode/javFiles/OLFun2.jav b/src/test/resources/bytecode/javFiles/OLFun2.jav index 406c0d98..affde26a 100644 --- a/src/test/resources/bytecode/javFiles/OLFun2.jav +++ b/src/test/resources/bytecode/javFiles/OLFun2.jav @@ -6,8 +6,8 @@ import java.lang.Boolean; public class OLFun2 { - x; m(f){ - x = f.apply(x + x) + var x = 1; + var y = f.apply(x + x) + 1; } } \ No newline at end of file