net.serenitybdd.screenplay.questions.QuestionHints Maven / Gradle / Ivy
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 extends QuestionHint>) 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);
}
}
}
}