Replace Junit4 assertions by AssertJ ones#333
Merged
VanRoy merged 1 commit intoassertj:mainfrom Feb 21, 2026
Merged
Conversation
There was only three found : - A few assertTrue - A few assertFalse - Lots of org.junit.Assert.fail
Member
|
@jmaniquet Thank you for that and for this very detailed description! Regarding a more deep refactoring of test we have to evaluate if it worth. Again thanks a lot for your help. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This solves #332
I used OpenRewrite as suggested by @scordio ; though not the recipe suggested as it was a major refactoring of the code base beyond the scope of the ticket.
Altering the code on a large scale was quite fast with that tool, I did liked it, great tool.
To find the right recipes, I did spent some time analyzing what needed changes though.
There was only three types of old assertions that I found :
org.junit.Assert.assertTrueorg.junit.Assert.assertFalseorg.junit.Assert.failThe first two were those I saw when working on #329 and that's what initiated my suggestion.
There were very few; I just happened to find by accident the only two classes that had them (Order_Equals_Test / Values_AreEqual_UUID_And_String_Test).
All the other files changed were using
org.junit.Assert.failintry/fail/catchblocksI spent some more time with OpenRewrite to see if I could change the
try/fail/catchblocks to one of the Throwable-related AssertJ assertions.I did find a recipe : https://docs.openrewrite.org/recipes/java/testing/assertj/junittryfailtoassertthatthrownby
However it seems to only work with empty
catchblocksAnd beside that, there are multiple ways in AssertJ to assert Throwables. This may not have been the one you would have chosen.
So I left
try/fail/catchas is for now.I also played with the recipe to replace
Assertions.assertThatby the static import.It works, but i realized two things :
assertThat(from core and from db) have to coexist - so my second guess is the non-static import comes from that constraintI left that as is for now too; though maybe it can now be solved thanks to #329
As for OpenRewrite : I did not commit the config I used. Once run, I see it as dead code in the POM.
That's just me however, and I can alter the POM with the OpenRewrite config I used if you wish.
As for the recipes as I used : I did not find any that migrated Junit4 assertions to AssertJ ones.
There was however :
For reference, I ended up with this :
If there is any interest, I'm willing to do more test-related refactorings; I have done this kind of work before.