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

com.cedarsoft.test.utils.matchers.AndMatcher Maven / Gradle / Ivy

package com.cedarsoft.test.utils.matchers;

import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.mockito.ArgumentMatcher;

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

/**
 * @author Johannes Schneider ([email protected])
 */
class AndMatcher extends ArgumentMatcher implements Serializable {
  private final List> matchers;

  public AndMatcher(List> matchers) {
    this.matchers = new ArrayList>(matchers);
  }

  @Override
  public boolean matches(Object argument) {
    for (Matcher matcher : matchers) {
      if (!matcher.matches(argument)) {
        return false;
      }
    }
    return true;
  }

  @Override
  public void describeTo(Description description) {
    description.appendText("and(");
    for (Iterator> it = matchers.iterator(); it.hasNext(); ) {
      it.next().describeTo(description);
      if (it.hasNext()) {
        description.appendText(", ");
      }
    }
    description.appendText(")");
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy