### Question:
ChRootedFs extends AbstractFileSystem { @Override public void mkdir(final Path dir, final FsPermission permission, final boolean createParent) throws IOException, UnresolvedLinkException { myFs.mkdir(fullPath(dir), permission, createParent); } ChRootedFs(final AbstractFileSystem fs, final Path theRoot); @Override URI getUri(); String stripOutRoot(final Path p); @Override Path getHomeDirectory(); @Override Path getInitialWorkingDirectory(); Path getResolvedQualifiedPath(final Path f); @Override FSDataOutputStream createInternal(final Path f,
      final EnumSet<CreateFlag> flag, final FsPermission absolutePermission,
      final int bufferSize, final short replication, final long blockSize,
      final Progressable progress, final ChecksumOpt checksumOpt,
      final boolean createParent); @Override boolean delete(final Path f, final boolean recursive); @Override BlockLocation[] getFileBlockLocations(final Path f, final long start,
      final long len); @Override FileChecksum getFileChecksum(final Path f); @Override FileStatus getFileStatus(final Path f); @Override FileStatus getFileLinkStatus(final Path f); @Override FsStatus getFsStatus(); @Override FsServerDefaults getServerDefaults(); @Override int getUriDefaultPort(); @Override FileStatus[] listStatus(final Path f); @Override void mkdir(final Path dir, final FsPermission permission,
      final boolean createParent); @Override FSDataInputStream open(final Path f, final int bufferSize); @Override void renameInternal(final Path src, final Path dst); @Override void renameInternal(final Path src, final Path dst, 
      final boolean overwrite); @Override void setOwner(final Path f, final String username,
      final String groupname); @Override void setPermission(final Path f, final FsPermission permission); @Override boolean setReplication(final Path f, final short replication); @Override void setTimes(final Path f, final long mtime, final long atime); @Override void setVerifyChecksum(final boolean verifyChecksum); @Override boolean supportsSymlinks(); @Override void createSymlink(final Path target, final Path link,
      final boolean createParent); @Override Path getLinkTarget(final Path f); @Override List<Token<?>> getDelegationTokens(String renewer);  }### Answer:
@Test public void testRename() throws IOException { FileContextTestHelper.createFile(fc, "/newDir/foo"); fc.rename(new Path("/newDir/foo"), new Path("/newDir/fooBar")); Assert.assertFalse(exists(fc, new Path("/newDir/foo"))); Assert.assertFalse(exists(fcTarget, new Path(chrootedTo,"newDir/foo"))); Assert.assertTrue(isFile(fc, FileContextTestHelper.getTestRootPath(fc,"/newDir/fooBar"))); Assert.assertTrue(isFile(fcTarget, new Path(chrootedTo,"newDir/fooBar"))); fc.mkdir(new Path("/newDir/dirFoo"), FileContext.DEFAULT_PERM, false); fc.rename(new Path("/newDir/dirFoo"), new Path("/newDir/dirFooBar")); Assert.assertFalse(exists(fc, new Path("/newDir/dirFoo"))); Assert.assertFalse(exists(fcTarget, new Path(chrootedTo,"newDir/dirFoo"))); Assert.assertTrue(isDir(fc, FileContextTestHelper.getTestRootPath(fc,"/newDir/dirFooBar"))); Assert.assertTrue(isDir(fcTarget, new Path(chrootedTo,"newDir/dirFooBar"))); }
@Test public void testRenameAcrossFs() throws IOException { fc.mkdir(new Path("/newDir/dirFoo"), FileContext.DEFAULT_PERM, true); fc.rename(new Path("/newDir/dirFoo"), new Path("file: FileContextTestHelper.isDir(fc, new Path("/dirFooBar")); }