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

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

There is a newer version: 8.9.2
Show newest version
package com.cedarsoft.test.utils.matchers;

import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Matcher;

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

/**
 * @author Johannes Schneider ([email protected])
 */
class AndMatcher extends BaseMatcher {
  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