Repository navigation
Run unconditional sub-recipes from getRecipeList() and keep cleanups local to the changed element - #1230
Merged
Conversation
23 of 76 tasks
…-recipes-v1 # Conflicts: # src/main/java/org/openrewrite/java/testing/arquillian/ReplaceArquillianInSequenceAnnotation.java
…-recipes-v1 # Conflicts: # src/main/java/org/openrewrite/java/testing/junit5/AssertToAssertions.java # src/main/java/org/openrewrite/java/testing/junit5/RemoveObsoleteRunners.java
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 queued
ChangeType-style sub-recipes throughdoAfterVisitfor every file they visited, or ran whole-file cleanups (LambdaBlockToExpression,RemoveUnusedImports) that also rewrote code the recipe never touched. Sub-recipes that only act on their own matches belong ingetRecipeList(), and cleanups should stay limited to the element the recipe changed.Moved to
getRecipeList(). Each of these sub-recipes is gated on the same type the recipe's precondition checks, so the scope stays the same:UpdateBeforeAfterAnnotations: the four lifecycleChangeTypes. The visitor is now justRemoveRedundantJUnit4LifecycleAnnotations, which still runs first because a recipe's own visitor runs before its recipe list.UseWiremockExtension:ChangeType(WireMockRule, WireMockExtension).ReplaceArquillianInSequenceAnnotation:ChangeType(InSequence, Order).MockUtilsToStatic:ChangeMethodTargetToStatic. It used to run fromvisitCompilationUnit, so Java files only.Local instead of whole-file.
AssertThrowsOnLastStatementandExpectedExceptionToAssertThrowsrunLambdaBlockToExpressiononly on theassertThrowscall they produced.JMockitMockUpToMockitoruns it only on the method it rewrote.AssertThrowsOnLastStatementkeeps the old Java-only behaviour, becauseLambdaBlockToExpression'sJavaFileCheckerdoes not apply when its visitor runs on a subtree.JUnitFailToAssertJFailusesmaybeRemoveImportonorg.junit.jupiter.api.Assertionsinstead ofRemoveUnusedImports.RemoveDoNothingForDefaultMockscallsmaybeRemoveImportfor each type, method owner and field owner that the removed stubbing referenced, instead ofRemoveUnusedImports.RemoveObsoleteRunnersandJUnitParamsRunnerToParameterizedremove the@RunWithannotation from the class they visit, instead of queuing a file-wideRemoveAnnotationvisitor per class.RemoveObsoleteRunnersstays a visitor, becauseMockitoJUnitRunnerToExtensioncalls itsgetVisitor().AssertToAssertionsused to queue oneChangeMethodTargetToStaticperAssertcall. It now collects the method names and queues one per distinct name at the end of the file.Skipped
MigrateJUnitTestCase: its precondition excludesTestCases that overriderun(TestResult). ItsChangeTypes andUseStaticImports would also run on those files, and on any file using JupiterAssertions, from the recipe list.TestRuleToTestInfo:ChangeType(org.junit.Before, BeforeEach)would then run on every file using@Before, not just those with aTestNamerule.AnyToNullable: the sub-recipes are gated on the scanning recipe's accumulator (amockito-alldependency somewhere), which a recipe list cannot see.AssertToAssertionsmatchUnknownTypes = true: kept on purpose.missingTypeInfoandmigratesAssertStatementsWithMissingTypeInforely on it for unresolved JUnit 4 types.Verified with
./gradlew teston the tests of every touched recipe and the composites that include them:JUnit5MigrationTest,Mockito1to{3,4,5}MigrationTest,JunitMockitoUpgradeIntegrationTest,MockitoJUnitRunnerToExtensionTest,ArquillianJUnit4ToArquillianJunit5Test, thewiremockandjmockitpackages. The first run had 330 tests (1 skipped) and the separatejmockitpackage run had 92, all passing, with no test changes needed.Fixes item N4 of #1211.