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

net.serenitybdd.screenplay.conditions.ConditionalPerformable Maven / Gradle / Ivy

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

import java.util.HashMap;

import net.serenitybdd.markers.IsHidden;
import net.serenitybdd.screenplay.Actor;
import net.serenitybdd.screenplay.Performable;

import java.util.HashMap;
import java.util.Map;

public abstract class ConditionalPerformable implements Performable, IsHidden {

    protected final Map outcomeToPerform;

    public ConditionalPerformable() {
        this.outcomeToPerform = new HashMap();
        outcomeToPerform.put(true, new Performable[]{ new SilentPerformable() });
        outcomeToPerform.put(false, new Performable[]{ new SilentPerformable() });
    }

    public ConditionalPerformable andIfSo(Performable... taskToPerform) {
        outcomeToPerform.put(true, taskToPerform);
        return this;
    }

    public ConditionalPerformable otherwise(Performable... taskToPerform) {
        outcomeToPerform.put(false, taskToPerform);
        return this;
    }

    @Override
    public  void performAs(T actor) {
        actor.attemptsTo(outcomeToPerform.get(evaluatedConditionFor(actor)));
    }

    protected abstract Boolean evaluatedConditionFor(Actor actor);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy