Skip to content

Conversation

fmodesto
Copy link
Contributor

Summary
Refactor a few Refaster recipes by moving type variable declarations from the method level to the class level. This ensures consistency between before() and after() templates.

Motivation
OpenRewrite doesn’t support method-level generic type variables, which can result in incorrect or uncompilable replacements.

@rickie rickie requested review from Stephan202 and rickie and removed request for Stephan202 April 18, 2025 23:25
@Stephan202 Stephan202 added this to the 0.23.0 milestone Apr 19, 2025
.toIterable()
.containsExactlyElementsOf(
copyOf(Iterators.unmodifiableIterator(new ArrayList<>().iterator())));
assertEquals(
Copy link
Contributor

@mohamedsamehsalah mohamedsamehsalah Apr 20, 2025

Choose a reason for hiding this comment

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

I'd say we can omit the negative matches; it's not a pattern I see often in the tests. Up to @Stephan202

Copy link
Member

Choose a reason for hiding this comment

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

Indeed we generally don't do this, though we do for @Matches. Ideally we do move towards such more accurate testing, but that'd be quite an undertaking.

I'm fine with keeping the next tests, but do think we should then apply the changes consistently; will push a proposal.

Copy link
Contributor

@mohamedsamehsalah mohamedsamehsalah left a comment

Choose a reason for hiding this comment

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

Thanks 💪

@Stephan202 Stephan202 force-pushed the share_generics_within_the_rule branch from b59260a to da8330d Compare April 21, 2025 13:01
Copy link
Member

@Stephan202 Stephan202 left a comment

Choose a reason for hiding this comment

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

Rebased and added a commit. Thanks for this contribution @fmodesto!

Suggested commit message:

Improve `TestNGToAssertJRules` generic type constraints (#1645)

.toIterable()
.containsExactlyElementsOf(
copyOf(Iterators.unmodifiableIterator(new ArrayList<>().iterator())));
assertEquals(
Copy link
Member

Choose a reason for hiding this comment

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

Indeed we generally don't do this, though we do for @Matches. Ideally we do move towards such more accurate testing, but that'd be quite an undertaking.

I'm fine with keeping the next tests, but do think we should then apply the changes consistently; will push a proposal.

}

static final class AssertEqualIteratorIterationOrder {
static final class AssertEqualIteratorIterationOrder<S, T extends S> {
Copy link
Member

Choose a reason for hiding this comment

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

While more correct, this means that sometimes assertion statements won't be migrated. I'll add a note to track this limitation, for future improvements.

Iterators.unmodifiableIterator(new ArrayList<>().iterator()));
assertEquals(
Iterators.unmodifiableIterator(new ArrayList<String>().iterator()),
Iterators.unmodifiableIterator(new ArrayList<Number>().iterator()));
Copy link
Member

Choose a reason for hiding this comment

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

Looks like we can omit the unmodifiableIterator and synchronizedCollection wrappers. I might have introduced those in the past for consistency, but will drop them now.

Comment on lines 940 to 945
// XXX This rule fails for `java.nio.file.Path` as it is `Iterable`, but AssertJ's
// `assertThat(Path)` does not support `.containsExactlyElementsOf`.
Copy link
Member

Choose a reason for hiding this comment

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

This comment also applies to the rule below. Will copy it over.

@Stephan202
Copy link
Member

Looks like one of the GitHub Actions builds hung; pushed an empty commit.

Copy link
Contributor

@mohamedsamehsalah mohamedsamehsalah left a comment

Choose a reason for hiding this comment

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

Thanks for the changes @fmodesto ! 🚀

Suggestions LGTM @Stephan202 🙏

@Stephan202
Copy link
Member

Ah, I should have pressed the button to approve running of the workflows 🤦

Copy link

Looks good. No mutations were possible for these changes.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

@Stephan202 Stephan202 merged commit bc351a7 into PicnicSupermarket:master Apr 21, 2025
16 checks passed
@Stephan202 Stephan202 changed the title Share same generic parameters with the templates Improve TestNGToAssertJRules generic type constraints Apr 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants