class ZkBasedTreeNodeResource implements Closeable {

    @Override
    public void close() {
        synchronized (lock) {
            if (resource != null && cleanup != null) {
                cleanup.test(resource);
            }
            if (treeCache != null) {
                treeCache.close();
            }
            closed = true;
        }
    }

}

class ZkBasedTreeNodeResourceTest  {

    private static final Logger logger;

    @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);
    }

}