@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)); }
@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"))); }
@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")); }
@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")); }
@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"))); }
public void execute(FileCopyDetails fileCopyDetails) { RelativePath path = fileCopyDetails.getRelativePath(); path = path.replaceLastName(transformer.transform(path.getLastName())); fileCopyDetails.setRelativePath(path); }