### Question:
NonJavaccSourceFileVisitor extends EmptyFileVisitor { @Override public void visitFile(FileVisitDetails fileDetails) { if (!isValidSourceFileForTask(fileDetails)) { File sourceFile = fileDetails.getFile(); File destinationFile = new File(sourceFile.getAbsolutePath().replace(compiler.getInputDirectory().getAbsolutePath(), compiler.getOutputDirectory().getAbsolutePath())); copyFile(sourceFile, destinationFile); } } NonJavaccSourceFileVisitor(SourceFileCompiler compiler); @Override void visitFile(FileVisitDetails fileDetails);  }### Answer:
@Test public void givenATextInputFileWhenVisitFileThenFileIsCopiedToTaskOutputDirectory() { FileVisitDetails fileDetails = mock(FileVisitDetails.class); when(fileDetails.getFile()).thenReturn(new File(inputDirectory, TEXT_INPUT_FILENAME)); when(fileDetails.getName()).thenReturn(TEXT_INPUT_FILENAME); sourceVisitor.visitFile(fileDetails); assertEquals(1, outputDirectory.list().length); assertTrue(Arrays.asList(outputDirectory.list()).contains(TEXT_INPUT_FILENAME)); }
@Test public void givenATextInputFileInSubDirectoryWhenVisitFileThenFileIsCopiedToTaskOutputDirectory() { inputDirectory = new File(getClass().getResource("/javacc/inputWithNonJavaccFilesInSubDirectory").getFile()); when(compiler.getInputDirectory()).thenReturn(inputDirectory); FileVisitDetails fileDetails = mock(FileVisitDetails.class); when(fileDetails.getFile()).thenReturn(new File(inputDirectory, TEXT_INPUT_IN_SUBFOLDER_FILENAME)); when(fileDetails.getName()).thenReturn(TEXT_INPUT_IN_SUBFOLDER_FILENAME); sourceVisitor.visitFile(fileDetails); assertEquals(1, outputDirectory.list().length); assertTrue(Arrays.asList(outputDirectory.list()).contains("sub")); final File outputSubDirectory = new File(outputDirectory, "sub"); assertEquals(1, outputSubDirectory.list().length); assertTrue(Arrays.asList(outputSubDirectory.list()).contains(TEXT_INPUT_FILENAME)); }
@Test public void givenAJavaccInputFileWhenVisitFileThenFileIsNotCopiedToTaskOutputDirectory() { FileVisitDetails fileDetails = mock(FileVisitDetails.class); when(fileDetails.getFile()).thenReturn(new File(inputDirectory, JAVACC_INPUT_FILENAME)); when(fileDetails.getName()).thenReturn(JAVACC_INPUT_FILENAME); sourceVisitor.visitFile(fileDetails); assertEquals(0, outputDirectory.list().length); }
@Test(expected = JavaccTaskException.class) public void givenAnUnexistingTextInputFileWhenVisitFileThenExceptionIsThrown() { FileVisitDetails fileDetails = mock(FileVisitDetails.class); when(fileDetails.getFile()).thenReturn(new File(UNEXISTING_INPUT_FILENAME)); when(fileDetails.getName()).thenReturn(UNEXISTING_INPUT_FILENAME); sourceVisitor.visitFile(fileDetails); }