예제 #1
0
  @Test
  public void getSizeReturnsSizeOfFilteredContent() {
    final FileCopyDetails mappedDetails = expectActionExecutedWhenFileVisited();

    context.checking(
        new Expectations() {
          {
            one(details).open();
            will(returnValue(new ByteArrayInputStream("content".getBytes())));
          }
        });

    mappedDetails.filter(HelperUtil.toClosure("{ 'PREFIX: ' + it } "));

    assertThat(mappedDetails.getSize(), equalTo(15L));
  }
예제 #2
0
  @Test
  public void initialRelativePathForFileIsSpecPathPlusFilePath() {
    FileCopyDetails copyDetails = expectActionExecutedWhenFileVisited();

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

    assertThat(copyDetails.getRelativePath(), equalTo(new RelativePath(true, "spec", "file")));
  }
예제 #3
0
  @Test
  public void copyActionCanFilterContentWhenFileIsCopiedToStream() {
    final FileCopyDetails mappedDetails = expectActionExecutedWhenFileVisited();

    context.checking(
        new Expectations() {
          {
            one(details).open();
            will(returnValue(new ByteArrayInputStream("content".getBytes())));
          }
        });

    mappedDetails.filter(HelperUtil.toClosure("{ 'PREFIX: ' + it } "));

    ByteArrayOutputStream outstr = new ByteArrayOutputStream();
    mappedDetails.copyTo(outstr);
    assertThat(new String(outstr.toByteArray()), equalTo("PREFIX: content"));
  }
예제 #4
0
  @Test
  public void copyActionCanFilterContentWhenFileIsCopiedToFile() {
    final FileCopyDetails mappedDetails = expectActionExecutedWhenFileVisited();

    context.checking(
        new Expectations() {
          {
            one(details).open();
            will(returnValue(new ByteArrayInputStream("content".getBytes())));
            one(details).isDirectory();
            will(returnValue(false));
            one(details).getLastModified();
            will(returnValue(90L));
          }
        });

    mappedDetails.filter(HelperUtil.toClosure("{ 'PREFIX: ' + it } "));

    TestFile destDir = tmpDir.getDir().file("test.txt");
    mappedDetails.copyTo(destDir);
    destDir.assertContents(equalTo("PREFIX: content"));
  }
예제 #5
0
  @Test
  public void copyActionCanChangeFileDestinationPath() {
    FileCopyDetails copyDetails = expectActionExecutedWhenFileVisited();

    RelativePath newPath = new RelativePath(true, "new");
    copyDetails.setRelativePath(newPath);
    assertThat(copyDetails.getRelativePath(), equalTo(newPath));

    copyDetails.setPath("/a/b");
    assertThat(copyDetails.getRelativePath(), equalTo(new RelativePath(true, "a", "b")));

    copyDetails.setName("new name");
    assertThat(copyDetails.getRelativePath(), equalTo(new RelativePath(true, "a", "new name")));
  }
예제 #6
0
 public void execute(FileCopyDetails fileCopyDetails) {
   RelativePath path = fileCopyDetails.getRelativePath();
   path = path.replaceLastName(transformer.transform(path.getLastName()));
   fileCopyDetails.setRelativePath(path);
 }