@Test (timeout = 30000)
public void testReplaceFile() throws IOException {

  setupDirs();
  final File srcFile = new File(tmp, "src");
  
  // src exists, and target does not exist:
  srcFile.createNewFile();
  assertTrue(srcFile.exists());
  final File targetFile = new File(tmp, "target");
  assertTrue(!targetFile.exists());
  FileUtil.replaceFile(srcFile, targetFile);
  assertTrue(!srcFile.exists());
  assertTrue(targetFile.exists());
  // src exists and target is a regular file: 
  srcFile.createNewFile();
  assertTrue(srcFile.exists());
  FileUtil.replaceFile(srcFile, targetFile);
  assertTrue(!srcFile.exists());
  assertTrue(targetFile.exists());
  
  // src exists, and target is a non-empty directory: 
  srcFile.createNewFile();
  assertTrue(srcFile.exists());
  targetFile.delete();
  targetFile.mkdirs();
  File obstacle = new File(targetFile, "obstacle");
  obstacle.createNewFile();
  assertTrue(obstacle.exists());
  assertTrue(targetFile.exists() && targetFile.isDirectory());
  try {
    FileUtil.replaceFile(srcFile, targetFile);
    assertTrue(false);
  } catch (IOException ioe) {
    // okay
  }
  // check up the post-condition: nothing is deleted:
  assertTrue(srcFile.exists());
  assertTrue(targetFile.exists() && targetFile.isDirectory());
  assertTrue(obstacle.exists());
}