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

com.fitbur.mockito.internal.invocation.UnusedStubsFinder 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.invocation;

import com.fitbur.mockito.internal.InternalMockHandler;
import com.fitbur.mockito.internal.stubbing.StubbedInvocationMatcher;
import com.fitbur.mockito.internal.util.MockUtil;
import com.fitbur.mockito.invocation.Invocation;

import java.util.*;

public class UnusedStubsFinder {

    /**
     * Finds all unused stubs for given mocks
     * 
     * @param mocks
     */
    public List find(List mocks) {
        List unused = new LinkedList();
        for (Object mock : mocks) {
            InternalMockHandler handler = new MockUtil().getMockHandler(mock);
            List fromSingleMock = handler.getInvocationContainer().getStubbedInvocations();
            for(StubbedInvocationMatcher s : fromSingleMock) {
                if (!s.wasUsed()) {
                     unused.add(s.getInvocation());
                }
            }
        }
        return unused;
    }
}