commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1022736 - /commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileUtilsListFilesTestCase.java
Date Thu, 14 Oct 2010 22:02:44 GMT
Author: ggregory
Date: Thu Oct 14 22:02:43 2010
New Revision: 1022736

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

Modified:
    commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileUtilsListFilesTestCase.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=1022736&r1=1022735&r2=1022736&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:02:43 2010
@@ -17,6 +17,7 @@
 package org.apache.commons.io;
 
 import java.io.File;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Iterator;
 
@@ -85,10 +86,17 @@ public class FileUtilsListFilesTestCase 
     }
     
     private Collection<String> filesToFilenames(Collection<File> files) {
-        Collection<String> filenames = new java.util.ArrayList<String>(files.size());
-        Iterator<File> i = files.iterator();
-        while (i.hasNext()) {
-            filenames.add(i.next().getName());
+        Collection<String> filenames = new ArrayList<String>(files.size());
+        for (File file : files) {
+            filenames.add(file.getName());
+        }
+        return filenames;
+    }
+    
+    private Collection<String> filesToFilenames(Iterator<File> files) {
+        Collection<String> filenames = new ArrayList<String>();
+        while (files.hasNext()) {
+            filenames.add(files.next().getName());
         }
         return filenames;
     }
@@ -114,8 +122,31 @@ public class FileUtilsListFilesTestCase 
         filenames = filesToFilenames(files);
         assertTrue(filenames.contains("dummy-build.xml"));
         assertTrue(filenames.contains("README"));
+        assertFalse(filenames.contains("dummy-file.txt"));        
+    }
+
+    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.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.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"));
-        
     }
 
     public void testListFiles() throws Exception {



Mime
View raw message