-
Notifications
You must be signed in to change notification settings - Fork 85
ExpectedExceptionToAssertThrows: Handle branching and var usage in except methods #721
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
base: main
Are you sure you want to change the base?
Conversation
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.
Some suggestions could not be made:
- src/main/resources/META-INF/rewrite/examples.yml
- lines 2399-2399
- lines 2408-2408
- lines 2583-2598
- lines 3392-3391
- lines 3427-3445
@timtebeek updated the PR summary to clearly justify the changes introduced in this update. |
Hi thanks! Didn't get to this one; there's been a lot to get to with codemix.ai next week, but we hope to get this in soon still. |
@timtebeek can you please take a look |
@MBoegers are you able to fit in a review here? Finding I'm not getting to this with travel & prep. |
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.
Some suggestions could not be made:
- src/main/resources/META-INF/rewrite/examples.yml
- lines 1535-1535
- lines 1817-1817
- lines 1825-1825
- lines 2251-2251
- lines 2265-2265
- lines 2399-2399
- lines 2408-2408
- lines 2443-2503
- lines 2576-2575
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.
Some suggestions could not be made:
- src/main/resources/META-INF/rewrite/examples.yml
- lines 1535-1535
- lines 1817-1817
- lines 1825-1825
- lines 2251-2251
- lines 2265-2265
- lines 2399-2399
- lines 2408-2408
- lines 2443-2503
- lines 2576-2575
What's Changed?
Previously, the
ExpectedExceptionToAssertThrows
recipe failed to correctly handle:expectMessage
argumentsWhen variables declared before the
thrown.expect(...)
calls were referenced in assertions, results in uncompilable code after transformation.Problem Example (Before)
Input:
Output (broken):
The updated recipe now wraps only the statements that appear after the thrown.expect call. Such that all the variables declared will be available in assert call scope.
Conditional Exception Handling
The updated recipe now also supports conditionally triggered exceptions, which were previously unhandled. These often appear in parameterized tests.
1. If-Else Conditional:
2. Single If Block:
The updated recipe correctly handles both patterns, including nested conditional blocks. (refer unit test to understand the transformation)
Additional Improvements
thrown.expectMessage(String)
to use Hamcrest matchers, aligning with the original behavior.Before:
After:
Anyone you would like to review specifically?
@timtebeek
Checklist