-
Notifications
You must be signed in to change notification settings - Fork 79
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
Collapse consecutive AssertJ assertThat(..)
statements that each use the same object to a single statement
#373
Comments
Perhaps @pstreef can provide some pointers on the implementation here if he's willing to share, as I know he's done some similar work recently in an unrelated project. To be sure: I don't expect him to pick this up, but the general approach of collapsing subsequent calls to a more fluent invocation seems familiar. :) |
Sure thing @timtebeek! In most of the cases these assertions happen in the same method (maybe only work on I would only focus on local variables to start with, and maybe extend to global if it makes sense. Method invocation should not be considered as the return values do not have to always be the same for subsequent calls. I would only take into account calls that are consecutive, because if there is any other statement in between that could change the variable being asserted:
To get starter you will either have to start from a Alternatively you can start from Make sure to:
Then chain those calls by appending each chained call to the next one and ending with the Edge cases to test for:
|
* added recipe to collapse consecutive AssertThat statements (#373) * Apply formatter and remove unused builder * fixed formatting (#373) * Fix test indentation and type issues * Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update src/main/java/org/openrewrite/java/testing/assertj/CollapseConsecutiveAssertThatStatements.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Apply suggestions from code review * Strip out unnecessary elements from tests * Remove test with compilation error * First round of conventions applied * Apply quick old suggestion * Showcase an issue with incorrect use of `extracting` * Alternative implementation without index or nested visitors just yet * Compare types for the last unit test to pass * Further simplification * Remove need for autoformat * Do not duplicate indent, but guess continuation indent * Make collapse of assertThat part of best practices * Only retain last newline --------- Co-authored-by: Tim te Beek <[email protected]> Co-authored-by: Tim te Beek <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
What problem are you trying to solve?
What precondition(s) should be checked before applying this recipe?
Only consecutive calls; not when interleaved with others.
Only when the asserted object does not change; so for instance no calls to
extracting("baz")
, as that would change the semantics.Describe the situation before applying the recipe
Describe the situation after applying the recipe
Any additional context
Would help clean up after the migration from Hamcrest
allOf(Matcher...)
to individual statements.The text was updated successfully, but these errors were encountered: