new file: ../../../java/packages/OLOneFileTest.java
new file: OLOneFile.jav
This commit is contained in:
parent
a9d6e08a20
commit
bf80361c1f
133
src/test/java/packages/OLOneFileTest.java
Normal file
133
src/test/java/packages/OLOneFileTest.java
Normal file
@ -0,0 +1,133 @@
|
||||
package packages;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
public class OLOneFileTest {
|
||||
private static String path;
|
||||
private static File fileToTest;
|
||||
private static JavaTXCompiler compiler;
|
||||
private static ClassLoader loader;
|
||||
private static Class<?> classToTest;
|
||||
private static Class<?> classToTest1;
|
||||
private static Class<?> classToTest2;
|
||||
private static String pathToClassFile;
|
||||
private static Object instanceOfClass;
|
||||
private static Object instanceOfClass1;
|
||||
private static Object instanceOfClass2;
|
||||
|
||||
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/javFiles/packageTest";
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
path = rootDirectory +"/OLOneFile.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(
|
||||
Lists.newArrayList(fileToTest),
|
||||
Lists.newArrayList(new File(rootDirectory+"/de/test/output/")));
|
||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/javFiles/packageTest/";
|
||||
List<ResultSet> typeinferenceResult = compiler.typeInference();
|
||||
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTest = loader.loadClass("OLOneFile");
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
classToTest1 = loader.loadClass("OLextendsOneFile");
|
||||
instanceOfClass1 = classToTest1.getDeclaredConstructor().newInstance();
|
||||
classToTest2 = loader.loadClass("OLMainOneFile");
|
||||
instanceOfClass2 = classToTest2.getDeclaredConstructor().newInstance();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOLClassName() {
|
||||
assertEquals("OLOneFile", classToTest.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testmInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||
Method m = classToTest.getDeclaredMethod("m2", Integer.class);
|
||||
Integer result = (Integer) m.invoke(instanceOfClass, 5);
|
||||
assertEquals(new Integer(10), result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testmDouble() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||
Method m = classToTest.getDeclaredMethod("m2", Double.class);
|
||||
Double result = (Double) m.invoke(instanceOfClass, 5.0);
|
||||
assertEquals(new Double(10.0), result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testmString() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||
Method m = classToTest.getDeclaredMethod("m2", String.class);
|
||||
String result = (String) m.invoke(instanceOfClass, "xxx");
|
||||
assertEquals("xxxxxx", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOLextendsClassName() {
|
||||
assertEquals("OLextendsOneFile", classToTest1.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testextendsInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||
Method main = classToTest1.getMethod("m2", Integer.class);
|
||||
Integer result = (Integer) main.invoke(instanceOfClass1, 5);
|
||||
assertEquals(new Integer(10), result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testextendsDouble() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||
Method main = classToTest1.getMethod("m2", Double.class);
|
||||
Double result = (Double) main.invoke(instanceOfClass1, 5.0);
|
||||
assertEquals(new Double(10.0), result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testextendsString() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||
Method main = classToTest1.getMethod("m2", String.class);
|
||||
String result = (String) main.invoke(instanceOfClass1, "xxx");
|
||||
assertEquals("xxxxxx", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOLMainClassName() {
|
||||
assertEquals("OLMainOneFile", classToTest2.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testmainInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||
Method main = classToTest2.getDeclaredMethod("main", Integer.class);
|
||||
Integer result = (Integer) main.invoke(instanceOfClass2, 5);
|
||||
assertEquals(new Integer(10), result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testmainDouble() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||
Method main = classToTest2.getDeclaredMethod("main", Double.class);
|
||||
Double result = (Double) main.invoke(instanceOfClass2, 5.0);
|
||||
assertEquals(new Double(10.0), result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testmainString() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||
Method main = classToTest2.getDeclaredMethod("main", String.class);
|
||||
String result = (String) main.invoke(instanceOfClass2, "xxx");
|
||||
assertEquals("xxxxxx", result);
|
||||
}
|
||||
}
|
22
src/test/resources/javFiles/packageTest/OLOneFile.jav
Normal file
22
src/test/resources/javFiles/packageTest/OLOneFile.jav
Normal file
@ -0,0 +1,22 @@
|
||||
import java.lang.String;
|
||||
import java.lang.Integer;
|
||||
import java.lang.Double;
|
||||
import java.lang.Boolean;
|
||||
|
||||
|
||||
public class OLOneFile {
|
||||
|
||||
m2(x) { return x + x; }
|
||||
|
||||
}
|
||||
|
||||
public class OLextendsOneFile extends OLOneFile { }
|
||||
|
||||
public class OLMainOneFile {
|
||||
|
||||
main(x) {
|
||||
var ol;
|
||||
ol = new OLextendsOneFile();
|
||||
return ol.m2(x);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user