Repository navigation
Declare what templates name and build trees as the parser does - #1197
Merged
Merged
Conversation
The templates of SimplifyChainedAssertJAssertion, SimplifyArrayLengthAssertion, AdoptAssertJDurationAssertions and SimplifyHasSizeFromIsEqualToAssertion wrote `assertThat(..)` and resolved it only through the static import of the file they were applied to. On code that calls `Assertions.assertThat(..)` qualified, the call they wrote had no type and the output didn't import it. Each template now declares the `assertThat` of the call it replaces, read from that call's method type, and the output imports it. SimplifyChainedAssertJAssertion also declares `java.nio.file.Path` where it writes `Path.of(..)`. A new rewriteRun check in rewrite-test fails tests on templates that name what they don't declare. Four tests are added for fully qualified `assertThat` calls.
For a qualified `Assertions.assertTrue(..)`, the template declared `org.junit.jupiter.api.Assertions.assertEquals` as a type import, so the `Assertions` it writes resolved only through the file's own import. It now declares `org.junit.jupiter.api.Assertions`, and the output imports it where the call was fully qualified. A new rewriteRun check in rewrite-test fails tests on templates that name what they don't declare.
The field ScopedMocks declares, such as `MockedStatic<Calendar>`, and the `when`, `verify` and dynamic `when` calls PowerMockitoMockStaticToMockito writes, such as `Calendar::getInstance`, name the mocked class by its class name. Their templates resolved it only through the imports of the test they were applied to. They now declare the class's top-level type by its fully qualified name, unless it is in the default package, `java.lang` or the test's package. The field and the dynamic `when` also import it, so a mocked class written fully qualified still works. A new rewriteRun check in rewrite-test fails tests on templates that name what they don't declare.
…grateJUnitTestCase
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Several recipes wrote templates that name a type or static member without declaring it, so the name resolved only through the imports of the file the template was applied to. The AssertJ templates wrote
assertThat(..)that way. On code that callsAssertions.assertThat(..)qualified, they made an untyped call and added no import. They now declare theassertThatof the call they replace, read from its method type, and the output imports it. The PowerMock migrations declare and import the mocked class they name. AssertTrueEqualsToAssertEquals declaresorg.junit.jupiter.api.Assertionswhere it declared a method as a type.Two recipes built trees that their parser doesn't make of the text they print. ArgumentMatcherToLambda's lambda parameter is now a declaration without a type, not an identifier. MigrateJUnitTestCase removes
setName(..)and keeps its text as a comment. It used to hide the call behind an empty//, and that hidden call folded the static imports of one test into*. That test and its example now import two methods by name.New rewriteRun checks in rewrite-test fail tests on both problems. Four tests are added for fully qualified
assertThatcalls.