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

uk.org.lidalia.test.AllOf Maven / Gradle / Ivy

The newest version!
package uk.org.lidalia.test;

import org.hamcrest.Description;
import org.hamcrest.DiagnosingMatcher;
import org.hamcrest.Matcher;

/**
 * Calculates the logical conjunction of multiple matchers. Evaluation is shortcut, so
 * subsequent matchers are not called if an earlier matcher returns false.
 */
class AllOf extends DiagnosingMatcher {

    private final Iterable> matchers;

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

    @Override
    public boolean matches(final Object object, final Description mismatch) {
        for (final Matcher matcher : matchers) {
            if (!matcher.matches(object)) {
                matcher.describeMismatch(object, mismatch);
                return false;
            }
        }
        return true;
    }

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




© 2015 - 2025 Weber Informatics LLC | Privacy Policy