@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); }
@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 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 wrappedFileElementDelegatesToSourceForRemainingMethods() { final FileVisitDetails mappedDetails = expectSpecAndFileVisited(); final File file = new File("file"); context.checking( new Expectations() { { one(details).getFile(); will(returnValue(file)); } }); assertThat(mappedDetails.getFile(), sameInstance(file)); }
@Test public void givenATextInputFileInSubDirectoryWhenVisitFileThenFileIsCopiedToTaskOutputDirectory() { inputDirectory = new File(getClass().getResource("/javacc/inputWithNonJavaccFilesInSubDirectory").getFile()); when(task.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)); }