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

net.serenitybdd.screenplay.BaseConsequence Maven / Gradle / Ivy

There is a newer version: 1.1.26-rc.1
Show newest version
package net.serenitybdd.screenplay;

import net.thucydides.core.steps.StepEventBus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class BaseConsequence implements Consequence {

    private Class complaintType;
    private String complaintDetails;

    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 complaintType) {
        return orComplainWith(complaintType, null);
    }

    @Override
    public BaseConsequence orComplainWith(Class complaintType, String complaintDetails) {
        this.complaintType = complaintType;
        this.complaintDetails = complaintDetails;
        return this;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy