### Question:
SnapshotDirectory { @Nullable public abstract DirectoryStateHandle completeSnapshotAndGetHandle() throws IOException; private  SnapshotDirectory(@Nonnull Path directory, @Nonnull FileSystem fileSystem); private  SnapshotDirectory(@Nonnull Path directory); @Nonnull Path getDirectory(); boolean mkdirs(); @Nonnull FileSystem getFileSystem(); boolean exists(); FileStatus[] listStatus(); boolean cleanup(); boolean isSnapshotCompleted(); @Nullable abstract DirectoryStateHandle completeSnapshotAndGetHandle(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); static SnapshotDirectory temporary(@Nonnull Path directory); static SnapshotDirectory permanent(@Nonnull Path directory);  }### Answer:
@Test public void completeSnapshotAndGetHandle() throws Exception { File folderRoot = temporaryFolder.getRoot(); File folderA = new File(folderRoot, String.valueOf(UUID.randomUUID())); Assert.assertTrue(folderA.mkdirs()); Path folderAPath = new Path(folderA.toURI()); SnapshotDirectory snapshotDirectory = SnapshotDirectory.permanent(folderAPath); DirectoryStateHandle handle = snapshotDirectory.completeSnapshotAndGetHandle(); Assert.assertNotNull(handle); Assert.assertTrue(snapshotDirectory.cleanup()); Assert.assertTrue(folderA.isDirectory()); Assert.assertEquals(folderAPath, handle.getDirectory()); handle.discardState(); Assert.assertFalse(folderA.isDirectory()); Assert.assertTrue(folderA.mkdirs()); snapshotDirectory = SnapshotDirectory.permanent(folderAPath); Assert.assertTrue(snapshotDirectory.cleanup()); try { snapshotDirectory.completeSnapshotAndGetHandle(); Assert.fail(); } catch (IOException ignore) { } }