1/*
2 * Copyright (c) 2007 Mockito contributors
3 * This program is made available under the terms of the MIT License.
4 */
5
6package org.mockito.internal.matchers;
7
8import java.io.Serializable;
9import java.util.Iterator;
10import java.util.List;
11
12import org.hamcrest.Description;
13import org.hamcrest.Matcher;
14import org.mockito.ArgumentMatcher;
15
16@SuppressWarnings("unchecked")
17public class And extends ArgumentMatcher implements Serializable {
18
19    private static final long serialVersionUID = -4624719625691177501L;
20    private final List<Matcher> matchers;
21
22    public And(List<Matcher> matchers) {
23        this.matchers = matchers;
24    }
25
26    public boolean matches(Object actual) {
27        for (Matcher matcher : matchers) {
28            if (!matcher.matches(actual)) {
29                return false;
30            }
31        }
32        return true;
33    }
34
35    public void describeTo(Description description) {
36        description.appendText("and(");
37        for (Iterator<Matcher> it = matchers.iterator(); it.hasNext();) {
38            it.next().describeTo(description);
39            if (it.hasNext()) {
40                description.appendText(", ");
41            }
42        }
43        description.appendText(")");
44    }
45}
46