@Test
public void shouldThrowIllegalArgumentExceptionIfCallerSpecifiesIndexGreaterThanCommitIndexInCallToGetNextCommitted() throws Exception {

    final LogEntry[] entries = new LogEntry[] {
            SENTINEL(),
            NOOP(1, 1),
            CLIENT(2, 1, new UnitTestCommand()),
            CLIENT(3, 1, new UnitTestCommand()), // <-- committed until here
            CLIENT(4, 1, new UnitTestCommand()),
            CLIENT(5, 1, new UnitTestCommand()),
            CLIENT(6, 1, new UnitTestCommand())
    };
    final long currentTerm = 1;
    final long commitIndex = 3;
    // setup the starting state
    insertIntoLog(entries);
    store.setCurrentTerm(currentTerm);
    store.setCommitIndex(commitIndex);
    IllegalArgumentException callException = null;
    try {
        // act as if the caller is specifying a value > commitIndex
        // but check that we aren't accidentally triggering the other bounds check (i.e., that argument <= lastLogIndex)
        long callerLastAppliedCommandIndex = commitIndex + 1;
        assertThat(callerLastAppliedCommandIndex, lessThanOrEqualTo((long) entries.length - 1));
        // make the call
        algorithm.getNextCommitted(callerLastAppliedCommandIndex);
    } catch (IllegalArgumentException e) {
        callException = e;
    }
    assertThat(callException, notNullValue());
    // verify that the state hasn't changed
    assertThatLogContains(entries);
    assertThatTermAndCommitIndexHaveValues(currentTerm, commitIndex);
}