Skip to content

Commit 3e5d9d3

Browse files
committed
Removed the necessity to have the data/test directory.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/io/trunk@140556 13f79535-47bb-0310-9956-ffa450edef68
1 parent 2c5a897 commit 3e5d9d3

1 file changed

Lines changed: 22 additions & 14 deletions

File tree

src/test/org/apache/commons/io/FileUtilsTestCase.java

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.io.File;
1919
import java.io.FileInputStream;
2020
import java.io.IOException;
21+
import java.io.OutputStream;
2122
import java.net.URL;
2223

2324
import org.apache.commons.io.testtools.FileBasedTestCase;
@@ -31,7 +32,7 @@
3132
*
3233
* @author Peter Donald
3334
* @author Matthew Hawthorne
34-
* @version $Id: FileUtilsTestCase.java,v 1.16 2004/04/18 07:29:00 bayard Exp $
35+
* @version $Id: FileUtilsTestCase.java,v 1.17 2004/04/23 22:30:42 jeremias Exp $
3536
* @see FileUtils
3637
*/
3738
public class FileUtilsTestCase extends FileBasedTestCase {
@@ -380,14 +381,19 @@ private String replaceAll(
380381
// Used to exist as IOTestCase class
381382
public void testFileUtils() throws Exception {
382383
// Loads file from classpath
383-
String path = "/test.txt";
384-
URL url = this.getClass().getResource(path);
385-
assertNotNull(path + " was not found.", url);
386-
387-
String filename = url.getFile();
388-
//The following line applies a fix for spaces in a path
389-
filename = replaceAll(filename, "%20", " ");
390-
String filename2 = "test2.txt";
384+
File file1 = new File(getTestDirectory(), "test.txt");
385+
String filename = file1.getAbsolutePath();
386+
387+
//Create test file on-the-fly (used to be in CVS)
388+
OutputStream out = new java.io.FileOutputStream(file1);
389+
try {
390+
out.write("This is a test".getBytes("UTF-8"));
391+
} finally {
392+
out.close();
393+
}
394+
395+
File file2 = new File(getTestDirectory(), "test2.txt");
396+
String filename2 = file2.getAbsolutePath();
391397

392398
//1.0 These lines commented out as FilenameUtils not in 1.0
393399
//1.0 assertTrue(
@@ -402,15 +408,17 @@ public void testFileUtils() throws Exception {
402408
//1.0 "Second test file does not exist",
403409
//1.0 !FilenameUtils.fileExists(filename2));
404410

405-
FileUtils.writeStringToFile(new File(filename2), filename, "UTF-8");
406-
//1.0 assertTrue("Second file was written", FilenameUtils.fileExists(filename2));
411+
FileUtils.writeStringToFile(file2, filename, "UTF-8");
412+
assertTrue(file2.exists());
413+
assertTrue(file2.length() > 0);
407414

408-
String file2contents = FileUtils.readFileToString(new File(filename2), "UTF-8");
415+
String file2contents = FileUtils.readFileToString(file2, "UTF-8");
409416
assertTrue(
410417
"Second file's contents correct",
411-
FileUtils.readFileToString(new File(filename2), "UTF-8").equals(file2contents));
418+
filename.equals(file2contents));
412419

413-
new File(filename2).delete(); // remove after 1.0
420+
assertTrue(file2.delete());
421+
414422
//1.0 FilenameUtils.fileDelete(filename2);
415423
//1.0 assertTrue(
416424
//1.0 "Second test file does not exist",

0 commit comments

Comments
 (0)