Test für Methodenparameter erstellt
This commit is contained in:
parent
b6df854cc6
commit
5821839cbc
14
test/bytecode/VariableMultimethods.jav
Normal file
14
test/bytecode/VariableMultimethods.jav
Normal file
@ -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;
|
||||
}
|
||||
|
||||
}
|
98
test/bytecode/VariableMultimethodsTest.java
Normal file
98
test/bytecode/VariableMultimethodsTest.java
Normal file
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user