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

com.fitbur.mockito.internal.matchers.CapturingMatcher 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.matchers;

import com.fitbur.mockito.ArgumentMatcher;
import com.fitbur.mockito.exceptions.Reporter;

import static com.fitbur.mockito.exceptions.Reporter.noArgumentValueWasCaptured;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;

@SuppressWarnings("unchecked")
public class CapturingMatcher implements ArgumentMatcher, CapturesArguments, VarargMatcher, Serializable {
    
    private final LinkedList arguments = new LinkedList();

    public boolean matches(Object argument) {
        return true;
    }    

    public String toString() {
        return "";
    }

    public T getLastValue() {
        if (arguments.isEmpty()) {
            throw noArgumentValueWasCaptured();
        }
        
        return (T) arguments.getLast();
        
    }

    public List getAllValues() {
        return (List) arguments;
    }

    public void captureFrom(Object argument) {
        this.arguments.add(argument);
    }
}