@Override
    public void discardState() throws Exception {
        final FileSystem fs = getFileSystem();

        IOException actualException = null;
        boolean success = true;
        try {
            success = fs.delete(filePath, false);
        } catch (IOException e) {
            actualException = e;
        }

        if (!success || actualException != null) {
            if (fs.exists(filePath)) {
                throw Optional.ofNullable(actualException)
                        .orElse(
                                new IOException(
                                        "Unknown error caused the file '"
                                                + filePath
                                                + "' to not be deleted."));
            }
        }
    }
@Test
    void testDisposeDoesNotDeleteParentDirectory() throws Exception {
        final Path p = resolve("path", "with", "parent");
        final List<Path> pathsToDelete = new ArrayList<>();

        initializeFileSystem(
                MockedLocalFileSystem.newBuilder()
                        .setDeleteFunction(
                                (path, ignoredRecursionMarker) -> {
                                    pathsToDelete.add(path);
                                    return true;
                                })
                        .build());

        final FileStateHandle handle = new FileStateHandle(p, 42);
        handle.discardState();
        assertThat(pathsToDelete)
                .as(
                        "Only one delete call should have happened on the actual path but not the parent.")
                .singleElement()
                .isEqualTo(p);
    }