All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.fitbur.mockito.internal.verification.checkers.NonGreedyNumberOfInvocationsInOrderChecker Maven / Gradle / Ivy

There is a newer version: 1.0.0
Show newest version
/*
 * Copyright (c) 2007 Mockito contributors
 * This program is made available under the terms of the MIT License.
 */

package com.fitbur.mockito.internal.verification.checkers;

import static com.fitbur.mockito.exceptions.Reporter.tooLittleActualInvocationsInOrder;
import static com.fitbur.mockito.internal.invocation.InvocationMarker.markVerified;

import java.util.List;

import com.fitbur.mockito.internal.invocation.InvocationMatcher;
import com.fitbur.mockito.internal.invocation.InvocationsFinder;
import com.fitbur.mockito.internal.reporting.Discrepancy;
import com.fitbur.mockito.internal.verification.api.InOrderContext;
import com.fitbur.mockito.invocation.Invocation;
import com.fitbur.mockito.invocation.Location;

public class NonGreedyNumberOfInvocationsInOrderChecker {

    private final InvocationsFinder finder;

    public NonGreedyNumberOfInvocationsInOrderChecker() {
        this(new InvocationsFinder());
    }

    NonGreedyNumberOfInvocationsInOrderChecker(InvocationsFinder finder ) {
        this.finder = finder;
    }
    
    public void check(List invocations, InvocationMatcher wanted, int wantedCount, InOrderContext context) {
        int actualCount = 0;
        Location lastLocation = null;
        while( actualCount < wantedCount ){
            Invocation next = finder.findFirstMatchingUnverifiedInvocation( invocations, wanted, context );
            if( next == null ){
                throw tooLittleActualInvocationsInOrder(new Discrepancy(wantedCount, actualCount), wanted, lastLocation );
            }
            markVerified( next, wanted );
            context.markVerified( next );
            lastLocation = next.getLocation();
            actualCount++;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy