
net.serenitybdd.screenplay.BaseConsequence 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 com.google.common.base.Optional;
import net.thucydides.core.steps.StepEventBus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public abstract class BaseConsequence implements Consequence {
private Class extends Error> complaintType;
private String complaintDetails;
protected Optional optionalPrecondition = Optional.absent();
protected Optional explanation = Optional.absent();
private final Logger LOGGER = LoggerFactory.getLogger(this.getClass());
protected Error errorFrom(Throwable actualError) {
if (actualError instanceof Error) {
return (Error) actualError;
}
return new Error(actualError);
}
protected void throwComplaintTypeErrorIfSpecified(Error actualError) {
if (complaintType != null) {
LOGGER.error("Could not resolve question", actualError);
throw Complaint.from(complaintType, complaintDetails, actualError);
}
}
protected boolean thisStepShouldBeIgnored() {
return (StepEventBus.getEventBus().currentTestIsSuspended() || StepEventBus.getEventBus().aStepInTheCurrentTestHasFailed());
}
@Override
public BaseConsequence orComplainWith(Class extends Error> complaintType) {
return orComplainWith(complaintType, null);
}
@Override
public BaseConsequence orComplainWith(Class extends Error> complaintType, String complaintDetails) {
this.complaintType = complaintType;
this.complaintDetails = complaintDetails;
return this;
}
@Override
public Consequence whenAttemptingTo(Performable performable) {
this.optionalPrecondition = Optional.of(performable);
return this;
}
@Override
public Consequence because(String explanation) {
this.explanation = Optional.fromNullable(explanation);
return this;
}
protected Optional inputValues() {
if (!optionalPrecondition.isPresent()) {
return Optional.absent();
}
if (!(optionalPrecondition.get() instanceof RecordsInputs)) {
return Optional.absent();
}
return Optional.of(((RecordsInputs) optionalPrecondition.get()).getInputValues());
}
protected String addRecordedInputValuesTo(String message) {
if (!inputValues().isPresent()) {
return message;
}
return message + " [" + inputValues().get() + "]";
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy