diff options
author | wisberg <wisberg> | 2003-01-06 22:41:40 +0000 |
---|---|---|
committer | wisberg <wisberg> | 2003-01-06 22:41:40 +0000 |
commit | 89997f3c4660c10e902cf74256ee922e79b0c7e4 (patch) | |
tree | ff95e0cdf5cf2e4cdbaa84c0ffabd601b91a2329 /util/testsrc | |
parent | 4b530427b5924d93e6162b8c513052994d6373eb (diff) | |
download | aspectj-89997f3c4660c10e902cf74256ee922e79b0c7e4.tar.gz aspectj-89997f3c4660c10e902cf74256ee922e79b0c7e4.zip |
- generalized copyFiles to handle file-file, file-dir, and dir-dir
Diffstat (limited to 'util/testsrc')
-rw-r--r-- | util/testsrc/org/aspectj/util/FileUtilTest.java | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/util/testsrc/org/aspectj/util/FileUtilTest.java b/util/testsrc/org/aspectj/util/FileUtilTest.java index 7cda1692c..e528867da 100644 --- a/util/testsrc/org/aspectj/util/FileUtilTest.java +++ b/util/testsrc/org/aspectj/util/FileUtilTest.java @@ -58,6 +58,70 @@ public class FileUtilTest extends TestCase { } } + public void testNotIsFileIsDirectory() { + File noSuchFile = new File("foo"); + assertTrue(!noSuchFile.isFile()); + assertTrue(!noSuchFile.isDirectory()); + } + + public void testCopyFiles() { + // bad input + Class iaxClass = IllegalArgumentException.class; + + checkCopyFiles(null, null, iaxClass, false); + + File noSuchFile = new File("foo"); + checkCopyFiles(noSuchFile, null, iaxClass, false); + checkCopyFiles(noSuchFile, noSuchFile, iaxClass, false); + + File tempDir = FileUtil.getTempDir("testCopyFiles"); + tempFiles.add(tempDir); + File fromFile = new File(tempDir, "fromFile"); + String err = FileUtil.writeAsString(fromFile, "contents of from file"); + assertTrue(err, null == err); + checkCopyFiles(fromFile, null, iaxClass, false); + checkCopyFiles(fromFile, fromFile, iaxClass, false); + + // file-file + File toFile = new File(tempDir, "toFile"); + checkCopyFiles(fromFile, toFile, null, true); + + // file-dir + File toDir= new File(tempDir, "toDir"); + assertTrue(toDir.mkdirs()); + checkCopyFiles(fromFile, toDir, null, true); + + // dir-dir + File fromDir= new File(tempDir, "fromDir"); + assertTrue(fromDir.mkdirs()); + checkCopyFiles(fromFile, fromDir, null, false); + File toFile2 = new File(fromDir, "toFile2"); + checkCopyFiles(fromFile, toFile2, null, false); + checkCopyFiles(fromDir, toDir, null, true); + } + + void checkCopyFiles(File from, File to, Class exceptionClass, boolean clean) { + try { + FileUtil.copyFile(from, to); + assertTrue(null == exceptionClass); + if (to.isFile()) { + assertTrue(from.length() == to.length()); // XXX cheap test + } else { + File toFile = new File(to, from.getName()); + assertTrue(from.length() == toFile.length()); + } + } catch (Throwable t) { + assertTrue(null != exceptionClass); + assertTrue(exceptionClass.isAssignableFrom(t.getClass())); + } finally { + if (clean && (null != to) && (to.exists())) { + if (to.isDirectory()) { + FileUtil.deleteContents(to); + } + to.delete(); + } + } + } public void testDirCopySubdirs() throws IOException { // XXX dir diff File srcDir = new File("src"); File destDir = FileUtil.getTempDir("testDirCopySubdirs"); |