1 package jester.tests; 2 3 import java.io.BufferedOutputStream ; 4 import java.io.File ; 5 import java.io.FileOutputStream ; 6 import java.io.IOException ; 7 import java.io.PrintWriter ; 8 9 import jester.Configuration; 10 import jester.RealCompiler; 11 import junit.framework.TestCase; 12 13 public class CompilerTest extends TestCase { 14 15 private static final String FILE_NAME = "TestSourceFile"; 16 private static final String SOURCE_FILE_NAME = FILE_NAME + ".java"; 17 private static final String CLASS_FILE_NAME = FILE_NAME + ".class"; 18 private jester.Compiler compiler; 19 20 public CompilerTest(String name) { 21 super(name); 22 } 23 24 public static void main(String args[]) { 25 junit.awtui.TestRunner.main(new String [] { CompilerTest.class.getName() }); 26 } 27 28 protected void setUp() throws Exception { 29 super.setUp(); 30 Configuration conf = new MockConfiguration(); 31 compiler = new RealCompiler(conf); 32 createSourceFile(); 33 } 34 35 protected void tearDown() throws Exception { 36 super.tearDown(); 37 deleteFiles(); 38 } 39 40 public void testCompile() throws Exception { 41 compiler.compile(SOURCE_FILE_NAME); 42 assertTrue(hasClassFile()); 43 } 44 45 private void createSourceFile() throws IOException { 46 PrintWriter writer = new PrintWriter (new BufferedOutputStream (new FileOutputStream (SOURCE_FILE_NAME))); 47 writer.println("public class " + FILE_NAME + " {"); 48 writer.println("}"); 49 writer.close(); 50 } 51 52 private void deleteFiles() { 53 File f = new File (SOURCE_FILE_NAME); 54 f.delete(); 55 f = new File (CLASS_FILE_NAME); 56 f.delete(); 57 } 58 59 private boolean hasClassFile() { 60 File f = new File (CLASS_FILE_NAME); 61 return f.exists(); 62 } 63 64 } 65 | Popular Tags |