Skip to content
Jin Kwon edited this page Nov 13, 2026 · 2 revisions

assertj-validation

assertj-validation is an AssertJ extension for Jakarta Validation. It adds fluent assertions which run validation — on a bean, on a value against a bean property, on method and constructor parameters and return values — and assertions which inspect what validation produced: constraint violations, property paths and their nodes, the ConstraintViolationException a framework throws, and the metadata descriptors.

It is written against the Jakarta Validation API only. Nothing under src/main references an implementation; the tests run on Hibernate Validator, which is the only implementation exercised.

This wiki documents the working tree (0.6.2-SNAPSHOT), not the latest release. The published 0.6.1 artifact differs in a few places — see Published artifact.

Project snapshot

Item Value
Maven coordinates io.github.jinahya:assertj-validation (jar)
Latest release 0.6.1
Current source version 0.6.2-SNAPSHOT
Package com.github.jinahya.assertj.validation (one package)
Automatic-Module-Name com.github.jinahya.assertj.validation (no module-info.java)
Java main source/target/release 17
Java test source/target/release 25
Build JDK requirement JDK 25 (CI uses Temurin 25)
Parent POM io.github.jinahya:jinahya-parent:1.1.4
Jakarta Validation 3.1 (profile jakartaee-11, default) and 3.0 (profile jakartaee-10)
AssertJ built against 3.27.7; the assertj-4 profile tests 4.0.0-M1
Supported AssertJ 3.x from 3.27.7; 4.0.0-M1 tested as a milestone
Validation implementation in tests Hibernate Validator 9.1.4.Final (EE 11) / 8.0.5.Final (EE 10), with Expressly
Scope of jakarta.validation-api and assertj-core provided — the consumer brings both
Intended consumer scope test
License Apache License 2.0

Entry points

Every assertion is created by a static method of ValidationAssertions. None of them is named assertThat, so a static import of both ValidationAssertions.* and AssertJ's Assertions.* does not clash.

Group Entry point Page
Running validation assertThatBean(Object) Validating Beans, Executable Validation
assertThatProperty(Object) Validating Values
assertThatConstructor(Constructor) Executable Validation
Inspecting results assertThatConstraintViolations(Set), assertThatIterableOfConstraintViolations(Iterable), assertThatConstraintViolation(ConstraintViolation) Inspecting Violations
assertThatConstraintViolationException(ConstraintViolationException) Inspecting Violations
assertThatPath(Path), assertThatNode(Path.Node) and one assertThat…Node per node kind Paths and Nodes
Inspecting metadata assertThatBeanDescriptor(BeanDescriptor) and one entry point per descriptor type, plus assertThatConstraintDescriptor(ConstraintDescriptor) Metadata

Only the assertions which run validation take a validator and groups (usingValidator, usingValidatorFactory, targetingGroups); see Validator Lifecycle. The assertions on results have an InstanceOfAssertFactory each; see InstanceOf Factories.

Published artifact

Version On Central Note
0.6.1 yes see below
0.6.2-SNAPSHOT no the working tree this wiki describes

What 0.6.1 does not have, or does differently:

  • no assertThatConstraintViolationException(…) and no CONSTRAINT_VIOLATION_EXCEPTION factory;
  • a missing node index in path navigation surfaced as a NoSuchElementException, and a missing parameter index in extractingParameterDescriptor(int) as the list's IndexOutOfBoundsException; both are now AssertionErrors (see Paths and Nodes);
  • the validating methods dropped a description set with as(…) and a message set with withFailMessage(…), and nodes() and a wrong-kind node navigation dropped the description; all are honoured now;
  • method-validation failure messages were labelled differently from constructor ones;
  • the 0.6.1 build compiled against AssertJ 4.0.0-M1, and its profiles were named jakarta-ee-11 / jakarta-ee-10.

Installation

<dependency>
  <groupId>io.github.jinahya</groupId>
  <artifactId>assertj-validation</artifactId>
  <version><!-- released version --></version>
  <scope>test</scope>
</dependency>

Your build supplies jakarta.validation-api, assertj-core, and a validation provider. See Getting Started.

Where to go next

External


This wiki documents the working tree of the assertj-validation repository. Where a statement is version-sensitive it names the version it was written against.

Clone this wiki locally