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

net.serenitybdd.screenplay.questions.QuestionHints Maven / Gradle / Ivy

There is a newer version: 4.2.9
Show newest version
package net.serenitybdd.screenplay.questions;

import net.serenitybdd.core.Serenity;
import net.serenitybdd.core.pages.WebElementState;
import net.serenitybdd.screenplay.Question;
import org.hamcrest.Matcher;

import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import static java.util.Arrays.stream;

public class QuestionHints {
    public static Set> fromAssertion(Matcher matcher) {
        return stream(matcher.getClass().getInterfaces())
                .filter(QuestionHint.class::isAssignableFrom)
                .map( matcherInterface -> ((Class) matcherInterface) )
                .collect(Collectors.toSet());
    }

    public static HintAdder addHints(Set> hints) {
        return new HintAdder(hints);
    }

    public static class HintAdder {
        private final Set> hints;

        public HintAdder(Set> hints) {
            this.hints = hints;
        }

        public  void to(Question question) {
            if (question instanceof AcceptsHints) {
                ((AcceptsHints) question).apply(hints);
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy