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

org.mockito.internal.matchers.And Maven / Gradle / Ivy

There is a newer version: 5.12.0
Show newest version
/*
 * Copyright (c) 2007 Mockito contributors
 * This program is made available under the terms of the MIT License.
 */

package org.mockito.internal.matchers;

import org.mockito.ArgumentMatcher;

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

@SuppressWarnings("unchecked")
public class And implements ArgumentMatcher, Serializable {

    private final List matchers;

    public And(List matchers) {
        this.matchers = matchers;
    }

    public boolean matches(Object actual) {
        for (ArgumentMatcher matcher : matchers) {
            if (!matcher.matches(actual)) {
                return false;
            }
        }
        return true;
    }

    public String toString() {
        StringBuilder out = new StringBuilder();
        out.append("and(");
        for (Iterator it = matchers.iterator(); it.hasNext();) {
            out.append(it.next().toString());
            if (it.hasNext()) {
                out.append(", ");
            }
        }
        out.append(")");
        return out.toString();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy