net.serenitybdd.screenplay.CompositePerformable Maven / Gradle / Ivy
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);
}
}
}