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

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

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

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class CompositePerformable implements Performable {

    private final List todoList;

    private CompositePerformable(List todoList) {
        this.todoList = todoList;
    }

    public static Performable from(Performable firstPerformable, Performable nextPerformable) {
        List todoList = new ArrayList<>();
        todoList.addAll(flattened(firstPerformable));
        todoList.addAll(flattened(nextPerformable));
        return new CompositePerformable(todoList);
    }

    @Override
    public  void performAs(T actor) {
        todoList.forEach(actor::attemptsTo);
    }

    private static List flattened(Performable performable) {
        if (performable instanceof CompositePerformable) {
            return ((CompositePerformable) performable).todoList;
        } else {
            return Collections.singletonList(performable);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy