DiskChecker { public static void checkDirs(File dir) throws DiskErrorException { checkDir(dir); IOException ex = null; try (DirectoryStream<java.nio.file.Path> stream = Files.newDirectoryStream(dir.toPath())) { for (java.nio.file.Path entry: stream) { File child = entry.toFile(); if (child.isDirectory()) { checkDirs(child); } } } catch (DirectoryIteratorException de) { ex = de.getCause(); } catch (IOException ie) { ex = ie; } if (ex != null) { throw new DiskErrorException("I/O error when open a directory: " + dir.toString(), ex); } }  static boolean mkdirsWithExistsCheck(File dir); static void checkDirs(File dir); static void checkDir(File dir); static void mkdirsWithExistsAndPermissionCheck(
      LocalFileSystem localFS, Path dir, FsPermission expected); static void checkDir(LocalFileSystem localFS, Path dir,
                              FsPermission expected);  }
@Test (timeout = 30000) public void testCheckDirsIOException() throws Throwable { Path path = new Path("target", TestDiskChecker.class.getSimpleName()); File localDir = new File(path.toUri().getRawPath()); localDir.mkdir(); File localFile = new File(localDir, "test"); localFile.createNewFile(); File spyLocalDir = spy(localDir); doReturn(localFile.toPath()).when(spyLocalDir).toPath(); try { DiskChecker.checkDirs(spyLocalDir); fail("Expected exception for I/O error"); } catch (DiskErrorException e) { GenericTestUtils.assertExceptionContains("I/O error", e); assertTrue(e.getCause() instanceof IOException); } finally { localFile.delete(); localDir.delete(); } }