@Test
public void shouldThrowIllegalArgumentExceptionIfCallerSpecifiesIndexGreaterThanLastAppliedIndexInSnapshotInCallToGetNextCommitted() throws Exception {

    // we have a snapshot that contains data to index 6 (inclusive)
    long lastAppliedIndex = 6;
    SnapshotsStore.ExtendedSnapshot storedSnapshot = new UnitTestSnapshot(lastAppliedIndex, 2);
    // our log is empty
    clearLog(); // clear out the log completely - we don't even want the sentinel
    // set the term
    long currentTerm = 2;
    store.setCurrentTerm(currentTerm); // has to be >= snapshot term
    // set the committed index
    store.setCommitIndex(lastAppliedIndex);
    // 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 = 7
    //
    IllegalArgumentException callException = null;
    try {
        algorithm.getNextCommitted(lastAppliedIndex + 1); // the caller is acting as if it got some entry after the end of the snapshot
    } catch (IllegalArgumentException e) {
        callException = e;
    }
    assertThat(callException, notNullValue());
    // verify that the state hasn't changed
    assertThatLogIsEmpty();
    assertThatTermAndCommitIndexHaveValues(currentTerm, lastAppliedIndex);
}