public static void delete(final File file, final boolean ignoreFailures)
    {
        if (file.exists())
        {
            if (file.isDirectory())
            {
                final File[] files = file.listFiles();
                if (null != files)
                {
                    for (final File f : files)
                    {
                        delete(f, ignoreFailures);
                    }
                }
            }

            if (!file.delete() && !ignoreFailures)
            {
                try
                {
                    Files.delete(file.toPath());
                }
                catch (final IOException ex)
                {
                    LangUtil.rethrowUnchecked(ex);
                }
            }
        }
    }
@Test
    void deleteErrorHandlerDirectory() throws IOException
    {
        final ErrorHandler errorHandler = mock(ErrorHandler.class);
        final Path dir2 = tempDir.resolve("dir1").resolve("dir2");
        Files.createDirectories(dir2);
        Files.createFile(dir2.resolve("file2.txt"));
        Files.createFile(dir2.getParent().resolve("file1.txt"));
        final File dir = dir2.getParent().toFile();

        IoUtil.delete(dir, errorHandler);

        assertFalse(dir.exists());
        assertFalse(Files.exists(dir2));
        verifyNoInteractions(errorHandler);
    }