1 package jodd.file; 2 3 import java.io.File; 4 import java.io.IOException; 5 import junit.framework.TestCase; 6 7 public class TestFileUtil2 extends TestCase { 8 9 protected String dataRoot = "modules/testcase/data"; 10 11 public void setUp() { 12 String curDir = System.getProperty("user.dir"); 13 curDir = curDir.replace('\\', '/'); 14 if (curDir.endsWith("/testcase") == true) { 15 dataRoot = "data"; 16 } else if (curDir.endsWith("/modules") == true) { 17 dataRoot = "testcase/data"; 18 } 19 } 20 21 22 public void testFileManipulations() { 23 String root = dataRoot + "/file/"; 24 String tmp = root + "tmp/"; 25 String tmp2 = root + "xxx/"; 26 String tmp3 = root + "zzz/"; 27 28 assertTrue(FileUtil.copy(root + "a.txt", root + "w.txt")); 30 assertTrue(FileUtil.copy(root + "a.png", root + "w.png")); 31 assertTrue(FileUtil.copy(root + "a.txt", root)); assertTrue(FileUtil.copy(root + "a.txt", root + "w.txt")); 33 34 assertTrue(FileUtil.mkdirs(tmp)); 36 assertTrue(FileUtil.mkdirs(tmp + "x/")); 37 38 assertTrue(FileUtil.copy(root + "a.txt", tmp)); 40 assertTrue(FileUtil.copy(root + "a.png", tmp)); 41 42 assertFalse(FileUtil.copySafe(root + "a.txt", tmp)); 43 44 assertTrue(FileUtil.move(root + "w.txt", tmp + "w.txt")); 46 assertTrue(FileUtil.move(root + "w.png", tmp)); 47 48 assertFalse(FileUtil.moveSafe(root + "w.png", tmp)); 49 50 assertTrue(FileUtil.delete(tmp + "a.txt")); 52 assertTrue(FileUtil.delete(tmp + "a.png")); 53 assertFalse(FileUtil.delete(tmp + "a.txt")); 54 55 assertTrue(FileUtil.moveDir(tmp, tmp2)); 57 assertTrue(FileUtil.moveDir(tmp2, tmp2)); 58 59 assertTrue(FileUtil.copyDir(tmp2, tmp3)); 61 62 assertTrue(FileUtil.deleteDir(tmp2)); 64 assertTrue(FileUtil.deleteDir(tmp3)); 65 66 } 67 } 68 | Popular Tags |