@Test
  public void destroyAutoBalancer() throws InterruptedException {
    final int timer = 20; // simulate 20 milliseconds
    final CountDownLatch latch = new CountDownLatch(2);
    final CountDownLatch timerLatch = new CountDownLatch(1);
    when(mockClock.currentTimeMillis()).then((invocation) -> {
      latch.countDown();
      if (latch.getCount() == 0) {
        assertThat(timerLatch.await(1, TimeUnit.SECONDS)).isTrue();
        // scheduler is destroyed before wait is over
        // fail();
        throw new AssertionError();
      }
      return 1000L - timer;
    });

    Properties props = AutoBalancerJUnitTest.getBasicConfig();
    assertThat(latch.getCount()).isEqualTo(2);
    AutoBalancer autoR = new AutoBalancer(null, mockAuditor, mockClock, null);
    autoR.initialize(null, props);
    assertThat(latch.await(1, TimeUnit.MINUTES)).isTrue();
    verify(mockAuditor, times(1)).init(any(Properties.class));

    // after destroy no more execute will be called.
    autoR.destroy();
    timerLatch.countDown();
    TimeUnit.MILLISECONDS.sleep(2 * timer);
  }
UnitTests for AutoBalancer. All collaborators should be mocked.
geode-rebalancer/src/test/java/org/apache/geode/cache/util/AutoBalancerJUnitTest.java