Repository navigation
Hoist matchers created per visit to private static final constants - #1225
Merged
Merged
Conversation
51 of 76 tasks
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 built a new
MethodMatcherorAnnotationMatcherfor every visited method, class or annotation, or kept constant matchers as visitor instance fields. Matcher construction parses the signature, so these now live asprivate static finalconstants on the recipe class. Existing lower-camel static matcher fields in the same files are renamed to UPPER_SNAKE. Behaviour is unchanged.What changed:
AssertTrueInstanceofToAssertInstanceOf,EnclosedToNested,UpdateBeforeAfterAnnotations(now a static map of JUnit 4 to Jupiter matchers),ReplaceMockitoTestExecutionListener(@ExtendWith), andMockitoJUnitRunnerToExtension. InMockitoJUnitRunnerToExtensionthe visitor's string fields became staticAnnotationMatchers, which are passed toAnnotated.Matcherdirectly.LifecycleNonPrivate,AssertionsArgumentOrder(newListMatchers),ReplaceInitMockToOpenMock(EXCEPTION_CLASS_NAME),ReplaceArquillianInSequenceAnnotation, and the option-independent matchers inHamcrestMatcherToAssertJandHamcrestNotMatcherToAssertJ.AddMissingNested.hasTestMethodsranFindAnnotations.findonce per test annotation for every class declaration, and each call builds a recipe and a matcher. It now walks the class once with a small visitor that checks the annotations against static matchers. This matches the same annotations anywhere in the class subtree, as before.UseWiremockExtension,AssertionsArgumentOrder,RemoveTimesZeroAndOne.Not made static:
matchersMatcherdepends on the recipe option, so it stays a visitor instance field, which is built once per visitor. InHamcrestNotMatcherToAssertJit is renamed fromMATCHERS_MATCHERto lower camel case, since it isn't a constant.MockitoWhenOnStaticToMockStaticbuilds its before/after matchers from the annotation found on the setup method. They are now built once per stubbing, beforedoAfterVisit, instead of once per statement and per method declaration visited by the follow-up visitor.Verified with
./gradlew test --testson the test classes of all 15 recipes plusJUnit5MigrationTest,MockitoJUnitToMockitoExtensionTest,MigrateHamcrestToAssertJTest,JunitMockitoUpgradeIntegrationTestandMockito1to5MigrationTest: 331 tests, 0 failures, 5 skipped.Fixes item N6 of #1211.