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

com.fitbur.mockito.internal.verification.checkers.MissingInvocationInOrderChecker 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.argumentsAreDifferent;
import static com.fitbur.mockito.exceptions.Reporter.wantedButNotInvoked;
import static com.fitbur.mockito.exceptions.Reporter.wantedButNotInvokedInOrder;

import java.util.List;

import com.fitbur.mockito.exceptions.Reporter;
import com.fitbur.mockito.internal.invocation.InvocationMatcher;
import com.fitbur.mockito.internal.invocation.InvocationsFinder;
import com.fitbur.mockito.internal.reporting.SmartPrinter;
import com.fitbur.mockito.internal.verification.api.InOrderContext;
import com.fitbur.mockito.internal.verification.argumentmatching.ArgumentMatchingTool;
import com.fitbur.mockito.invocation.Invocation;
import com.fitbur.mockito.verification.VerificationMode;

public class MissingInvocationInOrderChecker {
    
    private final InvocationsFinder finder=new InvocationsFinder();
    
    public void check(List invocations, InvocationMatcher wanted, VerificationMode mode, InOrderContext context) {
        List chunk = finder.findAllMatchingUnverifiedChunks(invocations, wanted, context);
        
        if (!chunk.isEmpty()) {
            return;
        }
        
        Invocation previousInOrder = finder.findPreviousVerifiedInOrder(invocations, context);
        if (previousInOrder == null) {
            /**
             * It is of course possible to have an issue where the arguments are different
             * rather that not invoked in order. Issue related to
             * http://code.google.com/p/mockito/issues/detail?id=27. If the previous order
             * is missing, then this method checks if the arguments are different or if the order
             * is not invoked.
             */
             List actualInvocations = finder.findInvocations(invocations, wanted);
             if (actualInvocations == null || actualInvocations.isEmpty())  {
                 Invocation similar = finder.findSimilarInvocation(invocations, wanted);
                 if (similar != null) {
                     Integer[] indicesOfSimilarMatchingArguments =
                             new ArgumentMatchingTool().getSuspiciouslyNotMatchingArgsIndexes(wanted.getMatchers(),
                                     similar.getArguments());
                     SmartPrinter smartPrinter = new SmartPrinter(wanted, similar, indicesOfSimilarMatchingArguments);
                     throw argumentsAreDifferent(smartPrinter.getWanted(), smartPrinter.getActual(), similar.getLocation());
                 } 
                 throw wantedButNotInvoked(wanted);
                 
             }
        } else {
            throw wantedButNotInvokedInOrder(wanted, previousInOrder);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy