We have a method to test which iterates over some List. The example is a validator service which iterates over a List of validators applying each one and returning when one fails ie. it returns an Optional
containing an error message (this is just a concrete example to demonstrate Mockito and is not important to understand).
public class SomeValidationService implements ValidationService {
/* List of validators which all encapsulate some different business validation logic */
/* This gets injected say via Spring */
private List<Validator> validators;
public Optional<ErrorMessage> validateAction(final ObjectToValidate obj) {