AsyncHealthCheckDecorator extends HealthCheck implements Runnable { boolean tearDown() { return future.cancel(true); } AsyncHealthCheckDecorator(HealthCheck healthCheck, ScheduledExecutorService executorService, Clock clock);   AsyncHealthCheckDecorator(HealthCheck healthCheck, ScheduledExecutorService executorService); @Override void run(); HealthCheck getHealthCheck();  }
@Test @SuppressWarnings("unchecked") public void tearDownTriggersCancellation() throws Exception { when(mockExecutorService.scheduleAtFixedRate(any(Runnable.class), eq(0L), eq(1L), eq(TimeUnit.SECONDS))). thenReturn(mockFuture); when(mockFuture.cancel(true)).thenReturn(true); AsyncHealthCheckDecorator asyncDecorator = new AsyncHealthCheckDecorator(new DefaultAsyncHealthCheck(), mockExecutorService); asyncDecorator.tearDown(); verify(mockExecutorService, times(1)).scheduleAtFixedRate(any(Runnable.class), eq(0L), eq(1L), eq(TimeUnit.SECONDS)); verify(mockFuture, times(1)).cancel(eq(true)); }