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