Enrico Schrödter
ce52fd8904
RefType getBytecodeSignature unterscheidet zwischen RefType und TypePlacholder Abstrakte ByteCodeTest Klasse um getClassLoader erweitert Alle BytecodeTypeTests angepasst
62 lines
1.4 KiB
Java
62 lines
1.4 KiB
Java
package bytecode;
|
|
|
|
import static org.junit.Assert.*;
|
|
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.net.MalformedURLException;
|
|
import java.net.URL;
|
|
import java.net.URLClassLoader;
|
|
|
|
import junit.framework.TestCase;
|
|
|
|
import org.junit.BeforeClass;
|
|
import org.junit.Test;
|
|
|
|
public abstract class BytecodeTest extends TestCase{
|
|
public String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/";
|
|
public String testFile;
|
|
public String outputDirectory;
|
|
|
|
protected String testName;
|
|
|
|
public BytecodeTest(){
|
|
init();
|
|
|
|
if(testName != null){
|
|
|
|
testFile = testName+".jav";
|
|
outputDirectory = "";
|
|
|
|
SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputDirectory);
|
|
}else{
|
|
throw new RuntimeException("rootDirectory, testFile or outputFile is null.");
|
|
}
|
|
}
|
|
|
|
protected abstract void init();
|
|
|
|
protected Class getClassToTest(){
|
|
Class classToTest = null;
|
|
try {
|
|
ClassLoader classLoader = getClassLoader();
|
|
|
|
classToTest = classLoader.loadClass(testName);
|
|
|
|
|
|
} catch (Exception e) {
|
|
throw new RuntimeException(e);
|
|
}
|
|
|
|
return classToTest;
|
|
}
|
|
|
|
protected ClassLoader getClassLoader() throws Exception{
|
|
File file = new File(System.getProperty("user.dir")+"/test/bytecode/types/");
|
|
URL url = file.toURL();
|
|
URL[] urls = new URL[]{url};
|
|
|
|
return new URLClassLoader(urls);
|
|
}
|
|
}
|