2019-12-15 13:57:03 +00:00
|
|
|
package packages;
|
|
|
|
|
2019-12-15 23:54:00 +00:00
|
|
|
import com.google.common.collect.Lists;
|
2019-12-15 13:57:03 +00:00
|
|
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
|
|
|
import junit.framework.TestCase;
|
|
|
|
import org.junit.Before;
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
2019-12-15 23:54:00 +00:00
|
|
|
import java.net.URL;
|
2019-12-15 13:57:03 +00:00
|
|
|
|
|
|
|
public class ImportTest extends TestCase {
|
|
|
|
|
|
|
|
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/javFiles/packageTest/de/test/";
|
|
|
|
|
|
|
|
|
|
|
|
public ImportTest() throws ClassNotFoundException, IOException {
|
|
|
|
/*
|
|
|
|
Generate ToImport class in rootDirectory and in output-Directory
|
|
|
|
*/
|
|
|
|
JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"ToImport.jav"));
|
|
|
|
compiler.typeInference();
|
|
|
|
compiler.generateBytecode(rootDirectory + "output/");
|
|
|
|
File f = new File(rootDirectory + "output/de/test/ToImport.class");
|
|
|
|
assertTrue(f.exists());
|
2019-12-22 21:52:55 +00:00
|
|
|
|
2020-01-02 23:18:09 +00:00
|
|
|
compiler = new JavaTXCompiler(new File(rootDirectory+"ToImport.jav"));
|
|
|
|
compiler.typeInference();
|
2020-01-17 15:06:51 +00:00
|
|
|
compiler.generateBytecode();
|
2020-01-02 23:18:09 +00:00
|
|
|
f = new File(rootDirectory + "ToImport.class");
|
|
|
|
assertTrue(f.exists());
|
|
|
|
|
2019-12-22 21:52:55 +00:00
|
|
|
compiler = new JavaTXCompiler(new File(rootDirectory+"subpackage1/ToImport2.jav"));
|
|
|
|
compiler.typeInference();
|
|
|
|
compiler.generateBytecode(rootDirectory + "output/");
|
|
|
|
f = new File(rootDirectory + "output/de/test/subpackage1/ToImport2.class");
|
|
|
|
assertTrue(f.exists());
|
|
|
|
|
|
|
|
compiler = new JavaTXCompiler(new File(rootDirectory+"subpackage2/ToImport3.jav"));
|
|
|
|
compiler.typeInference();
|
|
|
|
compiler.generateBytecode(rootDirectory + "output/");
|
|
|
|
f = new File(rootDirectory + "output/de/test/subpackage2/ToImport3.class");
|
|
|
|
assertTrue(f.exists());
|
2019-12-15 13:57:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testSetPackageNameInBytecodeAndOutputFolder() throws IOException, ClassNotFoundException {
|
2019-12-15 23:54:00 +00:00
|
|
|
JavaTXCompiler compiler = new JavaTXCompiler(
|
|
|
|
Lists.newArrayList(new File(rootDirectory+"ImportTest.jav")),
|
2020-01-12 21:49:51 +00:00
|
|
|
Lists.newArrayList(new File(rootDirectory+"output/")));
|
2019-12-15 13:57:03 +00:00
|
|
|
compiler.typeInference();
|
|
|
|
File f = new File(rootDirectory + "output/de/test/ImportTest.class");
|
|
|
|
if(f.exists() && !f.isDirectory()) {
|
|
|
|
f.delete();
|
|
|
|
}
|
|
|
|
compiler.generateBytecode(rootDirectory + "output/");
|
|
|
|
f = new File(rootDirectory + "output/de/test/ImportTest.class");
|
|
|
|
assertTrue(f.exists());
|
|
|
|
}
|
2019-12-22 16:59:40 +00:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testSetPackageNameInBytecodeAndStandardOutputFolder() throws IOException, ClassNotFoundException {
|
|
|
|
JavaTXCompiler compiler = new JavaTXCompiler(
|
|
|
|
Lists.newArrayList(new File(rootDirectory+"ImportTest.jav")),
|
2020-01-12 21:49:51 +00:00
|
|
|
Lists.newArrayList(new File(rootDirectory+"output/")));
|
2019-12-22 16:59:40 +00:00
|
|
|
compiler.typeInference();
|
|
|
|
File f = new File(rootDirectory + "ImportTest.class");
|
|
|
|
if(f.exists() && !f.isDirectory()) {
|
|
|
|
f.delete();
|
|
|
|
}
|
2020-01-17 15:06:51 +00:00
|
|
|
compiler.generateBytecode();
|
2019-12-22 16:59:40 +00:00
|
|
|
f = new File(rootDirectory + "ImportTest.class");
|
|
|
|
assertTrue(f.exists());
|
|
|
|
}
|
2019-12-22 21:52:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testImportTwoClasses() throws IOException, ClassNotFoundException {
|
|
|
|
JavaTXCompiler compiler = new JavaTXCompiler(
|
|
|
|
Lists.newArrayList(new File(rootDirectory+"ImportTest2.jav")),
|
2020-01-12 21:49:51 +00:00
|
|
|
Lists.newArrayList(new File(rootDirectory+"output/")));
|
2019-12-22 21:52:55 +00:00
|
|
|
compiler.typeInference();
|
|
|
|
File f = new File(rootDirectory + "ImportTest2.class");
|
|
|
|
if(f.exists() && !f.isDirectory()) {
|
|
|
|
f.delete();
|
|
|
|
}
|
2020-01-17 15:06:51 +00:00
|
|
|
compiler.generateBytecode();
|
2019-12-22 21:52:55 +00:00
|
|
|
f = new File(rootDirectory + "ImportTest2.class");
|
|
|
|
assertTrue(f.exists());
|
|
|
|
}
|
2020-01-02 23:18:09 +00:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testImportDefaultPackage() throws IOException, ClassNotFoundException {
|
|
|
|
JavaTXCompiler compiler = new JavaTXCompiler(
|
|
|
|
Lists.newArrayList(new File(rootDirectory+"ImportTestDefault.jav")));
|
|
|
|
compiler.typeInference();
|
|
|
|
File f = new File(rootDirectory + "ImportTestDefault.class");
|
|
|
|
if(f.exists() && !f.isDirectory()) {
|
|
|
|
f.delete();
|
|
|
|
}
|
2020-01-17 15:06:51 +00:00
|
|
|
compiler.generateBytecode();
|
2020-01-02 23:18:09 +00:00
|
|
|
f = new File(rootDirectory + "ImportTestDefault.class");
|
|
|
|
assertTrue(f.exists());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-15 13:57:03 +00:00
|
|
|
}
|