Skip to content
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

Merged
merged 8 commits into from
May 25, 2023

Conversation

pibizza
Copy link
Contributor

@pibizza pibizza commented May 25, 2023

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

  • I've added unit tests to cover both positive and negative cases
  • I've added the license header to any new files through ./gradlew licenseFormat
  • I've used the IntelliJ auto-formatter on affected files
  • I've updated the documentation (if applicable)

@timtebeek timtebeek added the recipe Recipe request label May 25, 2023
Copy link
Contributor

@knutwannheden knutwannheden left a 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.

pibizza and others added 3 commits May 25, 2023 22:16
…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>
@pibizza
Copy link
Contributor Author

pibizza commented May 25, 2023

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.

@pibizza pibizza marked this pull request as ready for review May 25, 2023 20:18
…isEmptyTest.java

Co-authored-by: Tim te Beek <timtebeek@gmail.com>
@knutwannheden knutwannheden merged commit 6363365 into openrewrite:main May 25, 2023
1 check passed
@murdos
Copy link
Contributor

murdos commented May 26, 2023

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.

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

@pibizza
Copy link
Contributor Author

pibizza commented May 26, 2023

@murdos I think we can put this in the recipe to cleanup the size. I can take care of that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
recipe Recipe request
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

4 participants