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

com.fitbur.mockito.internal.verification.checkers.MissingInvocationChecker 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 java.util.List;

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.argumentmatching.ArgumentMatchingTool;
import com.fitbur.mockito.invocation.Invocation;

public class MissingInvocationChecker {
    
    private final InvocationsFinder finder;
    
    public MissingInvocationChecker() {
        this(new InvocationsFinder());
    }
    
    MissingInvocationChecker(InvocationsFinder finder) {
        this.finder = finder;
    }
    
    public void check(List invocations, InvocationMatcher wanted) {
        List actualInvocations = finder.findInvocations(invocations, wanted);
        
        if (actualInvocations.isEmpty()) {
            Invocation similar = finder.findSimilarInvocation(invocations, wanted);
            if (similar != null) {
                ArgumentMatchingTool argumentMatchingTool = new ArgumentMatchingTool();
                Integer[] indexesOfSuspiciousArgs = argumentMatchingTool.getSuspiciouslyNotMatchingArgsIndexes(wanted.getMatchers(), similar.getArguments());
                SmartPrinter smartPrinter = new SmartPrinter(wanted, similar, indexesOfSuspiciousArgs);
                throw argumentsAreDifferent(smartPrinter.getWanted(), smartPrinter.getActual(), similar.getLocation());
            } 
            
            throw wantedButNotInvoked(wanted, invocations);
            
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy