@Test public void generatedPasswordsAreValid() { List<String> passwords = Stream.generate(() -> MapperUtils.generatePassword(minLengthRule.getMinLength())) .limit(50) .collect(Collectors.toList()); List<String> errorMessages = passwords.stream() .flatMap(password -> unit.validate("ann-acm", password).stream()) .collect(Collectors.toList()); errorMessages.forEach(System.out::println); assertTrue(errorMessages.isEmpty()); }
public List<String> validate(String userId, String password) { return passwordRules.stream() .map(rule -> rule.runValidationAndGetMessage(userId, password)) .filter(Objects::nonNull) .collect(Collectors.toList()); }
PasswordValidationService { public List<String> validate(String userId, String password) { return passwordRules.stream() .map(rule -> rule.runValidationAndGetMessage(userId, password)) .filter(Objects::nonNull) .collect(Collectors.toList()); } }
PasswordValidationService { public List<String> validate(String userId, String password) { return passwordRules.stream() .map(rule -> rule.runValidationAndGetMessage(userId, password)) .filter(Objects::nonNull) .collect(Collectors.toList()); }  }
PasswordValidationService { public List<String> validate(String userId, String password) { return passwordRules.stream() .map(rule -> rule.runValidationAndGetMessage(userId, password)) .filter(Objects::nonNull) .collect(Collectors.toList()); }  List<String> validate(String userId, String password); void setPasswordRules(List<PasswordValidationRule> passwordRules); }
PasswordValidationService { public List<String> validate(String userId, String password) { return passwordRules.stream() .map(rule -> rule.runValidationAndGetMessage(userId, password)) .filter(Objects::nonNull) .collect(Collectors.toList()); }  List<String> validate(String userId, String password); void setPasswordRules(List<PasswordValidationRule> passwordRules);  }