ActiveInstanceElectorService implements Service, LeaderLatchListener { @Override public void isLeader() { LOG.warn("Server instance with server id {} is elected as leader", serverId); serviceState.becomingActive(); try { for (ActiveStateChangeHandler handler : activeStateChangeHandlers) { handler.instanceIsActive(); } activeInstanceState.update(serverId); serviceState.setActive(); } catch (Exception e) { LOG.error("Got exception while activating", e); notLeader(); rejoinElection(); } } @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 testActiveStateSetOnBecomingLeader() { ActiveInstanceElectorService activeInstanceElectorService = new ActiveInstanceElectorService(configuration, new HashSet<ActiveStateChangeHandler>(), curatorFactory, activeInstanceState, serviceState); activeInstanceElectorService.isLeader(); InOrder inOrder = inOrder(serviceState); inOrder.verify(serviceState).becomingActive(); inOrder.verify(serviceState).setActive(); }