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

Recipe to make tests throw at most a single Exception #510

Merged
merged 3 commits into from
Apr 24, 2024

Conversation

Bananeweizen
Copy link
Contributor

@Bananeweizen Bananeweizen commented Apr 21, 2024

What's changed?

New recipe for replacing exception subclasses in test method signatures by java.lang.Exception, to improve readability. I'm not sure if there is any static code analysis guideline demanding this. I am sure that there are different opinions by developers whether to declare void test throws MyVerySpecialException or just ...Exception. Nevertheless I do need this recipe at work, and maybe it's useful for others, too.

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

You may want to look at the DocumentExample in the test to see the main idea. Feel free to suggest a different name or description.
The "is this a test" detection has been copied from another recipe. I'm not sure if it would be useful to have some helper classes there to unify that.

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
Copy link
Contributor

Nice addition! Still have to go over it in more details, but I'm thinking we can name this something like TestMethodSingleThrow, to signify what the recipe will do beyond SimplifyTestThrows. Any thoughts there? Open to suggestions; just wondering if simplify is perhaps too broad.

@timtebeek timtebeek self-requested a review April 23, 2024 19:32
@timtebeek timtebeek added the recipe Recipe request label Apr 23, 2024
@timtebeek timtebeek changed the title new recipe to simplify test method throws declarations Recipe to make tests throw at most a single Exception Apr 24, 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.

Great addition, thanks for contributing this!

@timtebeek timtebeek merged commit d73c390 into openrewrite:main Apr 24, 2024
1 check passed
@Bananeweizen Bananeweizen deleted the test_throws branch April 24, 2024 11:35
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.

2 participants