Refactor tests to break out WildcardFileFilterTest.
ADD
src/test/java/org/apache/commons/io/filefilter/AbstractFilterTest.java
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.io.filefilter;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.FileVisitResult;
+import java.nio.file.Files;
+import java.nio.file.Path;
+
+import org.apache.commons.io.IOCase;
+import org.junit.jupiter.api.io.TempDir;
+
+/**
+ * Used to test FileFilterUtils.
+ */
+public class AbstractFilterTest {
+
+ /**
+ * The subversion directory name.
+ */
+ static final String SVN_DIR_NAME = ".svn";
+
+ static final boolean WINDOWS = File.separatorChar == '\\';
+
+ @TempDir
+ public File temporaryFolder;
+
+ void assertFiltering(final IOFileFilter filter, final File file, final boolean expected) {
+ // Note. This only tests the (File, String) version if the parent of
+ // the File passed in is not null
+ assertEquals(expected, filter.accept(file),
+ "Filter(File) " + filter.getClass().getName() + " not " + expected + " for " + file);
+
+ if (file != null && file.getParentFile() != null) {
+ assertEquals(expected, filter.accept(file.getParentFile(), file.getName()),
+ "Filter(File, String) " + filter.getClass().getName() + " not " + expected + " for " + file);
+ } else if (file == null) {
+ assertEquals(expected, filter.accept(file),
+ "Filter(File, String) " + filter.getClass().getName() + " not " + expected + " for null");
+ }
+ assertNotNull(filter.toString());
+ }
+
+ void assertFiltering(final IOFileFilter filter, final Path path, final boolean expected) {
+ // Note. This only tests the (Path, Path) version if the parent of
+ // the File passed in is not null
+ final FileVisitResult expectedFileVisitResult = AbstractFileFilter.toDefaultFileVisitResult(expected);
+ assertEquals(expectedFileVisitResult, filter.accept(path, null),
+ "Filter(Path) " + filter.getClass().getName() + " not " + expectedFileVisitResult + " for " + path);
+
+ if (path != null && path.getParent() != null) {
+ assertEquals(expectedFileVisitResult, filter.accept(path, null),
+ "Filter(Path, Path) " + filter.getClass().getName() + " not " + expectedFileVisitResult + " for "
+ + path);
+ } else if (path == null) {
+ assertEquals(expectedFileVisitResult, filter.accept(path, null),
+ "Filter(Path, Path) " + filter.getClass().getName() + " not " + expectedFileVisitResult + " for null");
+ }
+ assertNotNull(filter.toString());
+ }
+
+ void assertFooBarFileFiltering(IOFileFilter filter) {
+ assertFiltering(filter, new File("foo"), true);
+ assertFiltering(filter, new File("foo"), true);
+ assertFiltering(filter, new File("bar"), true);
+ assertFiltering(filter, new File("fred"), false);
+ assertFiltering(filter, new File("foo").toPath(), true);
+ assertFiltering(filter, new File("foo").toPath(), true);
+ assertFiltering(filter, new File("bar").toPath(), true);
+ assertFiltering(filter, new File("fred").toPath(), false);
+
+ filter = new NameFileFilter(new String[] {"foo", "bar"}, IOCase.SENSITIVE);
+ assertFiltering(filter, new File("foo"), true);
+ assertFiltering(filter, new File("bar"), true);
+ assertFiltering(filter, new File("FOO"), false);
+ assertFiltering(filter, new File("BAR"), false);
+ assertFiltering(filter, new File("foo").toPath(), true);
+ assertFiltering(filter, new File("bar").toPath(), true);
+ assertFiltering(filter, new File("FOO").toPath(), false);
+ assertFiltering(filter, new File("BAR").toPath(), false);
+
+ filter = new NameFileFilter(new String[] {"foo", "bar"}, IOCase.INSENSITIVE);
+ assertFiltering(filter, new File("foo"), true);
+ assertFiltering(filter, new File("bar"), true);
+ assertFiltering(filter, new File("FOO"), true);
+ assertFiltering(filter, new File("BAR"), true);
+ assertFiltering(filter, new File("foo").toPath(), true);
+ assertFiltering(filter, new File("bar").toPath(), true);
+ assertFiltering(filter, new File("FOO").toPath(), true);
+ assertFiltering(filter, new File("BAR").toPath(), true);
+
+ filter = new NameFileFilter(new String[] {"foo", "bar"}, IOCase.SYSTEM);
+ assertFiltering(filter, new File("foo"), true);
+ assertFiltering(filter, new File("bar"), true);
+ assertFiltering(filter, new File("FOO"), WINDOWS);
+ assertFiltering(filter, new File("BAR"), WINDOWS);
+ assertFiltering(filter, new File("foo").toPath(), true);
+ assertFiltering(filter, new File("bar").toPath(), true);
+ assertFiltering(filter, new File("FOO").toPath(), WINDOWS);
+ assertFiltering(filter, new File("BAR").toPath(), WINDOWS);
+
+ filter = new NameFileFilter(new String[] {"foo", "bar"}, null);
+ assertFiltering(filter, new File("foo"), true);
+ assertFiltering(filter, new File("bar"), true);
+ assertFiltering(filter, new File("FOO"), false);
+ assertFiltering(filter, new File("BAR"), false);
+ assertFiltering(filter, new File("foo").toPath(), true);
+ assertFiltering(filter, new File("bar").toPath(), true);
+ assertFiltering(filter, new File("FOO").toPath(), false);
+ assertFiltering(filter, new File("BAR").toPath(), false);
+
+ // repeat for a List
+ final java.util.ArrayList<String> list = new java.util.ArrayList<>();
+ list.add("foo");
+ list.add("bar");
+ filter = new NameFileFilter(list);
+ assertFiltering(filter, new File("foo"), true);
+ assertFiltering(filter, new File("bar"), true);
+ assertFiltering(filter, new File("fred"), false);
+ assertFiltering(filter, new File("foo").toPath(), true);
+ assertFiltering(filter, new File("bar").toPath(), true);
+ assertFiltering(filter, new File("fred").toPath(), false);
+
+ filter = new NameFileFilter("foo");
+ assertFiltering(filter, new File("foo"), true);
+ assertFiltering(filter, new File("FOO"), false); // case-sensitive
+ assertFiltering(filter, new File("barfoo"), false);
+ assertFiltering(filter, new File("foobar"), false);
+ assertFiltering(filter, new File("fred"), false);
+ assertFiltering(filter, new File("foo").toPath(), true);
+ assertFiltering(filter, new File("FOO").toPath(), false); // case-sensitive
+ assertFiltering(filter, new File("barfoo").toPath(), false);
+ assertFiltering(filter, new File("foobar").toPath(), false);
+ assertFiltering(filter, new File("fred").toPath(), false);
+
+ // FileFilterUtils.nameFileFilter(String, IOCase) tests
+ filter = FileFilterUtils.nameFileFilter("foo", IOCase.INSENSITIVE);
+ assertFiltering(filter, new File("foo"), true);
+ assertFiltering(filter, new File("FOO"), true); // case-insensitive
+ assertFiltering(filter, new File("barfoo"), false);
+ assertFiltering(filter, new File("foobar"), false);
+ assertFiltering(filter, new File("fred"), false);
+ assertFiltering(filter, new File("foo").toPath(), true);
+ assertFiltering(filter, new File("FOO").toPath(), true); // case-insensitive
+ assertFiltering(filter, new File("barfoo").toPath(), false);
+ assertFiltering(filter, new File("foobar").toPath(), false);
+ assertFiltering(filter, new File("fred").toPath(), false);
+ }
+
+ boolean equalsLastModified(final File left, final File right) throws IOException {
+ return Files.getLastModifiedTime(left.toPath()).equals(Files.getLastModifiedTime(right.toPath()));
+ }
+
+ // -----------------------------------------------------------------------
+
+
+}

MODIFY
src/test/java/org/apache/commons/io/filefilter/FileFilterTestCase.java
src/test/java/org/apache/commons/io/filefilter/FileFilterTestCase.java
import java.io.File;
import java.io.FileFilter;
import java.io.FilenameFilter;
-import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileVisitResult;
import org.apache.commons.io.test.TestUtils;
import org.apache.commons.lang3.SystemUtils;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.io.TempDir;
/**
* Used to test FileFilterUtils.
*/
-public class FileFilterTestCase {
-
- /**
- * The subversion directory name.
- */
- static final String SVN_DIR_NAME = ".svn";
-
- private static final boolean WINDOWS = File.separatorChar == '\\';
-
- @TempDir
- public File temporaryFolder;
-
- void assertFiltering(final IOFileFilter filter, final File file, final boolean expected) {
- // Note. This only tests the (File, String) version if the parent of
- // the File passed in is not null
- assertEquals(expected, filter.accept(file),
- "Filter(File) " + filter.getClass().getName() + " not " + expected + " for " + file);
-
- if (file != null && file.getParentFile() != null) {
- assertEquals(expected, filter.accept(file.getParentFile(), file.getName()),
- "Filter(File, String) " + filter.getClass().getName() + " not " + expected + " for " + file);
- } else if (file == null) {
- assertEquals(expected, filter.accept(file),
- "Filter(File, String) " + filter.getClass().getName() + " not " + expected + " for null");
- }
- assertNotNull(filter.toString());
- }
-
- void assertFiltering(final IOFileFilter filter, final Path path, final boolean expected) {
- // Note. This only tests the (Path, Path) version if the parent of
- // the File passed in is not null
- final FileVisitResult expectedFileVisitResult = AbstractFileFilter.toDefaultFileVisitResult(expected);
- assertEquals(expectedFileVisitResult, filter.accept(path, null),
- "Filter(Path) " + filter.getClass().getName() + " not " + expectedFileVisitResult + " for " + path);
-
- if (path != null && path.getParent() != null) {
- assertEquals(expectedFileVisitResult, filter.accept(path, null),
- "Filter(Path, Path) " + filter.getClass().getName() + " not " + expectedFileVisitResult + " for "
- + path);
- } else if (path == null) {
- assertEquals(expectedFileVisitResult, filter.accept(path, null),
- "Filter(Path, Path) " + filter.getClass().getName() + " not " + expectedFileVisitResult + " for null");
- }
- assertNotNull(filter.toString());
- }
-
- private void assertFooBarFileFiltering(IOFileFilter filter) {
- assertFiltering(filter, new File("foo"), true);
- assertFiltering(filter, new File("foo"), true);
- assertFiltering(filter, new File("bar"), true);
- assertFiltering(filter, new File("fred"), false);
- assertFiltering(filter, new File("foo").toPath(), true);
- assertFiltering(filter, new File("foo").toPath(), true);
- assertFiltering(filter, new File("bar").toPath(), true);
- assertFiltering(filter, new File("fred").toPath(), false);
-
- filter = new NameFileFilter(new String[] {"foo", "bar"}, IOCase.SENSITIVE);
- assertFiltering(filter, new File("foo"), true);
- assertFiltering(filter, new File("bar"), true);
- assertFiltering(filter, new File("FOO"), false);
- assertFiltering(filter, new File("BAR"), false);
- assertFiltering(filter, new File("foo").toPath(), true);
- assertFiltering(filter, new File("bar").toPath(), true);
- assertFiltering(filter, new File("FOO").toPath(), false);
- assertFiltering(filter, new File("BAR").toPath(), false);
-
- filter = new NameFileFilter(new String[] {"foo", "bar"}, IOCase.INSENSITIVE);
- assertFiltering(filter, new File("foo"), true);
- assertFiltering(filter, new File("bar"), true);
- assertFiltering(filter, new File("FOO"), true);
- assertFiltering(filter, new File("BAR"), true);
- assertFiltering(filter, new File("foo").toPath(), true);
- assertFiltering(filter, new File("bar").toPath(), true);
- assertFiltering(filter, new File("FOO").toPath(), true);
- assertFiltering(filter, new File("BAR").toPath(), true);
-
- filter = new NameFileFilter(new String[] {"foo", "bar"}, IOCase.SYSTEM);
- assertFiltering(filter, new File("foo"), true);
- assertFiltering(filter, new File("bar"), true);
- assertFiltering(filter, new File("FOO"), WINDOWS);
- assertFiltering(filter, new File("BAR"), WINDOWS);
- assertFiltering(filter, new File("foo").toPath(), true);
- assertFiltering(filter, new File("bar").toPath(), true);
- assertFiltering(filter, new File("FOO").toPath(), WINDOWS);
- assertFiltering(filter, new File("BAR").toPath(), WINDOWS);
-
- filter = new NameFileFilter(new String[] {"foo", "bar"}, null);
- assertFiltering(filter, new File("foo"), true);
- assertFiltering(filter, new File("bar"), true);
- assertFiltering(filter, new File("FOO"), false);
- assertFiltering(filter, new File("BAR"), false);
- assertFiltering(filter, new File("foo").toPath(), true);
- assertFiltering(filter, new File("bar").toPath(), true);
- assertFiltering(filter, new File("FOO").toPath(), false);
- assertFiltering(filter, new File("BAR").toPath(), false);
-
- // repeat for a List
- final java.util.ArrayList<String> list = new java.util.ArrayList<>();
- list.add("foo");
- list.add("bar");
- filter = new NameFileFilter(list);
- assertFiltering(filter, new File("foo"), true);
- assertFiltering(filter, new File("bar"), true);
- assertFiltering(filter, new File("fred"), false);
- assertFiltering(filter, new File("foo").toPath(), true);
- assertFiltering(filter, new File("bar").toPath(), true);
- assertFiltering(filter, new File("fred").toPath(), false);
-
- filter = new NameFileFilter("foo");
- assertFiltering(filter, new File("foo"), true);
- assertFiltering(filter, new File("FOO"), false); // case-sensitive
- assertFiltering(filter, new File("barfoo"), false);
- assertFiltering(filter, new File("foobar"), false);
- assertFiltering(filter, new File("fred"), false);
- assertFiltering(filter, new File("foo").toPath(), true);
- assertFiltering(filter, new File("FOO").toPath(), false); // case-sensitive
- assertFiltering(filter, new File("barfoo").toPath(), false);
- assertFiltering(filter, new File("foobar").toPath(), false);
- assertFiltering(filter, new File("fred").toPath(), false);
-
- // FileFilterUtils.nameFileFilter(String, IOCase) tests
- filter = FileFilterUtils.nameFileFilter("foo", IOCase.INSENSITIVE);
- assertFiltering(filter, new File("foo"), true);
- assertFiltering(filter, new File("FOO"), true); // case-insensitive
- assertFiltering(filter, new File("barfoo"), false);
- assertFiltering(filter, new File("foobar"), false);
- assertFiltering(filter, new File("fred"), false);
- assertFiltering(filter, new File("foo").toPath(), true);
- assertFiltering(filter, new File("FOO").toPath(), true); // case-insensitive
- assertFiltering(filter, new File("barfoo").toPath(), false);
- assertFiltering(filter, new File("foobar").toPath(), false);
- assertFiltering(filter, new File("fred").toPath(), false);
- }
-
- private boolean equalsLastModified(final File left, final File right) throws IOException {
- return Files.getLastModifiedTime(left.toPath()).equals(Files.getLastModifiedTime(right.toPath()));
- }
+public class FileFilterTestCase extends AbstractFilterTest {
@Test
public void testAgeFilter() throws Exception {
@@ -1731,128 +1593,4 @@ public void testTrue() {
assertNotNull(TrueFileFilter.INSTANCE.toString());
}
- @Test
- public void testWildcard() {
- IOFileFilter filter = new WildcardFileFilter("*.txt");
- assertFiltering(filter, new File("log.txt"), true);
- assertFiltering(filter, new File("log.TXT"), false);
- //
- assertFiltering(filter, new File("log.txt").toPath(), true);
- assertFiltering(filter, new File("log.TXT").toPath(), false);
-
- filter = new WildcardFileFilter("*.txt", IOCase.SENSITIVE);
- assertFiltering(filter, new File("log.txt"), true);
- assertFiltering(filter, new File("log.TXT"), false);
- //
- assertFiltering(filter, new File("log.txt").toPath(), true);
- assertFiltering(filter, new File("log.TXT").toPath(), false);
-
- filter = new WildcardFileFilter("*.txt", IOCase.INSENSITIVE);
- assertFiltering(filter, new File("log.txt"), true);
- assertFiltering(filter, new File("log.TXT"), true);
- //
- assertFiltering(filter, new File("log.txt").toPath(), true);
- assertFiltering(filter, new File("log.TXT").toPath(), true);
-
- filter = new WildcardFileFilter("*.txt", IOCase.SYSTEM);
- assertFiltering(filter, new File("log.txt"), true);
- assertFiltering(filter, new File("log.TXT"), WINDOWS);
- //
- assertFiltering(filter, new File("log.txt").toPath(), true);
- assertFiltering(filter, new File("log.TXT").toPath(), WINDOWS);
-
- filter = new WildcardFileFilter("*.txt", null);
- assertFiltering(filter, new File("log.txt"), true);
- assertFiltering(filter, new File("log.TXT"), false);
- //
- assertFiltering(filter, new File("log.txt").toPath(), true);
- assertFiltering(filter, new File("log.TXT").toPath(), false);
-
- filter = new WildcardFileFilter("*.java", "*.class");
- assertFiltering(filter, new File("Test.java"), true);
- assertFiltering(filter, new File("Test.class"), true);
- assertFiltering(filter, new File("Test.jsp"), false);
- //
- assertFiltering(filter, new File("Test.java").toPath(), true);
- assertFiltering(filter, new File("Test.class").toPath(), true);
- assertFiltering(filter, new File("Test.jsp").toPath(), false);
-
- filter = new WildcardFileFilter(new String[] {"*.java", "*.class"}, IOCase.SENSITIVE);
- assertFiltering(filter, new File("Test.java"), true);
- assertFiltering(filter, new File("Test.JAVA"), false);
- //
- assertFiltering(filter, new File("Test.java").toPath(), true);
- assertFiltering(filter, new File("Test.JAVA").toPath(), false);
-
- filter = new WildcardFileFilter(new String[] {"*.java", "*.class"}, IOCase.INSENSITIVE);
- assertFiltering(filter, new File("Test.java"), true);
- assertFiltering(filter, new File("Test.JAVA"), true);
- //
- assertFiltering(filter, new File("Test.java").toPath(), true);
- assertFiltering(filter, new File("Test.JAVA").toPath(), true);
-
- filter = new WildcardFileFilter(new String[] {"*.java", "*.class"}, IOCase.SYSTEM);
- assertFiltering(filter, new File("Test.java"), true);
- assertFiltering(filter, new File("Test.JAVA"), WINDOWS);
- //
- assertFiltering(filter, new File("Test.java").toPath(), true);
- assertFiltering(filter, new File("Test.JAVA").toPath(), WINDOWS);
-
- filter = new WildcardFileFilter(new String[] {"*.java", "*.class"}, null);
- assertFiltering(filter, new File("Test.java"), true);
- assertFiltering(filter, new File("Test.JAVA"), false);
- //
- assertFiltering(filter, new File("Test.java").toPath(), true);
- assertFiltering(filter, new File("Test.JAVA").toPath(), false);
-
- final List<String> patternList = Arrays.asList("*.txt", "*.xml", "*.gif");
- final IOFileFilter listFilter = new WildcardFileFilter(patternList);
- 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);
- //
- assertFiltering(listFilter, new File("Test.txt").toPath(), true);
- assertFiltering(listFilter, new File("Test.xml").toPath(), true);
- assertFiltering(listFilter, new File("Test.gif").toPath(), true);
- assertFiltering(listFilter, new File("Test.bmp").toPath(), false);
-
- final File txtFile = new File("test.txt");
- final Path txtPath = txtFile.toPath();
- final File bmpFile = new File("test.bmp");
- final Path bmpPath = bmpFile.toPath();
- final File dirFile = new File("src/java");
- final Path dirPath = dirFile.toPath();
- assertTrue(listFilter.accept(txtFile));
- assertFalse(listFilter.accept(bmpFile));
- assertFalse(listFilter.accept(dirFile));
- //
- assertEquals(FileVisitResult.CONTINUE, listFilter.accept(txtFile.toPath(), null));
- assertEquals(FileVisitResult.TERMINATE, listFilter.accept(bmpFile.toPath(), null));
- assertEquals(FileVisitResult.TERMINATE, listFilter.accept(dirFile.toPath(), null));
-
- assertTrue(listFilter.accept(txtFile.getParentFile(), txtFile.getName()));
- assertFalse(listFilter.accept(bmpFile.getParentFile(), bmpFile.getName()));
- assertFalse(listFilter.accept(dirFile.getParentFile(), dirFile.getName()));
- //
- assertEquals(FileVisitResult.CONTINUE, listFilter.accept(txtPath, null));
- assertEquals(FileVisitResult.TERMINATE, listFilter.accept(bmpPath, null));
- assertEquals(FileVisitResult.TERMINATE, listFilter.accept(dirPath, null));
-
- try {
- new WildcardFileFilter((String) null);
- fail();
- } catch (final IllegalArgumentException ignore) {
- }
- try {
- new WildcardFileFilter((String[]) null);
- fail();
- } catch (final IllegalArgumentException ignore) {
- }
- try {
- new WildcardFileFilter((List<String>) null);
- fail();
- } catch (final IllegalArgumentException ignore) {
- }
- }
}

ADD
src/test/java/org/apache/commons/io/filefilter/WildcardFileFilterTest.java
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.io.filefilter;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+
+import java.io.File;
+import java.nio.file.FileVisitResult;
+import java.nio.file.Path;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.commons.io.IOCase;
+import org.junit.jupiter.api.Test;
+
+public class WildcardFileFilterTest extends AbstractFilterTest {
+
+ @Test
+ public void testWildcard() {
+ IOFileFilter filter = new WildcardFileFilter("*.txt");
+ assertFiltering(filter, new File("log.txt"), true);
+ assertFiltering(filter, new File("log.TXT"), false);
+ //
+ assertFiltering(filter, new File("log.txt").toPath(), true);
+ assertFiltering(filter, new File("log.TXT").toPath(), false);
+
+ filter = new WildcardFileFilter("*.txt", IOCase.SENSITIVE);
+ assertFiltering(filter, new File("log.txt"), true);
+ assertFiltering(filter, new File("log.TXT"), false);
+ //
+ assertFiltering(filter, new File("log.txt").toPath(), true);
+ assertFiltering(filter, new File("log.TXT").toPath(), false);
+
+ filter = new WildcardFileFilter("*.txt", IOCase.INSENSITIVE);
+ assertFiltering(filter, new File("log.txt"), true);
+ assertFiltering(filter, new File("log.TXT"), true);
+ //
+ assertFiltering(filter, new File("log.txt").toPath(), true);
+ assertFiltering(filter, new File("log.TXT").toPath(), true);
+
+ filter = new WildcardFileFilter("*.txt", IOCase.SYSTEM);
+ assertFiltering(filter, new File("log.txt"), true);
+ assertFiltering(filter, new File("log.TXT"), WINDOWS);
+ //
+ assertFiltering(filter, new File("log.txt").toPath(), true);
+ assertFiltering(filter, new File("log.TXT").toPath(), WINDOWS);
+
+ filter = new WildcardFileFilter("*.txt", null);
+ assertFiltering(filter, new File("log.txt"), true);
+ assertFiltering(filter, new File("log.TXT"), false);
+ //
+ assertFiltering(filter, new File("log.txt").toPath(), true);
+ assertFiltering(filter, new File("log.TXT").toPath(), false);
+
+ filter = new WildcardFileFilter("*.java", "*.class");
+ assertFiltering(filter, new File("Test.java"), true);
+ assertFiltering(filter, new File("Test.class"), true);
+ assertFiltering(filter, new File("Test.jsp"), false);
+ //
+ assertFiltering(filter, new File("Test.java").toPath(), true);
+ assertFiltering(filter, new File("Test.class").toPath(), true);
+ assertFiltering(filter, new File("Test.jsp").toPath(), false);
+
+ filter = new WildcardFileFilter(new String[] {"*.java", "*.class"}, IOCase.SENSITIVE);
+ assertFiltering(filter, new File("Test.java"), true);
+ assertFiltering(filter, new File("Test.JAVA"), false);
+ //
+ assertFiltering(filter, new File("Test.java").toPath(), true);
+ assertFiltering(filter, new File("Test.JAVA").toPath(), false);
+
+ filter = new WildcardFileFilter(new String[] {"*.java", "*.class"}, IOCase.INSENSITIVE);
+ assertFiltering(filter, new File("Test.java"), true);
+ assertFiltering(filter, new File("Test.JAVA"), true);
+ //
+ assertFiltering(filter, new File("Test.java").toPath(), true);
+ assertFiltering(filter, new File("Test.JAVA").toPath(), true);
+
+ filter = new WildcardFileFilter(new String[] {"*.java", "*.class"}, IOCase.SYSTEM);
+ assertFiltering(filter, new File("Test.java"), true);
+ assertFiltering(filter, new File("Test.JAVA"), WINDOWS);
+ //
+ assertFiltering(filter, new File("Test.java").toPath(), true);
+ assertFiltering(filter, new File("Test.JAVA").toPath(), WINDOWS);
+
+ filter = new WildcardFileFilter(new String[] {"*.java", "*.class"}, null);
+ assertFiltering(filter, new File("Test.java"), true);
+ assertFiltering(filter, new File("Test.JAVA"), false);
+ //
+ assertFiltering(filter, new File("Test.java").toPath(), true);
+ assertFiltering(filter, new File("Test.JAVA").toPath(), false);
+
+ final List<String> patternList = Arrays.asList("*.txt", "*.xml", "*.gif");
+ final IOFileFilter listFilter = new WildcardFileFilter(patternList);
+ 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);
+ //
+ assertFiltering(listFilter, new File("Test.txt").toPath(), true);
+ assertFiltering(listFilter, new File("Test.xml").toPath(), true);
+ assertFiltering(listFilter, new File("Test.gif").toPath(), true);
+ assertFiltering(listFilter, new File("Test.bmp").toPath(), false);
+
+ final File txtFile = new File("test.txt");
+ final Path txtPath = txtFile.toPath();
+ final File bmpFile = new File("test.bmp");
+ final Path bmpPath = bmpFile.toPath();
+ final File dirFile = new File("src/java");
+ final Path dirPath = dirFile.toPath();
+ assertTrue(listFilter.accept(txtFile));
+ assertFalse(listFilter.accept(bmpFile));
+ assertFalse(listFilter.accept(dirFile));
+ //
+ assertEquals(FileVisitResult.CONTINUE, listFilter.accept(txtFile.toPath(), null));
+ assertEquals(FileVisitResult.TERMINATE, listFilter.accept(bmpFile.toPath(), null));
+ assertEquals(FileVisitResult.TERMINATE, listFilter.accept(dirFile.toPath(), null));
+
+ assertTrue(listFilter.accept(txtFile.getParentFile(), txtFile.getName()));
+ assertFalse(listFilter.accept(bmpFile.getParentFile(), bmpFile.getName()));
+ assertFalse(listFilter.accept(dirFile.getParentFile(), dirFile.getName()));
+ //
+ assertEquals(FileVisitResult.CONTINUE, listFilter.accept(txtPath, null));
+ assertEquals(FileVisitResult.TERMINATE, listFilter.accept(bmpPath, null));
+ assertEquals(FileVisitResult.TERMINATE, listFilter.accept(dirPath, null));
+
+ try {
+ new WildcardFileFilter((String) null);
+ fail();
+ } catch (final IllegalArgumentException ignore) {
+ }
+ try {
+ new WildcardFileFilter((String[]) null);
+ fail();
+ } catch (final IllegalArgumentException ignore) {
+ }
+ try {
+ new WildcardFileFilter((List<String>) null);
+ fail();
+ } catch (final IllegalArgumentException ignore) {
+ }
+ }
+}

Refactor tests to break out WildcardFileFilterTest.