Repository navigation
Failure Messages
When a validating assertion fails, it says what was validated, with which groups, and lists every violation:
[registration case 42]
The set of constraint violations resulted while validating
actual: User@3c1{name=null,age=0}
targeting
groups: [jakarta.validation.groups.Default]
expected to be empty but contains 1 element(s)
-> message : must not be blank
propertyPath : name
rootBeanClass : class User
messageTemplate: {jakarta.validation.constraints.NotBlank.message}
The lines under validating depend on the method: actual and property for hasValidProperty; actual,
beanType and property for isValidFor; actual and parameters of method / return value of method for method
validation; parameters of constructor / return value of constructor for constructors. The negative methods say
expected to be not empty but empty.
The failure goes through AssertJ, so the usual configuration applies:
-
as(..)/describedAs(..)prefixes it ([registration case 42]above); -
withFailMessage(..)/overridingErrorMessage(..), eager or lazy, replaces it; -
withRepresentation(..)formats theactual,propertyand group values.
A % in a value or a message is printed as is, not read as a format specifier.
A checking method on a violation or a descriptor, such as hasInvalidValue(..) or hasMessageTemplate(..), fails
with the attribute name as its description, after yours if you set one:
[case 42: messageTemplate]
expected: "{jakarta.validation.constraints.NotNull.message}"
but was: "{jakarta.validation.constraints.NotBlank.message}"
A navigated assertion — extractingViolations(), extractingPropertyPath(), nodes(), extracting...Node(int) —
carries the description, overriding message and representation of the assertion it came from. Navigation within a path
hands a lazy withFailMessage(Supplier) over lazily, so the supplier runs only if the navigated assertion fails.
assertj-validation · Apache License 2.0 · io.github.jinahya:assertj-validation · Java 17+ · Jakarta Validation 3.0 / 3.1 · AssertJ 3.27.7+
Start
Running validation
Inspecting results
Using it
Reference
Links