package packages; import com.google.common.collect.Lists; 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; import java.net.URL; 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(); f = new File(rootDirectory + "ToImport.class"); assertTrue(f.exists()); 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()); } @Test public void testSetPackageNameInBytecodeAndOutputFolder() throws IOException, ClassNotFoundException { JavaTXCompiler compiler = new JavaTXCompiler( Lists.newArrayList(new File(rootDirectory+"ImportTest.jav")), Lists.newArrayList(new File(rootDirectory+"output/"))); 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()); } @Test public void testSetPackageNameInBytecodeAndStandardOutputFolder() throws IOException, ClassNotFoundException { JavaTXCompiler compiler = new JavaTXCompiler( Lists.newArrayList(new File(rootDirectory+"ImportTest.jav")), Lists.newArrayList(new File(rootDirectory+"output/"))); compiler.typeInference(); File f = new File(rootDirectory + "ImportTest.class"); if(f.exists() && !f.isDirectory()) { f.delete(); } compiler.generateBytecode(); f = new File(rootDirectory + "ImportTest.class"); assertTrue(f.exists()); } @Test public void testImportTwoClasses() throws IOException, ClassNotFoundException { JavaTXCompiler compiler = new JavaTXCompiler( Lists.newArrayList(new File(rootDirectory+"ImportTest2.jav")), Lists.newArrayList(new File(rootDirectory+"output/"))); compiler.typeInference(); File f = new File(rootDirectory + "ImportTest2.class"); if(f.exists() && !f.isDirectory()) { f.delete(); } compiler.generateBytecode(); f = new File(rootDirectory + "ImportTest2.class"); assertTrue(f.exists()); } @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(); } compiler.generateBytecode(); f = new File(rootDirectory + "ImportTestDefault.class"); assertTrue(f.exists()); } }