### Question:
FileOperation implements FileAction { boolean isIgnored(File file){ boolean ignore = false; while(file != null){ String end = file.getAbsolutePath().substring(file.getAbsolutePath().lastIndexOf(System.getProperty("file.separator")) + 1); for(String pathToIgnore: ignoredPaths){ ignore = end.matches(pathToIgnore); if(ignore){ return true; } } file = file.getParentFile(); } return ignore; } FileOperation(String... ignoredPaths);  FileOperation(List<String> ignoredPaths); void operate(File file);  }### Answer:
@Test public void givenAnExistingFileNoFilterIsNotIgnored() throws Exception { assertFalse(new FileOperation() { public void onDirectory(File dir) throws IOException {} public void onFile(File file) throws IOException {} public void onNull(File nullFile) throws IOException {} public void onNew(File newFile) throws IOException {} }.isIgnored(new File(DirectoryManager.getBinDir()))); }
@Test public void givenAnExistingFileWithNonMatchingFilterIsNotIgnored() throws Exception { assertFalse(new FileOperation("nowayimpartofafoldername") { public void onDirectory(File dir) throws IOException {} public void onFile(File file) throws IOException {} public void onNull(File nullFile) throws IOException {} public void onNew(File newFile) throws IOException {} }.isIgnored(new File(DirectoryManager.getBinDir()))); }
@Test public void givenAnExistingFileWithMatchingFilterIsIgnored() throws Exception { assertTrue(new FileOperation("bin") { public void onDirectory(File dir) throws IOException {} public void onFile(File file) throws IOException {} public void onNull(File nullFile) throws IOException {} public void onNew(File newFile) throws IOException {} }.isIgnored(new File(DirectoryManager.getBinDir()))); }
@Test public void givenAnExistingFileWithFilterMatchingOnParentFolderIsIgnored() throws Exception { assertTrue(new FileOperation("app") { public void onDirectory(File dir) throws IOException {} public void onFile(File file) throws IOException {} public void onNull(File nullFile) throws IOException {} public void onNew(File newFile) throws IOException {} }.isIgnored(new File(DirectoryManager.getBinDir()))); }
@Test public void givenAnExistingFileWithPartiallyMatchingFilterIsNotIgnored() throws Exception { assertFalse(new FileOperation("bi") { public void onDirectory(File dir) throws IOException {} public void onFile(File file) throws IOException {} public void onNull(File nullFile) throws IOException {} public void onNew(File newFile) throws IOException {} }.isIgnored(new File(DirectoryManager.getBinDir()))); }
@Test public void givenAnExistingFileWithRegexMatchingFilterIsIgnored() throws Exception { assertTrue(new FileOperation("b.n") { public void onDirectory(File dir) throws IOException {} public void onFile(File file) throws IOException {} public void onNull(File nullFile) throws IOException {} public void onNew(File newFile) throws IOException {} }.isIgnored(new File(DirectoryManager.getBinDir()))); }
@Test public void givenAnExistingFileWithRegexMatchingFilterIsIgnored_compliment() throws Exception { assertFalse(new FileOperation("nowayimpart..afoldername") { public void onDirectory(File dir) throws IOException {} public void onFile(File file) throws IOException {} public void onNull(File nullFile) throws IOException {} public void onNew(File newFile) throws IOException {} }.isIgnored(new File(DirectoryManager.getBinDir()))); }
@Test public void givenIntellijFoldersSpecificallyFileInIdeaFolderAreIgnored() throws Exception { assertTrue(new FileOperation(".*\\.idea") { public void onDirectory(File dir) throws IOException {} public void onFile(File file) throws IOException {} public void onNull(File nullFile) throws IOException {} public void onNew(File newFile) throws IOException {} }.isIgnored(new File("/java-dojo/labs/01-koans/java-koans\\koans.idea/workspace.xml___jb_old___"))); }