JavaCompilerCore/test/bytecode/VariableMultimethodsTest.java
JanUlrich 7b9a00a7e6 Revert "Syntaxbaum bereinigen. Allen Code löschen. Nur Struktur bleibt erhalten"
This reverts commit 3ab96a3ed74f41435b6b41502377f5a0084e6d75.
2016-12-16 01:05:54 +01:00

99 lines
2.1 KiB
Java

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);
}
}