commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r897583 - /commons/proper/io/trunk/src/test/org/apache/commons/io/DirectoryWalkerTestCase.java
Date Sun, 10 Jan 2010 00:48:55 GMT
Author: sebb
Date: Sun Jan 10 00:48:55 2010
New Revision: 897583

URL: http://svn.apache.org/viewvc?rev=897583&view=rev
Log:
Test File filtering using a String results list

Modified:
    commons/proper/io/trunk/src/test/org/apache/commons/io/DirectoryWalkerTestCase.java

Modified: commons/proper/io/trunk/src/test/org/apache/commons/io/DirectoryWalkerTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/org/apache/commons/io/DirectoryWalkerTestCase.java?rev=897583&r1=897582&r2=897583&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/org/apache/commons/io/DirectoryWalkerTestCase.java (original)
+++ commons/proper/io/trunk/src/test/org/apache/commons/io/DirectoryWalkerTestCase.java Sun
Jan 10 00:48:55 2010
@@ -241,6 +241,12 @@
         }
     }
 
+    private void checkContainsString(String prefix, File[] files, Collection<String>
results) {
+        for (int i = 0; i < files.length; i++) {
+            assertTrue(prefix + "["+i+"] " + files[i], results.contains(files[i].toString()));
+        }
+    }
+
     /**
      * Extract the directories.
      */
@@ -365,6 +371,16 @@
 
     }
 
+    /**
+     * Test Filtering
+     */
+    public void testFilterString() {
+        List<String> results = new TestFileFinderString(dirsAndFilesFilter, -1).find(javaDir);
+        assertEquals("Result Size", (outputFiles.length + ioFiles.length), results.size());
+        checkContainsString("IO File", ioFiles, results);
+        checkContainsString("Output File", outputFiles, results);
+    }
+
     // ------------ Test DirectoryWalker implementation --------------------------
 
     /**
@@ -534,4 +550,32 @@
         }
     }
 
+    /**
+     * Test DirectoryWalker implementation that finds files in a directory hierarchy
+     * applying a file filter.
+     */
+    private static class TestFileFinderString extends DirectoryWalker<String> {
+
+        protected TestFileFinderString(FileFilter filter, int depthLimit) {
+            super(filter, depthLimit);
+        }
+
+        /** find files. */
+        protected List<String> find(File startDirectory) {
+           List<String> results = new ArrayList<String>();
+           try {
+               walk(startDirectory, results);
+           } catch(IOException ex) {
+               Assert.fail(ex.toString());
+           }
+           return results;
+        }
+
+        /** Handles a file by adding the File to the result set. */
+        @Override
+        protected void handleFile(File file, int depth, Collection<String> results)
{
+            results.add(file.toString());
+        }
+    }
+
 }



Mime
View raw message