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

org.mockito.internal.invocation.UnusedStubsFinder Maven / Gradle / Ivy

There is a newer version: 2.0.2-beta
Show newest version
/*
 * Copyright (c) 2007 Mockito contributors
 * This program is made available under the terms of the MIT License.
 */
package org.mockito.internal.invocation;

import org.mockito.internal.MockHandlerInterface;
import org.mockito.internal.stubbing.StubbedInvocationMatcher;
import org.mockito.internal.util.MockUtil;

import java.util.*;

public class UnusedStubsFinder {

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