@Test
void testTakeLeadershipInterrupted() throws Exception {

    ZookeeperConfiguration zookeeperConfiguration =
        new ZookeeperConfiguration("connection-string", "/leader-selector-path", null, null);
    List<MonitorConfiguration> monitors = new ArrayList<>();
    Map<String, Object> settings = new HashMap<>();
    settings.put("constructorShouldThrowException", "false");
    settings.put("shouldCauseInterrupt", "false");
    monitors.add(
        new MonitorConfiguration(
            "com.microsoft.azure.practices.nvadaemon.NvaMonitorTest$MonitorValidConstructor",
            settings));
    DaemonConfiguration daemonConfiguration = new DaemonConfiguration(monitors, null);
    NvaDaemonConfiguration nvaDaemonConfiguration = new NvaDaemonConfiguration(
        zookeeperConfiguration, daemonConfiguration);
    CuratorFramework curatorFramework = mock(CuratorFramework.class);
    NvaLeaderSelectorListenerAdapter nvaLeaderSelectorListenerAdapter =
        new NvaLeaderSelectorListenerAdapter(nvaDaemonConfiguration, curatorFramework);
    AtomicReference<Thread> thread = new AtomicReference<>();
    ExecutorService executorService = Executors.newSingleThreadExecutor();
    Future<Void> task = executorService.submit(
        () -> {
            thread.set(Thread.currentThread());
            nvaLeaderSelectorListenerAdapter.takeLeadership(curatorFramework);
            return null;
        });
    Thread.sleep(3000);
    thread.get().interrupt();
      Assertions.assertThrows(IllegalStateException.class,
          () -> nvaLeaderSelectorListenerAdapter.close());
    task.get();
      Assertions.assertThrows(ExecutionException.class,
          () -> nvaLeaderSelectorListenerAdapter.takeLeadership(curatorFramework));
}