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

com.exasol.matcher.EnhancedAllOfMatcher Maven / Gradle / Ivy

package com.exasol.matcher;

import java.util.Arrays;

import org.hamcrest.*;

/**
 * This Hamcrest matcher improves upon the error reporting of the {@link org.hamcrest.core.AllOf} matcher.
 *
 * @param  matcher type
 */
public class EnhancedAllOfMatcher extends DiagnosingMatcher {
    private final Iterable> matchers;

    private EnhancedAllOfMatcher(final Iterable> matchers) {
        this.matchers = matchers;
    }

    /**
     * Get an {@link EnhancedAllOfMatcher} for multiple other matchers.
     *
     * @param matchers matchers to combine
     * @param       matcher type
     * @return built {@link EnhancedAllOfMatcher}
     */
    @SafeVarargs
    @SuppressWarnings("varargs")
    public static  Matcher enhancedAllOf(final Matcher... matchers) {
        return new EnhancedAllOfMatcher(Arrays.asList(matchers));
    }

    @Override
    protected boolean matches(final Object item, final Description mismatchDescription) {
        for (final Matcher matcher : this.matchers) {
            if (!matcher.matches(item)) {
                matcher.describeMismatch(item, mismatchDescription);
                return false;
            }
        }
        return true;
    }

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy