### Question:
LocalFileSystem extends FileSystem { @Override public boolean rename(final Path src, final Path dst) throws IOException { final File srcFile = pathToFile(src); final File dstFile = pathToFile(dst); final File dstParent = dstFile.getParentFile(); dstParent.mkdirs(); try { Files.move(srcFile.toPath(), dstFile.toPath(), StandardCopyOption.REPLACE_EXISTING); return true; } catch (NoSuchFileException | AccessDeniedException | DirectoryNotEmptyException | SecurityException ex) { return false; } } LocalFileSystem(); @Override BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len); @Override FileStatus getFileStatus(Path f); @Override URI getUri(); @Override Path getWorkingDirectory(); @Override Path getHomeDirectory(); @Override FSDataInputStream open(final Path f, final int bufferSize); @Override FSDataInputStream open(final Path f); @Override boolean exists(Path f); @Override FileStatus[] listStatus(final Path f); @Override boolean delete(final Path f, final boolean recursive); @Override boolean mkdirs(final Path f); @Override FSDataOutputStream create(final Path filePath, final WriteMode overwrite); @Override boolean rename(final Path src, final Path dst); @Override boolean isDistributedFS(); @Override FileSystemKind getKind(); static URI getLocalFsURI(); static LocalFileSystem getSharedInstance();  }### Answer:
@Test public void testRenameNonExistingFile() throws IOException { final FileSystem fs = FileSystem.getLocalFileSystem(); final File srcFile = new File(temporaryFolder.newFolder(), "someFile.txt"); final File destFile = new File(temporaryFolder.newFolder(), "target"); final Path srcFilePath = new Path(srcFile.toURI()); final Path destFilePath = new Path(destFile.toURI()); assertFalse(fs.rename(srcFilePath, destFilePath)); }
@Test public void testRenameFileWithNoAccess() throws IOException { final FileSystem fs = FileSystem.getLocalFileSystem(); final File srcFile = temporaryFolder.newFile("someFile.txt"); final File destFile = new File(temporaryFolder.newFolder(), "target"); Assume.assumeTrue(srcFile.getParentFile().setWritable(false, false)); Assume.assumeTrue(srcFile.setWritable(false, false)); try { final Path srcFilePath = new Path(srcFile.toURI()); final Path destFilePath = new Path(destFile.toURI()); assertFalse(fs.rename(srcFilePath, destFilePath)); } finally { srcFile.getParentFile().setWritable(true, false); srcFile.setWritable(true, false); } }