コード例 #1
0
  @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);
  }
コード例 #2
0
  @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);
  }
コード例 #3
0
  @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));
  }
コード例 #4
0
  @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));
  }
コード例 #5
0
  @Test
  public void relativePathForDirIsSpecPathPlusFilePath() {
    FileVisitDetails visitDetails = expectSpecAndDirVisited();

    context.checking(
        new Expectations() {
          {
            allowing(spec).getDestPath();
            will(returnValue(new RelativePath(false, "spec")));
            allowing(details).getRelativePath();
            will(returnValue(new RelativePath(false, "dir")));
          }
        });

    assertThat(visitDetails.getRelativePath(), equalTo(new RelativePath(false, "spec", "dir")));
  }
コード例 #6
0
  @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));
  }
コード例 #7
0
 public void visitFile(FileVisitDetails source) {
   File target = source.getRelativePath().getFile(baseDestDir);
   copyFile(source, target);
 }