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