commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1022738 - in /commons/proper/io/trunk/src/test/java/org/apache/commons/io: FileUtilsListFilesTestCase.java FileUtilsTestCase.java
Date Thu, 14 Oct 2010 22:12:04 GMT
Author: ggregory
Date: Thu Oct 14 22:12:03 2010
New Revision: 1022738

URL: http://svn.apache.org/viewvc?rev=1022738&view=rev
Log:
Improve unit test code coverage.

Modified:
    commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileUtilsListFilesTestCase.java
    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/FileUtilsListFilesTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileUtilsListFilesTestCase.java?rev=1022738&r1=1022737&r2=1022738&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileUtilsListFilesTestCase.java
(original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileUtilsListFilesTestCase.java
Thu Oct 14 22:12:03 2010
@@ -101,52 +101,52 @@ public class FileUtilsListFilesTestCase 
         return filenames;
     }
     
-    public void testListFilesByExtension() throws Exception {
-        String[] extensions = {"xml", "txt"};
-        
-        Collection<File> files = FileUtils.listFiles(getLocalTestDirectory(), extensions,
false);
-        assertEquals(1, files.size());
+    public void testIterateFilesByExtension() throws Exception {
+        String[] extensions = { "xml", "txt" };
+
+        Iterator<File> files = FileUtils.iterateFiles(getLocalTestDirectory(), extensions,
false);
         Collection<String> filenames = filesToFilenames(files);
+        assertEquals(1, filenames.size());
         assertTrue(filenames.contains("dummy-build.xml"));
         assertFalse(filenames.contains("README"));
         assertFalse(filenames.contains("dummy-file.txt"));
-        
-        files = FileUtils.listFiles(getLocalTestDirectory(), extensions, true);
+
+        files = FileUtils.iterateFiles(getLocalTestDirectory(), extensions, true);
         filenames = filesToFilenames(files);
         assertEquals(4, filenames.size());
         assertTrue(filenames.contains("dummy-file.txt"));
         assertFalse(filenames.contains("dummy-index.html"));
-        
-        files = FileUtils.listFiles(getLocalTestDirectory(), null, false);
-        assertEquals(2, files.size());
+
+        files = FileUtils.iterateFiles(getLocalTestDirectory(), null, false);
         filenames = filesToFilenames(files);
+        assertEquals(2, filenames.size());
         assertTrue(filenames.contains("dummy-build.xml"));
         assertTrue(filenames.contains("README"));
-        assertFalse(filenames.contains("dummy-file.txt"));        
+        assertFalse(filenames.contains("dummy-file.txt"));
     }
 
-    public void testIterateFilesByExtension() throws Exception {
-        String[] extensions = { "xml", "txt" };
-
-        Iterator<File> files = FileUtils.iterateFiles(getLocalTestDirectory(), extensions,
false);
+    public void testListFilesByExtension() throws Exception {
+        String[] extensions = {"xml", "txt"};
+        
+        Collection<File> files = FileUtils.listFiles(getLocalTestDirectory(), extensions,
false);
+        assertEquals(1, files.size());
         Collection<String> filenames = filesToFilenames(files);
-        assertEquals(1, filenames.size());
         assertTrue(filenames.contains("dummy-build.xml"));
         assertFalse(filenames.contains("README"));
         assertFalse(filenames.contains("dummy-file.txt"));
-
-        files = FileUtils.iterateFiles(getLocalTestDirectory(), extensions, true);
+        
+        files = FileUtils.listFiles(getLocalTestDirectory(), extensions, true);
         filenames = filesToFilenames(files);
         assertEquals(4, filenames.size());
         assertTrue(filenames.contains("dummy-file.txt"));
         assertFalse(filenames.contains("dummy-index.html"));
-
-        files = FileUtils.iterateFiles(getLocalTestDirectory(), null, false);
+        
+        files = FileUtils.listFiles(getLocalTestDirectory(), null, false);
+        assertEquals(2, files.size());
         filenames = filesToFilenames(files);
-        assertEquals(2, filenames.size());
         assertTrue(filenames.contains("dummy-build.xml"));
         assertTrue(filenames.contains("README"));
-        assertFalse(filenames.contains("dummy-file.txt"));
+        assertFalse(filenames.contains("dummy-file.txt"));        
     }
 
     public void testListFiles() throws Exception {

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=1022738&r1=1022737&r2=1022738&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 Thu
Oct 14 22:12:03 2010
@@ -1270,7 +1270,18 @@ public class FileUtilsTestCase extends F
         subDir.delete();
     }
 
-    public void testReadFileToString() throws Exception {
+    public void testReadFileToStringWithDefaultEncoding() throws Exception {
+        File file = new File(getTestDirectory(), "read.obj");
+        FileOutputStream out = new FileOutputStream(file);
+        byte[] text = "Hello /u1234".getBytes();
+        out.write(text);
+        out.close();
+        
+        String data = FileUtils.readFileToString(file);
+        assertEquals("Hello /u1234", data);
+    }
+
+    public void testReadFileToStringWithEncoding() throws Exception {
         File file = new File(getTestDirectory(), "read.obj");
         FileOutputStream out = new FileOutputStream(file);
         byte[] text = "Hello /u1234".getBytes("UTF8");



Mime
View raw message