ZkBasedTreeNodeResource implements Closeable { @Override public void close() { synchronized (lock) { if (resource != null && cleanup != null) { cleanup.test(resource); } if (treeCache != null) { treeCache.close(); } closed = true; } } private  ZkBasedTreeNodeResource(Builder<T> builder); static Builder<T> newBuilder(); T get(); @Override void close(); boolean isClosed();  }
@Test void testClose() { ZkBasedTreeNodeResource<Map<String, String>> tree = ZkBasedTreeNodeResource .<Map<String, String>> newBuilder() .curator(curatorFramework) .path("/test") .factory(p -> p.entrySet().stream() .collect(toMap(Entry::getKey, e -> new String(e.getValue().getData())))) .build(); System.out.println(tree.get()); tree.close(); assertThrows(IllegalStateException.class, tree::get); }