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

Use JUnit5's assertSame or assertNotSame instead of assertTrue(... == ...) #642

Merged
merged 5 commits into from
Nov 17, 2024

Conversation

mccartney
Copy link
Contributor

@mccartney mccartney commented Nov 17, 2024

What's changed?

Adding a new recipe for converting:

assertTrue(a == b);

to

assertSame(a, b);

for JUnit5 test code as suggested in

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

@timtebeek timtebeek added the recipe Recipe request label Nov 17, 2024
@timtebeek timtebeek self-requested a review November 17, 2024 12:43
@timtebeek timtebeek linked an issue Nov 17, 2024 that may be closed by this pull request
timtebeek and others added 2 commits November 17, 2024 13:48
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@timtebeek timtebeek changed the title Adding UseAssertSame recipe Use JUnit5's assertSame or assertNotSame instead of assertTrue(... == ...) Nov 17, 2024
Copy link
Contributor

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mccartney ! I've applied a few small polishing commits, such as visiting method invocations directly, as opposed to via method declarations, to match cases nested in assertAll for instance. We'll also want to update the method type, as chained assertions look at the type, not the simple name.

@timtebeek timtebeek merged commit 93d76cf into openrewrite:main Nov 17, 2024
2 checks passed
@mccartney mccartney deleted the junit5-assert-same branch November 17, 2024 15:00
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.

Transform assertTrue to assertSame or assertNotSame
2 participants