@Test
public void testLeaveIfNotLeader() throws Exception {

    ZookeeperLeaderElector firstElector = newZookeeperLeaderElector();
    ZookeeperLeaderElector secondElector = newZookeeperLeaderElector();
    // Make the first elector a leader.
    assertThat(firstElector.join()).isTrue();
    awaitLeaderActivation();
    assertThat(firstElector.leaveIfNotLeader()).isFalse();
    // Check that second elector can join and leave the leader election process.
    assertThat(secondElector.join()).isTrue();
    assertThat(secondElector.leaveIfNotLeader()).isTrue();
}