ActiveInstanceElectorService implements Service, LeaderLatchListener { @Override public void stop() { if (!HAConfiguration.isHAEnabled(configuration)) { LOG.info("HA is not enabled, no need to stop leader election service"); return; } try { leaderLatch.close(); curatorFactory.close(); } catch (IOException e) { LOG.error("Error closing leader latch", e); } } @Inject  ActiveInstanceElectorService(Configuration configuration,
                                 Set<ActiveStateChangeHandler> activeStateChangeHandlerProviders,
                                 CuratorFactory curatorFactory, ActiveInstanceState activeInstanceState,
                                 ServiceState serviceState); @Override void start(); @Override void stop(); @Override void isLeader(); @Override void notLeader();  }
@Test public void testNoActionOnStopIfHAModeIsDisabled() { when(configuration.getBoolean(HAConfiguration.ATLAS_SERVER_HA_ENABLED_KEY, false)).thenReturn(false); ActiveInstanceElectorService activeInstanceElectorService = new ActiveInstanceElectorService(configuration, new HashSet<ActiveStateChangeHandler>(), curatorFactory, activeInstanceState, serviceState); activeInstanceElectorService.stop(); verifyZeroInteractions(curatorFactory); }