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

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

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

import java.util.List;
import java.util.function.BiConsumer;

public class Iterate {
    private final List collection;

    public Iterate(List collection) {
        this.collection = collection;
    }

    public static  Iterate over(List collection) {
        return new Iterate<>(collection);
    }

    public Performable forEach(BiConsumer action) {
        return Task.where("{0} checks each entry in the collection:",
                actor -> {
                    collection.forEach(
                            item -> actor.attemptsTo(processItem(item, action)));
                }
        );
    }

    private Performable processItem(T item, BiConsumer action) {
        return Task.where("For item " + item.toString(),
                actor -> action.accept(actor, item)
        );
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy