Repository navigation
Home
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 published0.6.1artifact differs in a few places — see Published artifact.
| 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 |
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.
| 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 noCONSTRAINT_VIOLATION_EXCEPTIONfactory; - a missing node index in path navigation surfaced as a
NoSuchElementException, and a missing parameter index inextractingParameterDescriptor(int)as the list'sIndexOutOfBoundsException; both are nowAssertionErrors (see Paths and Nodes); - the validating methods dropped a description set with
as(…)and a message set withwithFailMessage(…), andnodes()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.1build compiled against AssertJ4.0.0-M1, and its profiles were namedjakarta-ee-11/jakarta-ee-10.
<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.
- Getting Started — dependencies and the first assertions on a bean
-
Validator Lifecycle — who builds, owns and closes the
ValidatorFactory - Build and Profiles — the Jakarta EE generation and AssertJ profiles, and CI
- Known Limitations — current behaviour that is open in the issue tracker
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.
assertj-validation · Apache License 2.0 · io.github.jinahya:assertj-validation · Jakarta Validation 3.0 / 3.1 · AssertJ 3.27+ · Java 17+
Running validation
Inspecting results
Reference
External