v1.3.0
Exact single-document assertions land, and standard Hamcrest matchers become a first-class, bundled part of the assertion surface.
Highlights
- 01
Exact single-document assertions
hasSingleDocument() passes only when a collection holds exactly one document, and containsExactlyOneDocumentSatisfying(...) additionally requires that one document to satisfy the nested assertions. It is the strict sibling of containsDocumentSatisfying, which passes as soon as any of many documents matches.
- 02
First-class Hamcrest matchers
hasFieldMatching accepts any org.hamcrest.Matcher, so the standard library, including equalTo, containsString, startsWith and hasItem, asserts directly on a stored field value alongside the MongoFieldMatchers factory. Hamcrest is now an explicit compile dependency of both published modules, so import static org.hamcrest.Matchers.* needs nothing added to a consumer's build.
Full notes
Added
- Two exact-count collection assertions on assertThatCollection. hasSingleDocument() passes only when the collection holds exactly one document. It is the same check as hasDocumentCount(1), named for the single-aggregate and upsert tests where 'there should be exactly one row' is the point; it fails with 'Expected collection <db.coll> to hold a single document, but it holds N.'. containsExactlyOneDocumentSatisfying(requirements) is the strict sibling of containsDocumentSatisfying: it requires exactly one document and that the one document satisfy the nested assertions. It checks the count first, so a collection holding zero or several documents fails on the count alone and the nested assertions never run.
- Hamcrest matcher support across the assertion surface is now first-class and explicitly advertised. MongoDocumentAssert.hasFieldMatching(field, matcher) accepts any org.hamcrest.Matcher, so the whole standard org.hamcrest.Matchers. library works directly on a stored field value, alongside the MongoFieldMatchers factory (validObjectIdHex, validUuid, validIsoInstant, nonBlankString, matchesRegex, validJson, jsonPath, bsonDate, decimal128). Hamcrest is now declared as an explicit compile dependency of spring-mongo-test-utils as well as mongo-test-utils, so a consumer can import static org.hamcrest.Matchers. with no extra dependency added to their build.