コード例 #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 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"));
  }
コード例 #3
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"));
  }