### Question:
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);  }### Answer:
@Test public void passwordIsValid() { List<String> errorMessages = unit.validate("ann-acm", "AcMd3v["); assertTrue(errorMessages.isEmpty()); }
@Test public void passwordIsTooShort() { List<String> errorMessages = unit.validate("ann-acm", "Ac3$"); assertTrue(errorMessages.size() == 1); assertEquals("Password must be of minimum length of 7.", errorMessages.get(0)); }
@Test public void invalidPassword() { List<String> errorMessages = unit.validate("ann-acm", "ann-acm\\$\"'?"); assertTrue(errorMessages.size() == 3); }
@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()); }