|
27 | 27 | import junit.textui.TestRunner; |
28 | 28 |
|
29 | 29 | import org.apache.commons.io.FileUtils; |
| 30 | +import org.apache.commons.io.IOCase; |
30 | 31 | import org.apache.commons.io.testtools.FileBasedTestCase; |
31 | 32 |
|
32 | 33 | /** |
33 | 34 | * Used to test FileFilterUtils. |
34 | 35 | */ |
35 | 36 | public class FileFilterTestCase extends FileBasedTestCase { |
36 | 37 |
|
| 38 | + private static final boolean WINDOWS = (File.separatorChar == '\\'); |
| 39 | + |
37 | 40 | public FileFilterTestCase(String name) { |
38 | 41 | super(name); |
39 | 42 | } |
@@ -320,7 +323,7 @@ public void testOr() throws Exception { |
320 | 323 | assertEquals(true, f.getFileFilters().isEmpty()); |
321 | 324 | } |
322 | 325 |
|
323 | | - public void testWildcard() throws Exception { |
| 326 | + public void testDeprecatedWildcard() throws Exception { |
324 | 327 | IOFileFilter filter = new WildcardFilter("*.txt"); |
325 | 328 | List patternList = Arrays.asList( new String[] { "*.txt", "*.xml", "*.gif" } ); |
326 | 329 | IOFileFilter listFilter = new WildcardFilter( patternList ); |
@@ -380,7 +383,81 @@ public void testWildcard() throws Exception { |
380 | 383 | // expected |
381 | 384 | } |
382 | 385 | } |
383 | | - |
| 386 | + |
| 387 | + public void testWildcard() throws Exception { |
| 388 | + IOFileFilter filter = new WildcardFileFilter("*.txt"); |
| 389 | + assertFiltering(filter, new File("log.txt"), true); |
| 390 | + assertFiltering(filter, new File("log.TXT"), false); |
| 391 | + |
| 392 | + filter = new WildcardFileFilter("*.txt", IOCase.SENSITIVE); |
| 393 | + assertFiltering(filter, new File("log.txt"), true); |
| 394 | + assertFiltering(filter, new File("log.TXT"), false); |
| 395 | + |
| 396 | + filter = new WildcardFileFilter("*.txt", IOCase.INSENSITIVE); |
| 397 | + assertFiltering(filter, new File("log.txt"), true); |
| 398 | + assertFiltering(filter, new File("log.TXT"), true); |
| 399 | + |
| 400 | + filter = new WildcardFileFilter("*.txt", IOCase.SYSTEM); |
| 401 | + assertFiltering(filter, new File("log.txt"), true); |
| 402 | + assertFiltering(filter, new File("log.TXT"), WINDOWS); |
| 403 | + |
| 404 | + filter = new WildcardFileFilter("*.txt", (IOCase) null); |
| 405 | + assertFiltering(filter, new File("log.txt"), true); |
| 406 | + assertFiltering(filter, new File("log.TXT"), false); |
| 407 | + |
| 408 | + filter = new WildcardFileFilter(new String[] {"*.java", "*.class"}); |
| 409 | + assertFiltering(filter, new File("Test.java"), true); |
| 410 | + assertFiltering(filter, new File("Test.class"), true); |
| 411 | + assertFiltering(filter, new File("Test.jsp"), false); |
| 412 | + |
| 413 | + filter = new WildcardFileFilter(new String[] {"*.java", "*.class"}, IOCase.SENSITIVE); |
| 414 | + assertFiltering(filter, new File("Test.java"), true); |
| 415 | + assertFiltering(filter, new File("Test.JAVA"), false); |
| 416 | + |
| 417 | + filter = new WildcardFileFilter(new String[] {"*.java", "*.class"}, IOCase.INSENSITIVE); |
| 418 | + assertFiltering(filter, new File("Test.java"), true); |
| 419 | + assertFiltering(filter, new File("Test.JAVA"), true); |
| 420 | + |
| 421 | + filter = new WildcardFileFilter(new String[] {"*.java", "*.class"}, IOCase.SYSTEM); |
| 422 | + assertFiltering(filter, new File("Test.java"), true); |
| 423 | + assertFiltering(filter, new File("Test.JAVA"), WINDOWS); |
| 424 | + |
| 425 | + filter = new WildcardFileFilter(new String[] {"*.java", "*.class"}, (IOCase) null); |
| 426 | + assertFiltering(filter, new File("Test.java"), true); |
| 427 | + assertFiltering(filter, new File("Test.JAVA"), false); |
| 428 | + |
| 429 | + List patternList = Arrays.asList( new String[] { "*.txt", "*.xml", "*.gif" } ); |
| 430 | + IOFileFilter listFilter = new WildcardFileFilter( patternList ); |
| 431 | + assertFiltering(listFilter, new File("Test.txt"), true); |
| 432 | + assertFiltering(listFilter, new File("Test.xml"), true); |
| 433 | + assertFiltering(listFilter, new File("Test.gif"), true); |
| 434 | + assertFiltering(listFilter, new File("Test.bmp"), false); |
| 435 | + |
| 436 | + File txtFile = new File( "test.txt" ); |
| 437 | + File bmpFile = new File( "test.bmp" ); |
| 438 | + File dir = new File( "src/java" ); |
| 439 | + assertTrue( listFilter.accept( txtFile ) ); |
| 440 | + assertTrue( !listFilter.accept( bmpFile ) ); |
| 441 | + assertTrue( !listFilter.accept( dir ) ); |
| 442 | + |
| 443 | + assertTrue( listFilter.accept( txtFile.getParentFile(), txtFile.getName() ) ); |
| 444 | + assertTrue( !listFilter.accept( bmpFile.getParentFile(), bmpFile.getName() ) ); |
| 445 | + assertTrue( !listFilter.accept( dir.getParentFile(), dir.getName() ) ); |
| 446 | + |
| 447 | + try { |
| 448 | + new WildcardFileFilter((String) null); |
| 449 | + fail(); |
| 450 | + } catch (IllegalArgumentException ex) {} |
| 451 | + try { |
| 452 | + new WildcardFileFilter((String[]) null); |
| 453 | + fail(); |
| 454 | + } catch (IllegalArgumentException ex) {} |
| 455 | + try { |
| 456 | + new WildcardFileFilter((List) null); |
| 457 | + fail(); |
| 458 | + } catch (IllegalArgumentException ex) {} |
| 459 | + } |
| 460 | + |
384 | 461 | public void testDelegateFileFilter() throws Exception { |
385 | 462 | OrFileFilter orFilter = new OrFileFilter(); |
386 | 463 | File testFile = new File( "test.txt" ); |
|
0 commit comments