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

io.github.olib963.javatest.matchers.internal.MapSetMatcher Maven / Gradle / Ivy

There is a newer version: 0.2.0
Show newest version
package io.github.olib963.javatest.matchers.internal;

import io.github.olib963.javatest.matchers.MatchResult;
import io.github.olib963.javatest.matchers.Matcher;

import java.util.Collection;
import java.util.Map;
import java.util.function.Function;

public class MapSetMatcher implements Matcher> {

    private final Function, Collection> setFunction;
    private final Matcher elementMatcher;
    private final String type;

    public MapSetMatcher(Function, Collection> setFunction, Matcher elementMatcher, String type) {
        this.setFunction = setFunction;
        this.elementMatcher = elementMatcher;
        this.type = type;
    }

    @Override
    public MatchResult matches(Map value) {
        return MatchResult.of(setFunction.apply(value)
                .stream()
                .map(elementMatcher::matches)
                .anyMatch(r -> r.matches));
    }

    @Override
    public String describeExpected() {
        return "have a " + type + " that was expected to " + elementMatcher.describeExpected();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy