commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jerem...@apache.org
Subject cvs commit: jakarta-commons/io/src/test/org/apache/commons/io FileUtilsTestCase.java
Date Fri, 23 Apr 2004 22:30:43 GMT
jeremias    2004/04/23 15:30:42

  Modified:    io/src/test/org/apache/commons/io FileUtilsTestCase.java
  Log:
  Removed the necessity to have the data/test directory.
  
  Revision  Changes    Path
  1.17      +22 -14    jakarta-commons/io/src/test/org/apache/commons/io/FileUtilsTestCase.java
  
  Index: FileUtilsTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/io/src/test/org/apache/commons/io/FileUtilsTestCase.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- FileUtilsTestCase.java	18 Apr 2004 07:29:00 -0000	1.16
  +++ FileUtilsTestCase.java	23 Apr 2004 22:30:42 -0000	1.17
  @@ -18,6 +18,7 @@
   import java.io.File;
   import java.io.FileInputStream;
   import java.io.IOException;
  +import java.io.OutputStream;
   import java.net.URL;
   
   import org.apache.commons.io.testtools.FileBasedTestCase;
  @@ -380,14 +381,19 @@
       // Used to exist as IOTestCase class
       public void testFileUtils() throws Exception {
           // Loads file from classpath
  -        String path = "/test.txt";
  -        URL url = this.getClass().getResource(path);
  -        assertNotNull(path + " was not found.", url);
  -
  -        String filename = url.getFile();
  -        //The following line applies a fix for spaces in a path
  -        filename = replaceAll(filename, "%20", " ");
  -        String filename2 = "test2.txt";
  +        File file1 = new File(getTestDirectory(), "test.txt");
  +        String filename = file1.getAbsolutePath();
  +        
  +        //Create test file on-the-fly (used to be in CVS)
  +        OutputStream out = new java.io.FileOutputStream(file1);
  +        try {
  +            out.write("This is a test".getBytes("UTF-8"));
  +        } finally {
  +            out.close();
  +        }
  +        
  +        File file2 = new File(getTestDirectory(), "test2.txt");
  +        String filename2 = file2.getAbsolutePath();
   
   //1.0 These lines commented out as FilenameUtils not in 1.0
   //1.0        assertTrue(
  @@ -402,15 +408,17 @@
   //1.0            "Second test file does not exist",
   //1.0            !FilenameUtils.fileExists(filename2));
   
  -        FileUtils.writeStringToFile(new File(filename2), filename, "UTF-8");
  -//1.0        assertTrue("Second file was written", FilenameUtils.fileExists(filename2));
  +        FileUtils.writeStringToFile(file2, filename, "UTF-8");
  +        assertTrue(file2.exists());
  +        assertTrue(file2.length() > 0);
   
  -        String file2contents = FileUtils.readFileToString(new File(filename2), "UTF-8");
  +        String file2contents = FileUtils.readFileToString(file2, "UTF-8");
           assertTrue(
               "Second file's contents correct",
  -            FileUtils.readFileToString(new File(filename2), "UTF-8").equals(file2contents));
  +            filename.equals(file2contents));
   
  -          new File(filename2).delete();   // remove after 1.0
  +        assertTrue(file2.delete());
  +        
   //1.0        FilenameUtils.fileDelete(filename2);
   //1.0        assertTrue(
   //1.0            "Second test file does not exist",
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message