### Question:
FSToFSTransferClient implements BinaryTransferClient { @Override public URI transferReplaceExisting(PID binPid, URI sourceFileUri) { return transfer(binPid, sourceFileUri, true); } FSToFSTransferClient(IngestSource source, StorageLocation destination); @Override URI transfer(PID binPid, URI sourceFileUri); @Override URI transferReplaceExisting(PID binPid, URI sourceFileUri); URI transfer(PID binPid, URI sourceFileUri, boolean allowOverwrite); @Override URI transferVersion(PID binPid, URI sourceFileUri); @Override void shutdown(); @Override boolean isTransferred(PID binPid, URI sourceUri); @Override BinaryDetails getStoredBinaryDetails(PID binPid);  }### Answer:
@Test(expected = BinaryTransferException.class) public void transferReplaceFileThatDoesNotExist() { Path sourceFile = sourcePath.resolve("nofilehere.txt"); client.transferReplaceExisting(binPid, sourceFile.toUri()); }
@Test public void transferReplaceFileReadOnlySource() throws Exception { when(ingestSource.isReadOnly()).thenReturn(true); Path sourceFile = createSourceFile(); client.transferReplaceExisting(binPid, sourceFile.toUri()); assertIsSourceFile(binDestPath); assertIsSourceFile(sourceFile); }
@Test public void transferReplaceFileModifiableSource() throws Exception { when(ingestSource.isReadOnly()).thenReturn(false); Path sourceFile = createSourceFile(); client.transferReplaceExisting(binPid, sourceFile.toUri()); assertIsSourceFile(binDestPath); }
@Test public void transferReplaceFileAlreadyExists() throws Exception { String existingContent = "I exist"; Files.createDirectories(binDestPath.getParent()); createFile(binDestPath, existingContent); Path sourceFile = createSourceFile(); client.transferReplaceExisting(binPid, sourceFile.toUri()); assertIsSourceFile(binDestPath); }
@Test public void rollbackOnTransferInterruption() throws Exception { String existingContent = "I exist"; Path parentPath = binDestPath.getParent(); Files.createDirectories(parentPath); createFile(binDestPath, existingContent); Path sourceFile = createSourceFile(); File destFile = binDestPath.toFile(); File parentDir = parentPath.toFile(); parentDir.setReadOnly(); try { client.transferReplaceExisting(binPid, sourceFile.toUri()); } catch (BinaryTransferException e) { assertTrue("Original file should be present", destFile.exists()); assertEquals(1, binDestPath.getParent().toFile().listFiles().length); } finally { parentDir.setWritable(true); destFile.delete(); } }