1818import java .io .File ;
1919import java .io .FileInputStream ;
2020import java .io .IOException ;
21+ import java .io .OutputStream ;
2122import java .net .URL ;
2223
2324import org .apache .commons .io .testtools .FileBasedTestCase ;
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 */
3738public 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