public static List<Invocation> findMatchingChunk(List<Invocation> invocations, MatchableInvocation wanted, int wantedCount, InOrderContext context) {
        List<Invocation> unverified = removeVerifiedInOrder(invocations, context);
        List<Invocation> firstChunk = getFirstMatchingChunk(wanted, unverified);

        if (wantedCount != firstChunk.size()) {
            return findAllMatchingUnverifiedChunks(invocations, wanted, context);
        } else {
            return firstChunk;
        }
    }
public static List < Invocation > findMatchingChunk ( List < Invocation > invocations , MatchableInvocation wanted , int wantedCount , InOrderContext context ) { List < Invocation > unverified = removeVerifiedInOrder ( invocations , context ) ; List < Invocation > firstChunk = getFirstMatchingChunk ( wanted , unverified ) ; if ( wantedCount != firstChunk . size ( ) ) { return findAllMatchingUnverifiedChunks ( invocations , wanted , context ) ; } else { return firstChunk ; } }
some examples how it works:

Given invocations sequence:
1,1,2,1

if wanted is 1 and mode is times(2) then returns
1,1

if wanted is 1 and mode is atLeast() then returns
1,1,1

if wanted is 1 and mode is times(x), where x != 2 then returns
1,1,1