Enable JUnitAssertXXXToAssertThat for JUnit 4
What problem are you trying to solve?
I want to migrate JUnit 4 assertions to AssertJ. The existing recipes migrate only JUnit 5 assertions. From the recipe's description it is also not clear that "JUnit assertEquals to AssertJ" refer to JU 5 only.
Describe the solution you'd like
The existing recipes might be enhanced to cover both cases by trying to match methods for org.junit.jupiter.api.Assertions or org.junit.Assert and resolve the parameters differently. The assertions are quite similar except for the order of arguments.
Have you considered any alternatives or workarounds?
There could be also dedicated JUnit4AssertXXXToAssertThat recipes. This would likely produce more duplicated code.
Migrating to JUnit 5 is the ultimate goal, but I would like to do it stepwise and migrate the assertions before migrating the tests themselves.
Are you interested in contributing this feature to OpenRewrite?
Yes, I have a working draft for one recipe already. I could contribute this already, but it feels as if all JUnitAssertXXXToAssertThat recipses should be enhanced together. Might be surprising if only one recipe behaves different.
hi @kthoms ; thanks for pointing out that it wasn't immediately clear the recipe indeed also upgrades you to JUnit 5. I feel it might be complicated to update all recipes to also support JUnit 4, since there's also steps invoked that first apply JUnit 5 best practices to achieve a more idiomatic migration to AssertJ assertions. https://github.com/openrewrite/rewrite-testing-frameworks/blob/fc9d8b46f40b336d4ab0149078861f7743758a2b/src/main/resources/META-INF/rewrite/assertj.yml#L453-L482
It's been 7,5 years since JUnit 5 came out, and JUnit 6 is on the horizon for the end of this year. Since you're already eyeing JUnit 5, perhaps we should then not complicate the recipes here? Note that you can still develop and run those recipes yourself, but adoption into OpenRewrite might complicate what we have to maintain going forward.
I leave the decision up to you. For me it is important to migrate the assertions before actually upgrading to JUnit 5. The recipe that converts to JUnit 5 simply breaks too much stuff in our code base. So I want to take this step first. But I can use the recipes for our purpose now, of course.
Glad to hear the recipes you've developed have proven useful to you already. To keep maintenance on our side easier I'll close #673 for now, as much as the effort was appreciated! Hope you'll be able to switch to JUnit 5 soon, to leverage the continued support there
- https://github.com/openrewrite/rewrite-testing-frameworks/pull/690