@Test void testValidateUserNullEmail() { User user = new User(null, "password", Collections.emptyMap()); ValidationException e = assertThrows(ValidationException.class, () -> validator.validate(user)); assertEquals("Cannot post a user without an email address.", e.getMessage()); }
public void validate(User user) { if (user == null) { LOG.warn("Attempted to post a null user."); throw new ValidationException("Cannot post a null user."); } if (user.getEmail() == null) { LOG.warn("Attempted to post a user with a null Email object."); throw new ValidationException("Cannot post a user without an email address."); } if (!isValidEmail(user.getEmail().getAddress())) { LOG.error("The new user has an invalid email address: {}", user.getEmail()); throw new ValidationException("Invalid email address format. Please try again."); } if (!propertyValidator.isValidPropertiesMap(user.getProperties())) { LOG.warn("Attempted to post a user with invalid properties."); throw new ValidationException("Cannot post a user with invalid properties."); } }
RequestValidator { public void validate(User user) { if (user == null) { LOG.warn("Attempted to post a null user."); throw new ValidationException("Cannot post a null user."); } if (user.getEmail() == null) { LOG.warn("Attempted to post a user with a null Email object."); throw new ValidationException("Cannot post a user without an email address."); } if (!isValidEmail(user.getEmail().getAddress())) { LOG.error("The new user has an invalid email address: {}", user.getEmail()); throw new ValidationException("Invalid email address format. Please try again."); } if (!propertyValidator.isValidPropertiesMap(user.getProperties())) { LOG.warn("Attempted to post a user with invalid properties."); throw new ValidationException("Cannot post a user with invalid properties."); } } }
RequestValidator { public void validate(User user) { if (user == null) { LOG.warn("Attempted to post a null user."); throw new ValidationException("Cannot post a null user."); } if (user.getEmail() == null) { LOG.warn("Attempted to post a user with a null Email object."); throw new ValidationException("Cannot post a user without an email address."); } if (!isValidEmail(user.getEmail().getAddress())) { LOG.error("The new user has an invalid email address: {}", user.getEmail()); throw new ValidationException("Invalid email address format. Please try again."); } if (!propertyValidator.isValidPropertiesMap(user.getProperties())) { LOG.warn("Attempted to post a user with invalid properties."); throw new ValidationException("Cannot post a user with invalid properties."); } } @Inject  RequestValidator(PropertyValidator propertyValidator, boolean passwordHeaderCheckEnabled); }
RequestValidator { public void validate(User user) { if (user == null) { LOG.warn("Attempted to post a null user."); throw new ValidationException("Cannot post a null user."); } if (user.getEmail() == null) { LOG.warn("Attempted to post a user with a null Email object."); throw new ValidationException("Cannot post a user without an email address."); } if (!isValidEmail(user.getEmail().getAddress())) { LOG.error("The new user has an invalid email address: {}", user.getEmail()); throw new ValidationException("Invalid email address format. Please try again."); } if (!propertyValidator.isValidPropertiesMap(user.getProperties())) { LOG.warn("Attempted to post a user with invalid properties."); throw new ValidationException("Cannot post a user with invalid properties."); } } @Inject  RequestValidator(PropertyValidator propertyValidator, boolean passwordHeaderCheckEnabled); void validate(User user); void validate(String password, String email, boolean tokenAsPassword); void validate(String password, String email, User user); boolean isPasswordHeaderCheckEnabled(); }
RequestValidator { public void validate(User user) { if (user == null) { LOG.warn("Attempted to post a null user."); throw new ValidationException("Cannot post a null user."); } if (user.getEmail() == null) { LOG.warn("Attempted to post a user with a null Email object."); throw new ValidationException("Cannot post a user without an email address."); } if (!isValidEmail(user.getEmail().getAddress())) { LOG.error("The new user has an invalid email address: {}", user.getEmail()); throw new ValidationException("Invalid email address format. Please try again."); } if (!propertyValidator.isValidPropertiesMap(user.getProperties())) { LOG.warn("Attempted to post a user with invalid properties."); throw new ValidationException("Cannot post a user with invalid properties."); } } @Inject  RequestValidator(PropertyValidator propertyValidator, boolean passwordHeaderCheckEnabled); void validate(User user); void validate(String password, String email, boolean tokenAsPassword); void validate(String password, String email, User user); boolean isPasswordHeaderCheckEnabled();  }