AsyncCloseableSupport implements ListenableAsyncCloseable { public static AsyncCloseableSupport of() { return of(f -> f.complete(null)); } private  AsyncCloseableSupport(Consumer<CompletableFuture<?>> closeAction); static AsyncCloseableSupport of(); static AsyncCloseableSupport of(Consumer<CompletableFuture<?>> closeAction); static AsyncCloseableSupport closed(); @Override boolean isClosing(); @Override boolean isClosed(); @Override CompletableFuture<?> closeAsync(); @Override void close(); @Override CompletableFuture<?> whenClosed();  }
@Test void closeActionCompletedExceptionally() { final AsyncCloseableSupport support = AsyncCloseableSupport.of(f -> { f.completeExceptionally(new AnticipatedException()); }); assertThatThrownBy(support::close).isInstanceOf(CompletionException.class) .hasCauseInstanceOf(AnticipatedException.class); }
@Test void closeActionFailed() { final AsyncCloseableSupport support = AsyncCloseableSupport.of(f -> { throw new AnticipatedException(); }); assertThatThrownBy(support::close).isInstanceOf(CompletionException.class) .hasCauseInstanceOf(AnticipatedException.class); }