-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added recipe to use explicit isEmpty in AssertJ assertions #344
Added recipe to use explicit isEmpty in AssertJ assertions #344
Conversation
src/test/java/org/openrewrite/java/testing/assertj/UseExplicitisEmptyTest.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from a few minor details this looks good to me.
We could consider creating a follow-up commit where we also apply this to CharSequence#isEmpty()
and Optional#isEmpty()
for which AssertJ AFAIK also has dedicated methods.
src/main/java/org/openrewrite/java/testing/assertj/UseExplicitIsEmpty.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/java/testing/assertj/UseExplicitIsEmpty.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/java/testing/assertj/UseExplicitisEmptyTest.java
Outdated
Show resolved
Hide resolved
…IsEmpty.java Co-authored-by: Knut Wannheden <knut.wannheden@gmail.com>
…IsEmpty.java Co-authored-by: Knut Wannheden <knut.wannheden@gmail.com>
…isEmptyTest.java Co-authored-by: Tim te Beek <timtebeek@gmail.com>
All comments applied. I agree with @knutwannheden that we should add recipes for other cases - for example Optional needs recipes for isPresent() and isEmpty(). There is lots to do for assertj cleanup. |
src/test/java/org/openrewrite/java/testing/assertj/UseExplicitisEmptyTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/java/testing/assertj/UseExplicitisEmptyTest.java
Outdated
Show resolved
Hide resolved
…isEmptyTest.java Co-authored-by: Tim te Beek <timtebeek@gmail.com>
src/main/java/org/openrewrite/java/testing/assertj/UseExplicitIsEmpty.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/java/testing/assertj/UseExplicitIsEmpty.java
Outdated
Show resolved
Hide resolved
In fact we can even go further and migrate 'assertThat(string.size()).isEqualTo(0)' to 'assertThat(string).isEmpty()' But I wonder if it belongs to the same recipe |
@murdos I think we can put this in the recipe to cleanup the size. I can take care of that. |
What's changed?
I have added a new recipe to simplify assertions in tests that use AssertJ isEmpty().
Specifically, this recipe simplifies assertThat(collection.isEmpty()).isTrue() into assertThat(collection).isEmpty() and assertThat(collection.isEmpty()).isFalse() into assertThat(collection).isNotEmpty()
What's your motivation?
I work a lot with AssertJ and I have lots of legacy code to cleanup assertions.
Anything in particular you'd like reviewers to focus on?
This is similar to other recipes I have contributed, so there should be no big issue.
Anyone you would like to review specifically?
Have you considered any alternatives or workarounds?
Any additional context
Checklist
./gradlew licenseFormat