Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New argument validation methods in KiwiValidations #750

Closed
sleberknight opened this issue Jul 17, 2022 · 0 comments · Fixed by #752
Closed

New argument validation methods in KiwiValidations #750

sleberknight opened this issue Jul 17, 2022 · 0 comments · Fixed by #752
Assignees
Labels
new feature A new feature such as a new class, method, package, group of classes, etc.
Milestone

Comments

@sleberknight
Copy link
Member

Add methods in KiwiValidations to validate method arguments. Normally these would go in KiwiPreconditions, but since these will require Jakarta Bean Validation, it seems to make more sense for them to live in KiwiValidations.

Method signatures:

// Validate an argument using the default validation group

public static <T> void checkArgumentValid(T object)

public static <T> void checkArgumentValid(T object, String errorMessage)

public static <T> void checkArgumentValid(T object,
        String errorMessageTemplate,
        Object... errorMessageArgs)

public static <T> void checkArgumentValid(T object,
        Function<Set<ConstraintViolation<T>>, String> errorMessageCreator)

// Validate an argument using custom validation group(s)

public static <T> void checkArgumentValid(T object, Class<?>... groupClasses)

public static <T> void checkArgumentValid(T object, String errorMessage, Class<?>... groupClasses)

// Unfortunately have to collect the args for the template in a list since
// you can't have two varargs parameters. It could also be an array but
// let's use List. It's pretty easy to do List.of(...)
public static <T> void checkArgumentValid(T object,
        String errorMessageTemplate,
        List<Object> errorMessageArgs,
        Class<?>... groupClasses)

public static <T> void checkArgumentValid(T object,
        Function<Set<ConstraintViolation<T>>, String> errorMessageCreator,
        Class<?>... groupClasses)

// Check set of constraint violations

public static <T> void checkArgumentNoViolations(Set<ConstraintViolation<T>> violations)

public static <T> void checkArgumentNoViolations(Set<ConstraintViolation<T>> violations,
        String errorMessage)

public static <T> void checkArgumentNoViolations(Set<ConstraintViolation<T>> violations,
        String errorMessageTemplate,
        Object... errorMessageArgs)

public static <T> void checkArgumentNoViolations(Set<ConstraintViolation<T>> violations,
        Function<Set<ConstraintViolation<T>>, String> errorMessageCreator)
@sleberknight sleberknight added the new feature A new feature such as a new class, method, package, group of classes, etc. label Jul 17, 2022
@sleberknight sleberknight added this to the 2.2.0 milestone Jul 17, 2022
@sleberknight sleberknight self-assigned this Jul 17, 2022
sleberknight added a commit that referenced this issue Jul 17, 2022
* Add methods that validate and throw ConstraintViolationException if
  validation fails
* Add methods that are intended to validate method arguments and throw
  IllegalArgumentException if validation fails.
* Update javadoc of KiwiPreconditions to mention the argument validation
  methods in KiwiValidations

Closes #750
Closes #751
chrisrohr pushed a commit that referenced this issue Jul 18, 2022
* Add methods that validate and throw ConstraintViolationException if
  validation fails
* Add methods that are intended to validate method arguments and throw
  IllegalArgumentException if validation fails.
* Update javadoc of KiwiPreconditions to mention the argument validation
  methods in KiwiValidations

Closes #750
Closes #751
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature A new feature such as a new class, method, package, group of classes, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant