(no commit message)
[utils] / support / general / src / test / java / org / wamblee / io / RegexFilenameFilterTest.java
1 /*
2  * Copyright 2005-2010 the original author or authors.
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  * 
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  * 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.wamblee.io;
17
18 import java.io.File;
19 import java.io.FileFilter;
20
21 import junit.framework.TestCase;
22
23 public class RegexFilenameFilterTest extends TestCase {
24
25     public void testMatching() {
26         FileFilter filter1 = new RegexFilenameFilter(".*\\.txt");
27         FileFilter filter2 = new RegexFilenameFilter("^a.*\\.txt$");
28
29         File file1 = new File("x.txt").getAbsoluteFile();
30         File file2 = new File("a.txtx").getAbsoluteFile();
31         File file3 = new File("aatxt").getAbsoluteFile();
32         File file4 = new File("batxt").getAbsoluteFile();
33         File file5 = new File("adibladibla.txt").getAbsoluteFile();
34
35         assertTrue(filter1.accept(file1));
36         assertTrue(filter1.accept(file2));
37         assertFalse(filter1.accept(file3));
38         assertFalse(filter1.accept(file4));
39         assertTrue(filter1.accept(file5));
40
41         assertFalse(filter2.accept(file1));
42         assertFalse(filter2.accept(file2));
43         assertFalse(filter2.accept(file3));
44         assertFalse(filter2.accept(file4));
45         assertTrue(filter2.accept(file5));
46
47     }
48 }