
net.serenitybdd.screenplay.BooleanQuestionConsequence Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of serenity-screenplay Show documentation
Show all versions of serenity-screenplay Show documentation
Support for the User Journey pattern in Serenity
package net.serenitybdd.screenplay;
import net.serenitybdd.core.eventbus.Broadcaster;
import net.serenitybdd.screenplay.events.ActorAsksQuestion;
import net.thucydides.core.steps.StepEventBus;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
public class BooleanQuestionConsequence extends BaseConsequence {
private final Question question;
private final String subject;
public BooleanQuestionConsequence(Question actual) {
this.question = actual;
this.subject = QuestionSubject.fromClass(actual.getClass()).andQuestion(actual).subject();
}
@Override
public void evaluateFor(Actor actor) {
// TODO: Override if running consequences
if (thisStepShouldBeIgnored() && !StepEventBus.getEventBus().softAssertsActive()) { return; }
Broadcaster.getEventBus().post(new ActorAsksQuestion(question));
try {
assertThat(reason(), question.answeredBy(actor), is(true));
} catch (Throwable actualError) {
throwComplaintTypeErrorIfSpecified(errorFrom(actualError));
throwDiagosticErrorIfProvided(errorFrom(actualError));
throw actualError;
}
}
private String reason() {
return "Expected " + QuestionSubject.fromClass(question.getClass());
}
private void throwDiagosticErrorIfProvided(Error actualError) {
if (question instanceof QuestionDiagnostics) {
throw Complaint.from(((QuestionDiagnostics) question).onError(), actualError);
}
}
@Override
public String toString() {
return String.format("Then %s", subject);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy