From 5821839cbc49cdda97646d9effe6564ee3c38bbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Schr=C3=B6dter?= Date: Fri, 3 Jun 2016 10:57:48 +0200 Subject: [PATCH] =?UTF-8?q?Test=20f=C3=BCr=20Methodenparameter=20erstellt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/bytecode/VariableMultimethods.jav | 14 +++ test/bytecode/VariableMultimethodsTest.java | 98 +++++++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 test/bytecode/VariableMultimethods.jav create mode 100644 test/bytecode/VariableMultimethodsTest.java diff --git a/test/bytecode/VariableMultimethods.jav b/test/bytecode/VariableMultimethods.jav new file mode 100644 index 00000000..ad5520f4 --- /dev/null +++ b/test/bytecode/VariableMultimethods.jav @@ -0,0 +1,14 @@ +class VariableMultimethods{ + public Integer method(Integer z, Integer x, Integer y){ + return x+y+z; + } + + public Integer method(Integer x, Integer y){ + return x+y; + } + + public Integer method(Integer y){ + return y; + } + +} \ No newline at end of file diff --git a/test/bytecode/VariableMultimethodsTest.java b/test/bytecode/VariableMultimethodsTest.java new file mode 100644 index 00000000..2990e25b --- /dev/null +++ b/test/bytecode/VariableMultimethodsTest.java @@ -0,0 +1,98 @@ +package bytecode; + +import static org.junit.Assert.*; + +import java.io.File; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Vector; + +import org.junit.Test; + +import org.junit.Ignore; + +import bytecode.SourceFileBytecodeTest; + + +public class VariableMultimethodsTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "VariableMultimethods"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } + + @Test + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } + + @Test + public void testOneArgument() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + + Integer y = 1; + + Class[] params = new Class[]{ + y.getClass() + }; + + Method method = cls.getDeclaredMethod("method", params); + Integer returnValue = (Integer) method.invoke(obj, y); + assertEquals(new Integer(1), returnValue); + } + + @Test + public void testTwoArgument() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + + Integer x = 1; + Integer y = 2; + + Class[] params = new Class[]{ + x.getClass(), + y.getClass() + }; + + Method method = cls.getDeclaredMethod("method", params); + Integer returnValue = (Integer) method.invoke(obj, x, y); + assertEquals(new Integer(3), returnValue); + } + + @Test + public void testThreeArgument() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + + Integer z = 1; + Integer x = 2; + Integer y = 4; + + Class[] params = new Class[]{ + z.getClass(), + x.getClass(), + y.getClass() + }; + + Method method = cls.getDeclaredMethod("method", params); + Integer returnValue = (Integer) method.invoke(obj, z, x, y); + assertEquals(new Integer(7), returnValue); + } +}