@Test
public void shouldReturnSnapshotInResponseToRepeatedGetNextCommittedCallsWithInitialIndexToSearchFromAsZero() throws Exception {

    // we have a snapshot that contains data to index 6 (inclusive)
    int lastAppliedTerm = 2;
    long lastAppliedIndex = 6;
    SnapshotsStore.ExtendedSnapshot storedSnapshot = new UnitTestSnapshot(lastAppliedIndex, lastAppliedTerm);
    // our log is empty
    clearLog(); // clear out the log completely - we don't even want the sentinel
    // set the committed index
    store.setCommitIndex(lastAppliedIndex);
    // set the current term
    // this has to be >= the term in the snapshot
    store.setCurrentTerm(lastAppliedTerm);
    // have the snapshot store return the snapshot
    when(snapshotsStore.getLatestSnapshot()).thenReturn(storedSnapshot);
    //
    // situation is as follows:
    //
    //                   +----------- COMMITTED = 6
    //                   V
    //   ---------------------
    //  | LAST APPLIED = 6   | (SNAPSHOT)
    //  ---------------------
    //   ^
    //   +----------- INDEX TO SEARCH FROM = 0
    //
    Committed committed;
    // OK, now, let's start by saying that the last index we applied was '0' (IOW, we have no state and have to start from scratch)
    // we should get the snapshot back
    committed = algorithm.getNextCommitted(0);
    checkMatchingSnapshot(committed, storedSnapshot);
    // if we make a second call we should get nothing
    committed = algorithm.getNextCommitted(committed.getIndex()); // index = 7
    assertThat(committed, nullValue());
    // algorithm should have exactly the same state at the end
    assertThatLogIsEmpty();
    assertThatTermAndCommitIndexHaveValues(lastAppliedTerm, lastAppliedIndex);
}