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

Junit4 to assertj #673

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Conversation

kthoms
Copy link
Contributor

@kthoms kthoms commented Feb 11, 2025

What's changed?

This change enables JUnitAssertXXXToAssertThat recipes to also handle JUnit 4 assertions. Therefore it introduces an abstract superclass that allows to configure JUnit 4 & 5 specific method matchers and a visitor that handles both configurations.

Tests are added for the refactoring of JUnit 4 style assertions. Note that JUnit 4 has mostly matching assertions, but less capabilities in detail:

  • No support for message suppliers
  • No assertion for instanceOf
    The tests are reduced by that for JUnit 4.

What's your motivation?

This is for a migration to JUnit 5 where I want to migrate the assertions before the test classes themselves, because due to extensive use of JUnit 4 rules and parametrized tests the migration has to be done partially manually and changes to the assertions are distracting.

Anything in particular you'd like reviewers to focus on?

The structure of the abstract's class logic and naming.

Performance consideration: When JUnit 4 style is migrated, first the JUnit 5 configuration is tried to be matched.

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

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Some suggestions could not be made:

  • src/main/java/org/openrewrite/java/testing/search/FindUnitTests.java
    • lines 86-87

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Some suggestions could not be made:

  • src/main/java/org/openrewrite/java/testing/search/FindUnitTests.java
    • lines 86-87

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

Enable JUnitAssertXXXToAssertThat for JUnit 4
1 participant