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

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

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

import net.serenitybdd.model.exceptions.SerenityManagedException;

public class FailedConsequence {
        private final Consequence consequence;
        private final RuntimeException runtimeExceptionCause;
        private final Error errorCause;

        public FailedConsequence(Consequence consequence, Throwable cause) {
            this.consequence = consequence;
            if (cause instanceof Error) {
                this.errorCause = (Error) cause;
                this.runtimeExceptionCause = null;
            } else if (cause instanceof RuntimeException) {
                this.errorCause = null;
                this.runtimeExceptionCause = (RuntimeException) cause;
            } else {
                this.errorCause = null;
                this.runtimeExceptionCause = (RuntimeException) SerenityManagedException.detachedCopyOf(cause);
            }
        }

        public Consequence getConsequence() {
            return consequence;
        }

        public Throwable getCause() {
            return (runtimeExceptionCause != null) ? runtimeExceptionCause : errorCause;
        }

    public void throwException() {
        if (runtimeExceptionCause != null) {
            throw runtimeExceptionCause;
        }
        throw errorCause;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy