org.mockito.internal.matchers.And Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mockito-core Show documentation
Show all versions of mockito-core Show documentation
Mock objects library for java
/*
* 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();
}
}