Overloading Test überarbeitet

This commit is contained in:
Enrico Schrödter 2015-10-23 19:04:13 +02:00
parent 040a1f4088
commit 52be0a1af3

View File

@ -2,7 +2,10 @@ package bytecode.types;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import java.io.File;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Vector; import java.util.Vector;
import org.junit.Test; import org.junit.Test;
@ -24,17 +27,22 @@ public class OverloadingTest extends BytecodeTest{
Class cls = getClassToTest(); Class cls = getClassToTest();
Object obj = cls.newInstance(); Object obj = cls.newInstance();
Vector<String> stringVector = new Vector<String>(); File file = new File(rootDirectory);
URL url = file.toURL();
URL[] urls = new URL[]{url};
ClassLoader classLoader = new URLClassLoader(urls);
Class stringVector = classLoader.loadClass("java%util%Vector%%java%lang%String%");
Class[] params = new Class[1]; Class[] params = new Class[1];
params[0] = stringVector.getClass(); params[0] = stringVector;
Method method = cls.getDeclaredMethod("method", params); Method method = cls.getDeclaredMethod("method", params);
method.invoke(obj, stringVector); method.invoke(obj, stringVector.newInstance());
assertTrue(true); assertTrue(true);
}catch(Exception e){ }catch(Exception e){
e.printStackTrace(); throw new RuntimeException(e);
fail();
} }
} }
@ -44,17 +52,22 @@ public class OverloadingTest extends BytecodeTest{
Class cls = getClassToTest(); Class cls = getClassToTest();
Object obj = cls.newInstance(); Object obj = cls.newInstance();
Vector<Integer> stringVector = new Vector<Integer>(); File file = new File(rootDirectory);
URL url = file.toURL();
URL[] urls = new URL[]{url};
ClassLoader classLoader = new URLClassLoader(urls);
Class integerVector = classLoader.loadClass("java%util%Vector%%java%lang%Integer%");
Class[] params = new Class[1]; Class[] params = new Class[1];
params[0] = stringVector.getClass(); params[0] = integerVector;
Method method = cls.getDeclaredMethod("method", params); Method method = cls.getDeclaredMethod("method", params);
method.invoke(obj, stringVector); method.invoke(obj, integerVector.newInstance());
assertTrue(true); assertTrue(true);
}catch(Exception e){ }catch(Exception e){
e.printStackTrace(); throw new RuntimeException(e);
fail();
} }
} }