11/*
22 * Copyright 2002-2004 The Apache Software Foundation.
3- *
3+ *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
66 * You may obtain a copy of the License at
7- *
7+ *
88 * http://www.apache.org/licenses/LICENSE-2.0
9- *
9+ *
1010 * Unless required by applicable law or agreed to in writing, software
1111 * distributed under the License is distributed on an "AS IS" BASIS,
1212 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -29,11 +29,11 @@ public class FileFilterTestCase extends TestCase {
2929 public FileFilterTestCase (String name ) {
3030 super (name );
3131 }
32-
32+
3333 public static void main (String [] args ) {
3434 TestRunner .run (suite ());
3535 }
36-
36+
3737 public static TestSuite suite () {
3838 return new TestSuite (FileFilterTestCase .class );
3939 }
@@ -45,7 +45,7 @@ public void tearDown() {
4545 }
4646
4747 public void assertFiltering (IOFileFilter filter , File file , boolean expected ) throws Exception {
48- // Note. This only tests the (File, String) version if the parent of
48+ // Note. This only tests the (File, String) version if the parent of
4949 // the File passed in is not null
5050 assertTrue (
5151 "Filter(File) " + filter .getClass ().getName () + " not " + expected + " for " + file ,
@@ -71,11 +71,11 @@ public void testSuffix() throws Exception {
7171 assertFiltering (filter , new File ("fred" ), false );
7272 assertFiltering (filter , new File (".tes" ), true );
7373 assertFiltering (filter , new File ("fred.test" ), true );
74-
74+
7575 filter = new SuffixFileFilter ("est" );
7676 assertFiltering (filter , new File ("test" ), true );
7777 assertFiltering (filter , new File ("fred" ), false );
78-
78+
7979 try {
8080 new SuffixFileFilter ((String ) null );
8181 fail ();
@@ -108,18 +108,18 @@ public void testPrefix() throws Exception {
108108 assertFiltering (filter , new File ("test" ), false );
109109 assertFiltering (filter , new File ("fo_o.test" ), false );
110110 assertFiltering (filter , new File ("abar.exe" ), false );
111-
111+
112112 filter = new PrefixFileFilter ("tes" );
113113 assertFiltering (filter , new File ("test" ), true );
114114 assertFiltering (filter , new File ("fred" ), false );
115-
115+
116116 try {
117117 new PrefixFileFilter ((String ) null );
118118 fail ();
119119 } catch (IllegalArgumentException ex ) {
120120 }
121121 }
122-
122+
123123 public void testNameFilter () throws Exception {
124124 IOFileFilter filter = new NameFileFilter (new String [] { "foo" , "bar" });
125125 assertFiltering (filter , new File ("foo" ), true );
@@ -197,4 +197,35 @@ public void testOr() throws Exception {
197197 }
198198 }
199199
200+
201+ public void testWildcard () throws Exception {
202+ IOFileFilter filter = new WildcardFilter ("*.txt" );
203+ assertFiltering (filter , new File ("log.txt" ), true );
204+ // assertFiltering(filter, new File("log.txt.bak"), false);
205+
206+ filter = new WildcardFilter ("log?.txt" );
207+ assertFiltering (filter , new File ("log1.txt" ), true );
208+ assertFiltering (filter , new File ("log12.txt" ), false );
209+
210+ filter = new WildcardFilter ("open??.????04" );
211+ assertFiltering (filter , new File ("openAB.102504" ), true );
212+ assertFiltering (filter , new File ("openA.102504" ), false );
213+ assertFiltering (filter , new File ("openXY.123103" ), false );
214+ // assertFiltering(filter, new File("openAB.102504.old"), false);
215+
216+ filter = new WildcardFilter (new String [] {"*.java" , "*.class" });
217+ assertFiltering (filter , new File ("Test.java" ), true );
218+ assertFiltering (filter , new File ("Test.class" ), true );
219+ assertFiltering (filter , new File ("Test.jsp" ), false );
220+
221+ try {
222+ new WildcardFilter ((String ) null );
223+ fail ();
224+ } catch (IllegalArgumentException ex ) {
225+ // expected
226+ }
227+ }
228+
229+
200230}
231+
0 commit comments