commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tobr...@apache.org
Subject svn commit: r201764 - in /jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io: ./ filefilter/ input/
Date Sun, 26 Jun 2005 09:57:25 GMT
Author: tobrien
Date: Sat Jun 25 09:33:04 2005
New Revision: 201764

URL: http://svn.apache.org/viewcvs?rev=201764&view=rev
Log:
Increased test coverage for file filter tests, and also fixed some nits in CountingInputStreamTest.

Modified:
    jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/IOUtilsWriteTestCase.java
    jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/filefilter/FileFilterTestCase.java
    jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/filefilter/IOFileFilterAbstractTestCase.java
    jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/input/CountingInputStreamTest.java
    jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/input/PackageTestSuite.java

Modified: jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/IOUtilsWriteTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/IOUtilsWriteTestCase.java?rev=201764&r1=201763&r2=201764&view=diff
==============================================================================
--- jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/IOUtilsWriteTestCase.java
(original)
+++ jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/IOUtilsWriteTestCase.java
Sat Jun 25 09:33:04 2005
@@ -205,8 +205,6 @@
     }
 
     public void testWrite_stringToOutputStream_nullData() throws Exception {
-        String str = new String(inData, "US-ASCII");
-        
         ByteArrayOutputStream baout = new ByteArrayOutputStream();
         YellOnFlushAndCloseOutputStream out = new YellOnFlushAndCloseOutputStream(baout,
true, true);
         
@@ -242,8 +240,6 @@
     }
 
     public void testWrite_stringToOutputStream_Encoding_nullData() throws Exception {
-        String str = new String(inData, "US-ASCII");
-        
         ByteArrayOutputStream baout = new ByteArrayOutputStream();
         YellOnFlushAndCloseOutputStream out = new YellOnFlushAndCloseOutputStream(baout,
true, true);
         
@@ -293,8 +289,6 @@
     }
 
     public void testWrite_stringToWriter_Encoding_nullData() throws Exception {
-        String str = new String(inData, "US-ASCII");
-        
         ByteArrayOutputStream baout = new ByteArrayOutputStream();
         YellOnFlushAndCloseOutputStream out = new YellOnFlushAndCloseOutputStream(baout,
true, true);
         Writer writer = new OutputStreamWriter(baout, "US-ASCII");
@@ -330,8 +324,6 @@
     }
 
     public void testWrite_charArrayToOutputStream_nullData() throws Exception {
-        String str = new String(inData, "US-ASCII");
-        
         ByteArrayOutputStream baout = new ByteArrayOutputStream();
         YellOnFlushAndCloseOutputStream out = new YellOnFlushAndCloseOutputStream(baout,
true, true);
         
@@ -418,8 +410,6 @@
     }
 
     public void testWrite_charArrayToWriter_Encoding_nullData() throws Exception {
-        String str = new String(inData, "US-ASCII");
-        
         ByteArrayOutputStream baout = new ByteArrayOutputStream();
         YellOnFlushAndCloseOutputStream out = new YellOnFlushAndCloseOutputStream(baout,
true, true);
         Writer writer = new OutputStreamWriter(baout, "US-ASCII");

Modified: jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/filefilter/FileFilterTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/filefilter/FileFilterTestCase.java?rev=201764&r1=201763&r2=201764&view=diff
==============================================================================
--- jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/filefilter/FileFilterTestCase.java
(original)
+++ jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/filefilter/FileFilterTestCase.java
Sat Jun 25 09:33:04 2005
@@ -16,6 +16,11 @@
 package org.apache.commons.io.filefilter;
 
 import java.io.File;
+import java.io.FileFilter;
+import java.io.FilenameFilter;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
 
 import junit.framework.TestSuite;
 import junit.textui.TestRunner;
@@ -68,10 +73,16 @@
 
     public void testSuffix() throws Exception {
         IOFileFilter filter = new SuffixFileFilter(new String[] { "tes", "est" });
+        File testFile = new File( "test" );
+        File fredFile = new File( "fred" );
         assertFiltering(filter, new File("fred.tes"), true);
         assertFiltering(filter, new File("fred.est"), true);
         assertFiltering(filter, new File("fred.EST"), false); //case-sensitive
         assertFiltering(filter, new File("fred.exe"), false);
+
+        filter = FileFilterUtils.orFileFilter( 
+        			FileFilterUtils.suffixFileFilter( "tes" ),
+        			FileFilterUtils.suffixFileFilter( "est" ) );
         assertFiltering(filter, new File("fred"), false);
         assertFiltering(filter, new File(".tes"), true);
         assertFiltering(filter, new File("fred.test"), true);
@@ -80,12 +91,33 @@
         assertFiltering(filter, new File("test"), true);
         assertFiltering(filter, new File("fred"), false);
 
+        assertTrue( filter.accept( testFile.getParentFile(), testFile.getName() ) );
+        assertTrue( !filter.accept( fredFile.getParentFile(), fredFile.getName() ) );
+
+        List prefixes = Arrays.asList( new String[] { "ood", "red" } );
+        IOFileFilter listFilter = new SuffixFileFilter( prefixes );
+
+        assertTrue( !listFilter.accept( testFile.getParentFile(), testFile.getName() ) );
+        assertTrue( listFilter.accept( fredFile.getParentFile(), fredFile.getName() ) );
+
         try {
             new SuffixFileFilter((String) null);
             fail();
         } catch (IllegalArgumentException ex) {
         }
-    }
+
+        try {
+            new SuffixFileFilter((String[]) null);
+            fail();
+        } catch (IllegalArgumentException ex) {
+        }
+
+        try {
+            new SuffixFileFilter((List) null);
+            fail();
+        } catch (IllegalArgumentException ex) {
+        }
+}
 
     public void testDirectory() throws Exception {
         IOFileFilter filter = new DirectoryFileFilter();
@@ -103,11 +135,16 @@
 
     public void testPrefix() throws Exception {
         IOFileFilter filter = new PrefixFileFilter(new String[] { "foo", "bar" });
+        File testFile = new File( "test" );
+        File fredFile = new File( "fred" );
+
         assertFiltering(filter, new File("foo.test"), true);
         assertFiltering(filter, new File("FOO.test"), false);  //case-sensitive
         assertFiltering(filter, new File("foo"), true);
         assertFiltering(filter, new File("bar"), true);
         assertFiltering(filter, new File("food/"), true);
+
+        filter = FileFilterUtils.prefixFileFilter( "bar" );
         assertFiltering(filter, new File("barred\\"), true);
         assertFiltering(filter, new File("test"), false);
         assertFiltering(filter, new File("fo_o.test"), false);
@@ -117,11 +154,33 @@
         assertFiltering(filter, new File("test"), true);
         assertFiltering(filter, new File("fred"), false);
 
+        assertTrue( filter.accept( testFile.getParentFile(), testFile.getName() ) );
+        assertTrue( !filter.accept( fredFile.getParentFile(), fredFile.getName() ) );
+
+        List prefixes = Arrays.asList( new String[] { "foo", "fre" } );
+        IOFileFilter listFilter = new PrefixFileFilter( prefixes );
+
+        assertTrue( !listFilter.accept( testFile.getParentFile(), testFile.getName() ) );
+        assertTrue( listFilter.accept( fredFile.getParentFile(), fredFile.getName() ) );
+        
+        
         try {
             new PrefixFileFilter((String) null);
             fail();
         } catch (IllegalArgumentException ex) {
         }
+
+        try {
+            new PrefixFileFilter((String[]) null);
+            fail();
+        } catch (IllegalArgumentException ex) {
+        }
+
+        try {
+            new PrefixFileFilter((List) null);
+            fail();
+        } catch (IllegalArgumentException ex) {
+        }
     }
 
     public void testNameFilter() throws Exception {
@@ -147,6 +206,33 @@
         assertFiltering(filter, new File("fred"), false);
     }
 
+    public void testNameFilterNullArgument() throws Exception {
+    	String test = null;
+    	try {
+    		IOFileFilter filter = new NameFileFilter(test);
+    		fail( "constructing a NameFileFilter with a null String argument should fail.");
+    	} catch( IllegalArgumentException iae ) {
+    	}
+    }
+
+    public void testNameFilterNullArrayArgument() throws Exception {
+    	String[] test = null;
+    	try {
+    		IOFileFilter filter = new NameFileFilter(test);
+    		fail( "constructing a NameFileFilter with a null String[] argument should fail.");
+    	} catch( IllegalArgumentException iae ) {
+    	}
+    }
+
+    public void testNameFilterNullListArgument() throws Exception {
+    	List test = null;
+    	try {
+    		IOFileFilter filter = new NameFileFilter(test);
+    		fail( "constructing a NameFileFilter with a null List argument should fail.");
+    	} catch( IllegalArgumentException iae ) {
+    	}
+    }
+
     public void testTrue() throws Exception {
         IOFileFilter filter = FileFilterUtils.trueFileFilter();
         assertFiltering(filter, new File("foo.test"), true);
@@ -180,20 +266,51 @@
         assertFiltering(new AndFileFilter(trueFilter, falseFilter), new File("foo.test"),
false);
         assertFiltering(new AndFileFilter(falseFilter, trueFilter), new File("foo.test"),
false);
         assertFiltering(new AndFileFilter(falseFilter, falseFilter), new File("foo.test"),
false);
+
+        List filters = new ArrayList();
+        assertFiltering( new AndFileFilter( filters ), new File( "test" ), false );
+        assertFiltering( new AndFileFilter(), new File( "test" ), false );
+        
         try {
             new AndFileFilter(falseFilter, null);
             fail();
         } catch (IllegalArgumentException ex) {
         }
-    }
+
+        try {
+            new AndFileFilter((List) null);
+            fail();
+        } catch (IllegalArgumentException ex) {
+        }
+}
 
     public void testOr() throws Exception {
         IOFileFilter trueFilter = TrueFileFilter.INSTANCE;
         IOFileFilter falseFilter = FalseFileFilter.INSTANCE;
-        assertFiltering(new OrFileFilter(trueFilter, trueFilter), new File("foo.test"), true);
-        assertFiltering(new OrFileFilter(trueFilter, falseFilter), new File("foo.test"),
true);
-        assertFiltering(new OrFileFilter(falseFilter, trueFilter), new File("foo.test"),
true);
-        assertFiltering(new OrFileFilter(falseFilter, falseFilter), new File("foo.test"),
false);
+        File testFile = new File( "foo.test" );
+        assertFiltering(new OrFileFilter(trueFilter, trueFilter), testFile, true);
+        assertFiltering(new OrFileFilter(trueFilter, falseFilter), testFile, true);
+        assertFiltering(new OrFileFilter(falseFilter, trueFilter), testFile, true);
+        assertFiltering(new OrFileFilter(falseFilter, falseFilter), testFile, false);
+        assertFiltering(new OrFileFilter(), testFile, false);
+        
+        List filters = new ArrayList();
+        filters.add( trueFilter );
+        filters.add( falseFilter );
+
+        OrFileFilter orFilter = new OrFileFilter( filters );
+
+        assertFiltering(orFilter, testFile, true);
+        assertEquals( orFilter.getFileFilters(), filters );
+        orFilter.removeFileFilter( trueFilter );
+        assertFiltering(orFilter, testFile, false);
+        orFilter.setFileFilters( filters );
+        assertFiltering(orFilter, testFile, true);
+        
+        assertTrue( orFilter.accept( testFile.getParentFile(), testFile.getName() ) );
+        orFilter.removeFileFilter( trueFilter );
+        assertTrue( !orFilter.accept( testFile.getParentFile(), testFile.getName() ) );
+        
         try {
             new OrFileFilter(falseFilter, null);
             fail();
@@ -204,6 +321,12 @@
 
     public void testWildcard() throws Exception {
         IOFileFilter filter = new WildcardFilter("*.txt");
+        List patternList = Arrays.asList( new String[] { "*.txt", "*.xml", "*.gif" } );
+        IOFileFilter listFilter = new WildcardFilter( patternList );
+        File txtFile = new File( "test.txt" );
+        File bmpFile = new File( "test.bmp" );
+        File dir = new File( "src/java" );
+        
         assertFiltering(filter, new File("log.txt"), true);
 //        assertFiltering(filter, new File("log.txt.bak"), false);
 
@@ -222,12 +345,63 @@
         assertFiltering(filter, new File("Test.class"), true);
         assertFiltering(filter, new File("Test.jsp"), false);
 
+        assertFiltering(listFilter, new File("Test.txt"), true);
+        assertFiltering(listFilter, new File("Test.xml"), true);
+        assertFiltering(listFilter, new File("Test.gif"), true);
+        assertFiltering(listFilter, new File("Test.bmp"), false);
+
+        assertTrue( listFilter.accept( txtFile ) );
+        assertTrue( !listFilter.accept( bmpFile ) );
+        assertTrue( !listFilter.accept( dir ) );
+
+        assertTrue( listFilter.accept( txtFile.getParentFile(), txtFile.getName() ) );
+        assertTrue( !listFilter.accept( bmpFile.getParentFile(), bmpFile.getName() ) );
+        assertTrue( !listFilter.accept( dir.getParentFile(), dir.getName() ) );
+
         try {
             new WildcardFilter((String) null);
             fail();
         } catch (IllegalArgumentException ex) {
             // expected
         }
+
+        try {
+            new WildcardFilter((String[]) null);
+            fail();
+        } catch (IllegalArgumentException ex) {
+            // expected
+        }
+
+        try {
+            new WildcardFilter((List) null);
+            fail();
+        } catch (IllegalArgumentException ex) {
+            // expected
+        }
+    }
+    
+    public void testDelegateFileFilter() throws Exception {
+    	OrFileFilter orFilter = new OrFileFilter();
+    	File testFile = new File( "test.txt" );
+
+    	IOFileFilter filter = new DelegateFileFilter((FileFilter) orFilter);
+    	assertFiltering( filter, testFile, false );
+
+    	filter = new DelegateFileFilter((FilenameFilter) orFilter);
+    	assertFiltering( filter, testFile, false );
+
+    	try {
+    		new DelegateFileFilter((FileFilter) null);
+    		fail();
+    	} catch( IllegalArgumentException iae ) {
+    	}
+
+    	try {
+    		new DelegateFileFilter((FilenameFilter) null);
+    		fail();
+    	} catch( IllegalArgumentException iae ) {
+    	}
+
     }
 
     public void testMakeCVSAware() throws Exception {

Modified: jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/filefilter/IOFileFilterAbstractTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/filefilter/IOFileFilterAbstractTestCase.java?rev=201764&r1=201763&r2=201764&view=diff
==============================================================================
--- jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/filefilter/IOFileFilterAbstractTestCase.java
(original)
+++ jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/filefilter/IOFileFilterAbstractTestCase.java
Sat Jun 25 09:33:04 2005
@@ -18,7 +18,7 @@
 import java.io.File;
 import junit.framework.TestCase;
 
-public class IOFileFilterAbstractTestCase extends TestCase {
+public abstract class IOFileFilterAbstractTestCase extends TestCase {
   
   /**
    * Constructs a new instance of

Modified: jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/input/CountingInputStreamTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/input/CountingInputStreamTest.java?rev=201764&r1=201763&r2=201764&view=diff
==============================================================================
--- jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/input/CountingInputStreamTest.java
(original)
+++ jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/input/CountingInputStreamTest.java
Sat Jun 25 09:33:04 2005
@@ -18,7 +18,6 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
-import java.util.Arrays;
 
 import junit.framework.TestCase;
 
@@ -81,7 +80,7 @@
 
         int count = cis.resetCount();
         found = cis.read(result, 6, 5);
-        assertEquals( found, cis.getCount() );
+        assertEquals( found, count );
     }
     
     public void testZeroLength1() throws Exception {

Modified: jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/input/PackageTestSuite.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/input/PackageTestSuite.java?rev=201764&r1=201763&r2=201764&view=diff
==============================================================================
--- jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/input/PackageTestSuite.java
(original)
+++ jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/input/PackageTestSuite.java
Sat Jun 25 09:33:04 2005
@@ -33,6 +33,7 @@
 
     public static Test suite() {
         TestSuite suite = new TestSuite("IO Utilities - input");
+        suite.addTest(new TestSuite(ClassLoaderObjectInputStreamTest.class));
         suite.addTest(new TestSuite(CountingInputStreamTest.class));
         suite.addTest(new TestSuite(SwappedDataInputStreamTest.class));
         return suite;



---------------------------------------------------------------------
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