LeaderContext implements Context { @Override public boolean isLeader() { return this.leadershipController.getLocalLeader().filter(l -> l.isCandidate(this.candidate)).isPresent(); } LeaderContext(Candidate candidate, LeadershipController leadershipController); @Override boolean isLeader(); @Override void yield();  }
@Test public void testIsLeaderWithoutLeader() { given(this.mockLeadershipController.getLocalLeader()).willReturn(Optional.empty()); boolean result = this.leaderContext.isLeader(); assertThat(result).isFalse(); }
@Test public void testIsLeaderWithAnotherLeader() { given(this.mockLeadershipController.getLocalLeader()).willReturn(Optional.of(this.mockLeader)); boolean result = this.leaderContext.isLeader(); assertThat(result).isFalse(); }
@Test public void testIsLeaderWhenLeader() { given(this.mockLeadershipController.getLocalLeader()).willReturn(Optional.of(this.mockLeader)); given(this.mockLeader.isCandidate(this.mockCandidate)).willReturn(true); boolean result = this.leaderContext.isLeader(); assertThat(result).isTrue(); }