### Question:
NativeIO { public static void renameTo(File src, File dst) throws IOException { if (!nativeLoaded) { if (!src.renameTo(dst)) { throw new IOException("renameTo(src=" + src + ", dst=" + dst + ") failed."); } } else { renameTo0(src.getAbsolutePath(), dst.getAbsolutePath()); } }  static boolean isAvailable(); static native FileDescriptor open(String path, int flags, int mode); static native void chmod(String path, int mode); static void posixFadviseIfPossible(
      FileDescriptor fd, long offset, long len, int flags); static void syncFileRangeIfPossible(
      FileDescriptor fd, long offset, long nbytes, int flags); static Stat getFstat(FileDescriptor fd); static void renameTo(File src, File dst); static final int O_RDONLY; static final int O_WRONLY; static final int O_RDWR; static final int O_CREAT; static final int O_EXCL; static final int O_NOCTTY; static final int O_TRUNC; static final int O_APPEND; static final int O_NONBLOCK; static final int O_SYNC; static final int O_ASYNC; static final int O_FSYNC; static final int O_NDELAY; static final int POSIX_FADV_NORMAL; static final int POSIX_FADV_RANDOM; static final int POSIX_FADV_SEQUENTIAL; static final int POSIX_FADV_WILLNEED; static final int POSIX_FADV_DONTNEED; static final int POSIX_FADV_NOREUSE; static final int SYNC_FILE_RANGE_WAIT_BEFORE; static final int SYNC_FILE_RANGE_WRITE; static final int SYNC_FILE_RANGE_WAIT_AFTER; }### Answer:
@Test public void testRenameTo() throws Exception { final File TEST_DIR = new File(new File( System.getProperty("test.build.data","build/test/data")), "renameTest"); assumeTrue(TEST_DIR.mkdirs()); File nonExistentFile = new File(TEST_DIR, "nonexistent"); File targetFile = new File(TEST_DIR, "target"); try { NativeIO.renameTo(nonExistentFile, targetFile); Assert.fail(); } catch (NativeIOException e) { Assert.assertEquals(e.getErrno(), Errno.ENOENT); } File sourceFile = new File(TEST_DIR, "source"); Assert.assertTrue(sourceFile.createNewFile()); NativeIO.renameTo(sourceFile, sourceFile); NativeIO.renameTo(sourceFile, targetFile); sourceFile = new File(TEST_DIR, "source"); Assert.assertTrue(sourceFile.createNewFile()); File badTarget = new File(targetFile, "subdir"); try { NativeIO.renameTo(sourceFile, badTarget); Assert.fail(); } catch (NativeIOException e) { Assert.assertEquals(e.getErrno(), Errno.ENOTDIR); } FileUtils.deleteQuietly(TEST_DIR); }