@Test void isValidWrongCountOfTagsExceptionTest() { AddEcoNewsDtoRequest request = getAddEcoNewsDtoRequest(); request.setTags(Collections.emptyList()); request.setSource("https: assertThrows(WrongCountOfTagsException.class, () -> validator.isValid(request, null)); }
@Override public boolean isValid(AddEcoNewsDtoRequest value, ConstraintValidatorContext context) { if (value.getSource() != null && !value.getSource().isEmpty()) { isUrlValid(value.getSource()); } List<String> tags = value.getTags(); if (tags.isEmpty() || tags.size() > ValidationConstants.MAX_AMOUNT_OF_TAGS) { throw new WrongCountOfTagsException(ErrorMessage.WRONG_COUNT_OF_TAGS_EXCEPTION); } return true; }
EcoNewsDtoRequestValidator implements ConstraintValidator<ValidEcoNewsDtoRequest, AddEcoNewsDtoRequest> { @Override public boolean isValid(AddEcoNewsDtoRequest value, ConstraintValidatorContext context) { if (value.getSource() != null && !value.getSource().isEmpty()) { isUrlValid(value.getSource()); } List<String> tags = value.getTags(); if (tags.isEmpty() || tags.size() > ValidationConstants.MAX_AMOUNT_OF_TAGS) { throw new WrongCountOfTagsException(ErrorMessage.WRONG_COUNT_OF_TAGS_EXCEPTION); } return true; } }
EcoNewsDtoRequestValidator implements ConstraintValidator<ValidEcoNewsDtoRequest, AddEcoNewsDtoRequest> { @Override public boolean isValid(AddEcoNewsDtoRequest value, ConstraintValidatorContext context) { if (value.getSource() != null && !value.getSource().isEmpty()) { isUrlValid(value.getSource()); } List<String> tags = value.getTags(); if (tags.isEmpty() || tags.size() > ValidationConstants.MAX_AMOUNT_OF_TAGS) { throw new WrongCountOfTagsException(ErrorMessage.WRONG_COUNT_OF_TAGS_EXCEPTION); } return true; }  }
EcoNewsDtoRequestValidator implements ConstraintValidator<ValidEcoNewsDtoRequest, AddEcoNewsDtoRequest> { @Override public boolean isValid(AddEcoNewsDtoRequest value, ConstraintValidatorContext context) { if (value.getSource() != null && !value.getSource().isEmpty()) { isUrlValid(value.getSource()); } List<String> tags = value.getTags(); if (tags.isEmpty() || tags.size() > ValidationConstants.MAX_AMOUNT_OF_TAGS) { throw new WrongCountOfTagsException(ErrorMessage.WRONG_COUNT_OF_TAGS_EXCEPTION); } return true; }  @Override void initialize(ValidEcoNewsDtoRequest constraintAnnotation); @Override boolean isValid(AddEcoNewsDtoRequest value, ConstraintValidatorContext context); }
EcoNewsDtoRequestValidator implements ConstraintValidator<ValidEcoNewsDtoRequest, AddEcoNewsDtoRequest> { @Override public boolean isValid(AddEcoNewsDtoRequest value, ConstraintValidatorContext context) { if (value.getSource() != null && !value.getSource().isEmpty()) { isUrlValid(value.getSource()); } List<String> tags = value.getTags(); if (tags.isEmpty() || tags.size() > ValidationConstants.MAX_AMOUNT_OF_TAGS) { throw new WrongCountOfTagsException(ErrorMessage.WRONG_COUNT_OF_TAGS_EXCEPTION); } return true; }  @Override void initialize(ValidEcoNewsDtoRequest constraintAnnotation); @Override boolean isValid(AddEcoNewsDtoRequest value, ConstraintValidatorContext context);  }