1 package org.objectweb.celtix.tools.utils; 2 import java.io.File ; 3 import java.io.IOException ; 4 import junit.framework.TestCase; 5 public class FileWriterUtilTest extends TestCase { 6 7 private void cleanDir(File dir) { 8 try { 9 for (File fl : dir.listFiles()) { 10 if (fl.isDirectory()) { 11 cleanDir(fl); 12 } else { 13 fl.delete(); 14 } 15 } 16 } catch (Exception ex) { 17 } 19 dir.delete(); 20 } 21 22 public void testGetFile() throws Exception { 23 FileWriterUtil fileWriter = null; 24 String tmpDir = System.getProperty("java.io.tmpdir"); 25 File targetDir = new File (tmpDir + File.separator + "target"); 26 try { 27 targetDir.mkdirs(); 28 fileWriter = new FileWriterUtil(targetDir.getAbsolutePath()); 29 fileWriter.getWriter("com.iona.test" , "A.java"); 30 String packPath = "/com/iona/test/A.java".replace('/' , File.separatorChar); 31 String path = targetDir.getAbsolutePath() + packPath; 32 assertNotNull(new File (path).getName()); 33 } catch (IOException e) { 34 e.printStackTrace(); 36 } finally { 37 cleanDir(targetDir); 38 } 39 40 } 41 42 public void testGetWriter() throws Exception { 43 FileWriterUtil fileWriter = null; 44 String tmpDir = System.getProperty("java.io.tmpdir"); 45 File targetDir = new File (tmpDir + File.separator + "target"); 46 47 try { 48 targetDir.mkdirs(); 49 fileWriter = new FileWriterUtil(targetDir.getAbsolutePath()); 50 assertNotNull(fileWriter.getWriter("com.iona.test.SAMPLE" , "A.java")); 51 } catch (IOException e) { 52 e.printStackTrace(); 54 } finally { 55 cleanDir(targetDir); 56 } 57 } 58 59 60 } 61 | Popular Tags |