v3.25.0
🚫 Deprecated
Core
- Deprecate the following date/time related assertions in favor of
isCloseTo:isEqualToIgnoringHoursisEqualToIgnoringMinutesisEqualToIgnoringSecondsisEqualToIgnoringMillisisEqualToIgnoringNanosisInSameHourAsisInSameMinuteAsisInSameSecondAs
- Deprecate
asListin favor ofasInstanceOf#3138
✨ New Features
Core
-
Add
Descriptable#describedAs(Supplier<String>) -
Add
isInThePastandisInTheFuturetoLocalDateassertions #2933 -
Add
isInThePastandisInTheFutureto the missing Java 8 date/time types #2947 -
Add
isRecordandisNotRecordtoClassassertions #2968 -
Add
hasNullValueanddoesNotHaveNullValuetoAtomicReferenceAssert#2969 -
Add
asBoolean|Byte|Short|Int|Long|Float|DoubletoStringassertions #2580 -
Add
hasRecordComponentstoClassassertions #2995 -
Add getters for field path in
ComparisonDifference#3007 -
Allow to compare
enumandstringfields in the recursive comparison #2616 -
Provide value when
assertThatThrownBy/thenThrownByfail #3043 -
Add
isSealedandisNotSealedtoClassassertions #3080 -
Add
assertThatCharSequenceto disambiguate Groovy'sGString#3132 -
Change the way the properties are collected using the
Class.getMethods()API instead of iterating the class hierarchy usingClass.declaredMethods()#3135 -
Add default constructor for
RecursiveComparator#3206 -
Add
isPrimitiveandisNotPrimitivetoClassassertions #2722 -
Add
anyOf(ThrowingConsumer...)andallOf(ThrowingConsumer...)#3219Details
What was written as:
assertThat(elements) .extracting(Element::getProperty) .allSatisfy(p -> assertThat(p).satisfiesAnyOf( p1 -> assertThat(p1).isNull(), p1 -> assertThat(p1).isNotNull().extracting(Property::getId).isEqualTo(expected) ));
can now be shortened to:
assertThat(elements) .extracting(Element::getProperty) .allSatisfy(anyOf( // statically imported from Assertions p1 -> assertThat(p1).isNull(), p1 -> assertThat(p1).isNotNull().extracting(Property::getId).isEqualTo(expected) ));
-
Show the array/iterable under test in the assertion error message when it is not empty but should have been #3230
🐛 Bug Fixes
Core
- Compare Java types from
javaxandcom.sunby their equals method in recursive comparison #2928 - The recursive comparison
comparingOnlyFieldsdid not treat array/iterable elements as root objects #2994 - Fixes a bug when failing assertions on
DirectoryStreamtypes #3036 - Fix handling of null containers in the recursive assertion #3045
- Handle null values in map entry sets when formatting #3087
- Fix NPE when expected and actual field values are null #3034
- Fix NPE on
anyMatchwhenactualcontainsnullandObjects::isNullis used as predicate #3151 - Fix misleading subsequence failure messages in string assertions #3166
- Do not ignore nested fields of types specified in
comparingOnlyFieldsOfTypes#3207 containsExactlydoes not work properly with maps not using equals to compare keys #2165- Escape percentage in
shouldContainExactlyerror message #3288 - Fix recursive comparison of ignored types in unordered collection #3287
⚡ Improvements
- Add Spotless #3115
Core
-
Use Bnd feature to write resolved
bndrunfiles to output folder #2902 -
Add
Throwablestack trace toShouldHaveClause#2872 -
Avoid copy of any
Collectioninstance inIterables::assertContains -
Add
Throwablestack trace toShouldHaveRootCauseInstanceandShouldHaveRootCauseExactlyInstance#2910 -
Add missing description to nested condition #2755
-
Make nestable condition factory accept conditions on super types #2905
-
Add varargs overload to
Assert::hasStringandAssert::doesNotHaveString#2945 -
Improve recursive comparison performance by caching field and field names result #2979
-
Document performance cost of ignoring collection order
-
Track visited values and their comparison differences so that they can be reused #2954
-
Use hash code for
compareUnorderedIterablesto improve performance in some common cases #3020 -
Improve recursive comparison error message regarding
equalsmethods used for JDK types #2678 -
Format large arrays as strings #3065
-
Remove null check as
isArrayalready performs it -
Fix
PrimitiveArralList/TransformlingListtest file names #3124 -
Add exception for usages of
isEqualToandisNotEqualToon assertions #2921Details
Before this change, the following code:
AbstractAssert<?, ?> assertion = assertThat(something); assertThat(assertion).isEqualTo(assertion);
would throw an exception with a message about
equalsbeing unsupported, suggesting to useisEqualToinstead. The message is somewhat confusing to the reader, sinceisEqualTois indeed used, and is becauseisEqualTointernally relies on theequalsofactual, which is anAbstractAssertinstance and throws the exception above.isEqualToandisNotEqualTonow check ifactualis an assertion instance and raise anUnsupportedOperationExceptionif so, with a message suggesting to useisSameAsandisNotSameAsinstead.This is, for example, useful for testing custom assertion types for extension libraries, where the use of
satisfiesinstead ofisEqualTomay be desirable. -
Add check for missing fields in recursive comparison where specific fields are requested for comparison
-
Improve efficiency of iterable string conversion #3123
-
Add more tests for
usingRecursiveComparison#2790 -
Checks that compared fields exist before running the recursive comparison #3129
-
Remove
maven-surefire-pluginduplicate version #3180 -
Remove Maven default goal #3182
-
Add dependency graph workflow
-
Normalize non-breaking spaces like regular white spaces #3120
-
AbstractOffsetDateTimeAssert::isBetweenparameter names should useinclusive, notexclusive#3217 -
Invoke
isNotNullinreturnsanddoesNotReturn#3224 -
Cache node names in
ComparingFields,ComparingProperties#3242 -
Cache node names in
ComparingNormalizedFields -
Use simpler syntax in
DefaultRecursiveComparisonIntrospectionStrategy.getChildrenNodeNamesOf -
Update to Contributor Covenant Code of Conduct v2.1
-
Correct
containsassertion Javadoc to reflect method behavior in case actual is not empty and the group of values to look for is #3256 -
Fix Javadoc typos #3265
-
Improving null-safety of
isEqualToNormalizingNewlines#2776 -
Speed up for
BinaryDiffperformance #3193 -
Upgrade workflows to Java 21 #3191
-
Apply
flatten-maven-plugintoassertj-coreandassertj-guava#3311
🔨 Dependency Upgrades
Core
- Upgrade to Byte Buddy 1.14.11 #330
- Upgrade to JUnit BOM 5.10.1 #3254
- Upgrade to OpenTest4J 1.3.0 #3122
Guava
- Upgrade to Guava 32.1.3-jre #3218
❤️ Contributors
Thanks to all the contributors who worked on this release:
@bjhargrave @vlsi @Ds2994 @StefanBratanov @alex859 @ascopes @ljrmorgan @ghkim3221 @hezean @matthew-leng @etellman @hjir @amodolo @armandino @aindriu-aiven @Bananeweizen @JohnBryte @ManuelG28 @maximedezette @radistao @ykardziyaka @wouterpolet @sarajuhosova @pbacz @Gabriel-Darbord @Nacho321 @marcela-cardona-s @matthiaskraaz @quaff @grigala @martinfrancois @georgebax