@Override
    public boolean isLeader() {
        return isLeader;
    }
@Test
    void pausesPollingAfterDowngradeFromLeader() {
        final AtomicInteger lockInvocations = new AtomicInteger();
        final AtomicReference<Lock> lock = new AtomicReference<>();

        when(lockService.lock(any(), isNull())).then(i -> {
            lockInvocations.incrementAndGet();
            return Optional.ofNullable(lock.get());
        });

        leaderElectionService.startAsync().awaitRunning();
        lock.set(mock(Lock.class));
        await().until(() -> leaderElectionService.isLeader());

        // polling should continue
        int lockCount = lockInvocations.get();
        Uninterruptibles.sleepUninterruptibly(configuration.getLeaderElectionLockPollingInterval().multipliedBy(2));
        assertThat(lockInvocations.get()).isGreaterThan(lockCount);

        lock.set(null);
        await().until(() -> !leaderElectionService.isLeader());

        // polling should have been paused
        lockCount = lockInvocations.get();
        Uninterruptibles.sleepUninterruptibly(configuration.getLeaderElectionLockPollingInterval().multipliedBy(2));
        assertThat(lockInvocations.get()).isEqualTo(lockCount);
    }