Home | History | Annotate | Download | only in matchers
      1 /*
      2  * Copyright (c) 2007 Mockito contributors
      3  * This program is made available under the terms of the MIT License.
      4  */
      5 
      6 package org.mockito.internal.matchers;
      7 
      8 import java.io.Serializable;
      9 import java.util.Iterator;
     10 import java.util.List;
     11 
     12 import org.hamcrest.Description;
     13 import org.hamcrest.Matcher;
     14 import org.mockito.ArgumentMatcher;
     15 
     16 @SuppressWarnings("unchecked")
     17 public 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