### Question:
ZKUtil { public static String validateFileInput(String filePath) { File file = new File(filePath); if (!file.exists()) { return "File '" + file.getAbsolutePath() + "' does not exist."; } if (!file.canRead()) { return "Read permission is denied on the file '" + file.getAbsolutePath() + "'"; } if (file.isDirectory()) { return "'" + file.getAbsolutePath() + "' is a direcory. it must be a file."; } return null; }  static boolean deleteRecursive(
        ZooKeeper zk,
        final String pathRoot,
        final int batchSize); static void deleteRecursive(
        ZooKeeper zk,
        final String pathRoot); static void deleteRecursive(
        ZooKeeper zk,
        final String pathRoot,
        VoidCallback cb,
        Object ctx); static String validateFileInput(String filePath); static List<String> listSubTreeBFS(
        ZooKeeper zk,
        final String pathRoot); static void visitSubTreeDFS(
        ZooKeeper zk,
        final String path,
        boolean watch,
        StringCallback cb); static String getPermString(int perms); static String aclToString(List<ACL> acls);  }### Answer:
@Test public void testValidateFileInput() throws IOException { File file = File.createTempFile("test", ".junit", testData); file.deleteOnExit(); String absolutePath = file.getAbsolutePath(); String error = ZKUtil.validateFileInput(absolutePath); assertNull(error); }
@Test public void testValidateFileInputNotExist() { String fileName = UUID.randomUUID().toString(); File file = new File(testData, fileName); String absolutePath = file.getAbsolutePath(); String error = ZKUtil.validateFileInput(absolutePath); assertNotNull(error); String expectedMessage = "File '" + absolutePath + "' does not exist."; assertEquals(expectedMessage, error); }
@Test public void testValidateFileInputDirectory() throws Exception { File file = File.createTempFile("test", ".junit", testData); file.deleteOnExit(); file.delete(); file.mkdir(); String absolutePath = file.getAbsolutePath(); String error = ZKUtil.validateFileInput(absolutePath); assertNotNull(error); String expectedMessage = "'" + absolutePath + "' is a direcory. it must be a file."; assertEquals(expectedMessage, error); }
@Test public void testUnreadableFileInput() throws Exception { assumeTrue(!org.apache.zookeeper.Shell.WINDOWS); File file = File.createTempFile("test", ".junit", testData); file.setReadable(false, false); file.deleteOnExit(); String absolutePath = file.getAbsolutePath(); String error = ZKUtil.validateFileInput(absolutePath); assertNotNull(error); String expectedMessage = "Read permission is denied on the file '" + absolutePath + "'"; assertEquals(expectedMessage, error); }