Easily configure validators via properties in a Spring Boot project

The annotations from the Java Validation API provide a convenient and flexible tool to ensure the quality of an application’s input. Some of them have parameters that allow for the validation’s fine tuning. The main drawback is that the parameters’ values are resolved at compile time, that’s why they must be static final constants. We’ll show how we can overcome this limitation and configure validators via properties in a Spring Boot project. It would be […]

How to mock custom validators when unit testing

In the previous post we saw how dependencies in custom constraint validators can be mocked when we want to unit test our validation layer in a Spring Boot application. It all boils down to the creation of a custom ValidatorFactory that can use our custom ConstraintValidators, those will have their dependencies mocked and manually injected. But what if we want to mock an entire ConstraintValidator rather than just its dependencies? There are some situations where […]

How to mock dependencies when unit testing custom validators

The Java Validation API provides a very convenient API for input validation. It is part of the JavaEE spec, nevertheless it can be used within a Spring application too. Addressing the whole functioning of the Java Validation API is beyond the scope of this post, we will focus instead on how to unit test the validation layer. In this regard, we will show how to mock dependencies that might be injected in your custom constraint […]