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

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

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

import java.util.*;

public class AllInvocationsFinder {
    
    /**
     * gets all invocations from mocks. Invocations are ordered earlier first. 
     * 
     * @param mocks mocks
     * @return invocations
     */
    public List find(List mocks) {
        Set invocationsInOrder = new TreeSet(new SequenceNumberComparator());
        for (Object mock : mocks) {
            InternalMockHandler handler = new MockUtil().getMockHandler(mock);
            List fromSingleMock = handler.getInvocationContainer().getInvocations();
            invocationsInOrder.addAll(fromSingleMock);
        }
        
        return new LinkedList(invocationsInOrder);
    }

    private static final class SequenceNumberComparator implements Comparator {
        public int compare(Invocation o1, Invocation o2) {
            return Integer.valueOf(o1.getSequenceNumber()).compareTo(o2.getSequenceNumber());
        }
    }
}