@Test void testValidateEmailConstraint() { String attributeName = "attr"; Attribute attribute = when(mock(Attribute.class).getDataType()).thenReturn(EMAIL).getMock(); when(attribute.getName()).thenReturn(attributeName); EntityType entityType = when(mock(EntityType.class).getAtomicAttributes()) .thenReturn(singletonList(attribute)) .getMock(); String value = "invalidEmail"; Entity entity = when(mock(Entity.class).getEntityType()).thenReturn(entityType).getMock(); when(entity.getString(attribute)).thenReturn(value); Errors errors = mock(Errors.class); entityValidator.validate(entity, errors); verify(errors).rejectValue(attributeName, "constraints.Email", null, null); }
private void validateEmailConstraint(Entity entity, Attribute attribute, Errors errors) { if (attribute.getDataType() != AttributeType.EMAIL) { return; } String emailValue = entity.getString(attribute); if (emailValue == null) { return; } boolean valid = emailValidator.isValid(emailValue, null); if (!valid) { errors.rejectValue(attribute.getName(), ERROR_CODE_EMAIL, null, null); } }
EntityValidator implements Validator { private void validateEmailConstraint(Entity entity, Attribute attribute, Errors errors) { if (attribute.getDataType() != AttributeType.EMAIL) { return; } String emailValue = entity.getString(attribute); if (emailValue == null) { return; } boolean valid = emailValidator.isValid(emailValue, null); if (!valid) { errors.rejectValue(attribute.getName(), ERROR_CODE_EMAIL, null, null); } } }
EntityValidator implements Validator { private void validateEmailConstraint(Entity entity, Attribute attribute, Errors errors) { if (attribute.getDataType() != AttributeType.EMAIL) { return; } String emailValue = entity.getString(attribute); if (emailValue == null) { return; } boolean valid = emailValidator.isValid(emailValue, null); if (!valid) { errors.rejectValue(attribute.getName(), ERROR_CODE_EMAIL, null, null); } } EntityValidator(ExpressionValidator expressionValidator); }
EntityValidator implements Validator { private void validateEmailConstraint(Entity entity, Attribute attribute, Errors errors) { if (attribute.getDataType() != AttributeType.EMAIL) { return; } String emailValue = entity.getString(attribute); if (emailValue == null) { return; } boolean valid = emailValidator.isValid(emailValue, null); if (!valid) { errors.rejectValue(attribute.getName(), ERROR_CODE_EMAIL, null, null); } } EntityValidator(ExpressionValidator expressionValidator); @Override boolean supports(@Nonnull Class<?> clazz); @Override void validate(@Nonnull Object target, @Nonnull Errors errors); }
EntityValidator implements Validator { private void validateEmailConstraint(Entity entity, Attribute attribute, Errors errors) { if (attribute.getDataType() != AttributeType.EMAIL) { return; } String emailValue = entity.getString(attribute); if (emailValue == null) { return; } boolean valid = emailValidator.isValid(emailValue, null); if (!valid) { errors.rejectValue(attribute.getName(), ERROR_CODE_EMAIL, null, null); } } EntityValidator(ExpressionValidator expressionValidator); @Override boolean supports(@Nonnull Class<?> clazz); @Override void validate(@Nonnull Object target, @Nonnull Errors errors);  }