Author: sebb
Date: Sun Jun 2 14:15:37 2013
New Revision: 1488714
URL: http://svn.apache.org/r1488714
Log:
Add test case to show file sizes are compared at end
Modified:
commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileUtilsTestCase.java
Modified:
commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileUtilsTestCase.java
URL:
http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileUtilsTestCase.java?rev=1488714&r1=1488713&r2=1488714&view=diff
==============================================================================
---
commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileUtilsTestCase.java
(original)
+++
commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileUtilsTestCase.java
Sun Jun 2 14:15:37 2013
@@ -2568,6 +2568,32 @@ public class FileUtilsTestCase extends F
// If this does not work, test will fail next time (assuming target is
not cleaned)
}
+ // Test helper class to pretend a file is shorter than it is
+ private static class ShorterFile extends File {
+ public ShorterFile(String pathname) {
+ super(pathname);
+ }
+ @Override
+ public long length() {
+ return super.length() - 1;
+ }
+ }
+
+ // This test relies on FileUtils.copyFile using File.length to check the
output size
+ public void testIncorrectOutputSize() throws Exception {
+ File inFile = new File("pom.xml");
+ File outFile = new ShorterFile("target/pom.tmp"); // it will report a
shorter file
+ try {
+ FileUtils.copyFile(inFile, outFile);
+ fail("Expected IOException");
+ } catch (Exception e) {
+ final String msg = e.toString();
+ assertTrue(msg, msg.contains("Failed to copy full contents"));
+ } finally {
+ outFile.delete(); // tidy up
+ }
+ }
+
/**
* DirectoryWalker implementation that recursively lists all files and
directories.
*/