diff --git a/src/test/java/packages/ImportTest.java b/src/test/java/packages/ImportTest.java new file mode 100644 index 00000000..a6fbc075 --- /dev/null +++ b/src/test/java/packages/ImportTest.java @@ -0,0 +1,44 @@ +package packages; + +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; + +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()); + compiler = new JavaTXCompiler(new File(rootDirectory+"ToImport.jav")); + compiler.typeInference(); + compiler.generateBytecode(null); + f = new File(rootDirectory + "output/de/test/ToImport.class"); + assertTrue(f.exists()); + } + + @Test + public void testSetPackageNameInBytecodeAndOutputFolder() throws IOException, ClassNotFoundException { + JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"ImportTest.jav")); + 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()); + } +} diff --git a/src/test/resources/javFiles/packageTest/de/test/ImportTest.jav b/src/test/resources/javFiles/packageTest/de/test/ImportTest.jav new file mode 100644 index 00000000..58b6fc0b --- /dev/null +++ b/src/test/resources/javFiles/packageTest/de/test/ImportTest.jav @@ -0,0 +1,9 @@ +package de.test; + +import de.test.ToImport; + +class ImportTest{ + void methode(){ + new ToImport(); + } +} \ No newline at end of file diff --git a/src/test/resources/javFiles/packageTest/de/test/ToImport.jav b/src/test/resources/javFiles/packageTest/de/test/ToImport.jav new file mode 100644 index 00000000..3afdba54 --- /dev/null +++ b/src/test/resources/javFiles/packageTest/de/test/ToImport.jav @@ -0,0 +1,4 @@ +package de.test; + +class ToImport{ +} \ No newline at end of file