@Test
public void testAppendEntriesWithOlderTerm() throws Exception {

  Candidate candidate = new Candidate(mockRaftLog, scheduler, 1, mockRaftClient);
  candidate.init(mockRaftStateContext);
  Replica mockLeader = config.getReplica("other");
  AppendEntries request =
    AppendEntries.newBuilder()
      .setTerm(1L)
      .setLeaderId(mockLeader.toString())
      .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, never()).commitIndex(anyLong());
  verify(mockRaftStateContext).setState(any(Candidate.class), eq(Raft.StateType.LEADER));
  verifyZeroInteractions(mockRaftClient);
}