Repository navigation
Tighten preconditions that were too broad or too narrow - #1229
Merged
Merged
Conversation
23 of 76 tasks
…onditions-v1 # Conflicts: # src/main/resources/META-INF/rewrite/recipes.csv
…onditions-v1 # Conflicts: # src/main/java/org/openrewrite/java/testing/cleanup/TestMethodsShouldBeVoid.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 were gated on something nearly every file of their kind uses, so their visitors ran far more often than needed, while
KotlinTestMethodsShouldReturnUnitwas gated so narrowly that TestNG Kotlin tests, which its annotation matcher accepts, were never visited.Java recipes:
AdoptAssertJDurationAssertionsnow also requires a call onjava.time.Duration(UsesMethod("java.time.Duration *(..)")), as both rewrites need theassertThatargument to be a method call on aDuration. The AssertJisEqualTo/isGreaterThan/isLessThancheck alone matched almost every AssertJ file.RemoveIsMatchernow requiresis(Matcher)as well asMatcherAssert.assertThat.TestMethodsShouldBeVoidis gated on the four Jupiter annotations it actually checks, instead oforg..*Test.KotlinTestMethodsShouldReturnUnitnow also accepts files usingorg.testng.annotations.Test. TestNG skips test methods that return a value by default, so the conversion helps there too. A new test covers a TestNG Kotlin test, and it fails without the precondition change.Declarative recipes: the large relocation lists now sit behind an
org.openrewrite.java.search.HasTypeprecondition on the library's package glob, which covers every old type each list renames. A declarative precondition gates the whole recipe, build files included, so lists that were mixed with dependency changes moved into their own sub-recipe, at the same position in the parent:Testcontainers2ContainerClasseswas already pure Java, so it just getsorg.testcontainers..*next toSingleton.Wiremock3to4Migration: theChangeTypeblock moved intoWiremock4RelocatedTypes(com.github.tomakehurst.wiremock..*).MigrateTruthToAssertJ: the Truth Java recipes and theChangeMethodName/ChangeTypelist moved intoTruthCodeToAssertJ(com.google.common.truth..*). The Java recipes had to move too: a precondition is evaluated where its recipe sits in the list, andTruthAssertWithMessageToAssertJcan remove the last explicit Truth type before thehasLengthrename runs.EasyMockToMockito: everything between the dependency changes andMockitoBestPracticesmoved intoEasyMockCodeToMockito(org.easymock..*).MockitoBestPracticesstays ungated, as before. I checked that a subclass of anEasyMockSupportsubclass, with no EasyMock import, still passes the gate (supertypes count as types in use).recipes.csvwas regenerated with./gradlew recipeCsvGenerate.Verified with
./gradlew testonAdoptAssertJDurationAssertionsTest,AssertJBestPracticesTest,JUnit5BestPracticesTestand thehamcrest,cleanup,testcontainers,wiremock,truthandeasymockpackages: 645 tests, with one Truth failure that the sub-recipe split above fixed. After that change the YAML packages (186 tests) andKotlinTestMethodsShouldReturnUnitTestall pass.Fixes item M2 of #1211.