@Test
public void testAppendEntriesWithSameTerm() throws Exception {

  Candidate candidate = new Candidate(mockRaftLog, scheduler, 1, mockRaftClient);
  candidate.init(mockRaftStateContext);
  AppendEntries request =
    AppendEntries.newBuilder()
      .setTerm(2L)
      .setLeaderId("leader:1000")
      .setPrevLogIndex(1L)
      .setPrevLogTerm(1L)
      .setCommitIndex(1L)
      .build();
  candidate.appendEntries(mockRaftStateContext, request);
  verify(mockRaftLog).currentTerm(3L);
  verify(mockRaftLog, times(1)).currentTerm(anyLong());
  verify(mockRaftLog).votedFor(java.util.Optional.of(self));
  verify(mockRaftLog, times(1)).votedFor(any(Optional.class));
  verify(mockRaftLog, times(1)).commitIndex(anyLong());
  verify(mockRaftStateContext).setState(any(Candidate.class), eq(LEADER));
  verifyZeroInteractions(mockRaftClient);
}