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

org.hamcrest.core.AllOf Maven / Gradle / Ivy

There is a newer version: 2.0.2-beta
Show newest version
package org.hamcrest.core;

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

import java.util.Arrays;

/**
 * Calculates the logical conjunction of two matchers. Evaluation is
 * shortcut, so that the second matcher is not called if the first
 * matcher returns false.
 */
public class AllOf extends BaseMatcher {
    private final Iterable> matchers;

    public AllOf(Iterable> matchers) {
        this.matchers = matchers;
    }

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

    public void describeTo(Description description) {
    	description.appendList("(", " and ", ")", matchers);
    }

    /**
     * Evaluates to true only if ALL of the passed in matchers evaluate to true.
     */
    @Factory
    public static  Matcher allOf(Matcher... matchers) {
        return allOf(Arrays.asList(matchers));
    }

    /**
     * Evaluates to true only if ALL of the passed in matchers evaluate to true.
     */
    @Factory
    public static  Matcher allOf(Iterable> matchers) {
        return new AllOf(matchers);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy