@Override
    public boolean isLeader() {
        return isLeader;
    }
@Test
    void postsEventWhenLeaderChanges() {
        when(lockService.lock(any(), isNull())).thenReturn(Optional.of(mock(Lock.class)));

        leaderElectionService.startAsync().awaitRunning();

        verify(eventBus, timeout(10_000)).post(any(LeaderChangedEvent.class));
        assertThat(leaderElectionService.isLeader()).isTrue();

        when(lockService.lock(any(), isNull())).thenReturn(Optional.empty());
        verify(eventBus, timeout(10_000).times(2)).post(any(LeaderChangedEvent.class));
        assertThat(leaderElectionService.isLeader()).isFalse();
    }