Package org.jmock.dynamic

Source Code of org.jmock.dynamic.LIFOInvocationDispatcher

/* Copyright (c) 2000-2003, jMock.org. See bundled LICENSE.txt */
package org.jmock.dynamic;

import org.jmock.expectation.Verifiable;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.ListIterator;

public class LIFOInvocationDispatcher implements InvocationDispatcher {

    private ArrayList invokables = new ArrayList();

    public Object dispatch(Invocation invocation) throws Throwable {
        ListIterator i = invokables.listIterator(invokables.size());
        while (i.hasPrevious()) {
            Invokable invokable = (Invokable) i.previous();
            if (invokable.matches(invocation)) {
                return invokable.invoke(invocation);
            }
        }
        throw new DynamicMockError(invocation, "No match found");
    }

    public void add(Invokable invokable) {
        invokables.add(invokable);
    }

    public void verify() {
        Iterator i = invokables.iterator();
        while (i.hasNext()) {
            ((Verifiable) i.next()).verify();
        }
    }

    public void clear() {
        invokables.clear();
    }

}
TOP

Related Classes of org.jmock.dynamic.LIFOInvocationDispatcher

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.