Repository navigation
Track Hamcrest not(..) negation locally instead of on the ExecutionContext - #1214
Merged
Merged
Conversation
…nContext` `RemoveNotMatcherVisitor` stored whether a matcher was negated on the `ExecutionContext`, keyed by the printed matcher, so a negation leaked into later assertions with the same matcher text: `assertThat(a, not(nullValue())); assertThat(b, nullValue());` became `assertNotNull(a); assertNotNull(b);`, and `not(not(x))` threw a `NullPointerException`. `HamcrestMatcherToJUnit5` and `HamcrestInstanceOfToJUnit5` now flip the negation for each `not(..)` layer they unwrap, and the hamcrest tests no longer disable the immutable execution context check that would have caught this.
23 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.
HamcrestMatcherToJUnit5remembered whether an assertion was negated on theExecutionContext, keyed by the printed matcher, so anot(..)in one assertion flipped every later assertion with the same matcher text:became
assertNotNull(a); assertNotNull(b);. The same state was shared withHamcrestInstanceOfToJUnit5, andnot(not(x))failed with aNullPointerException.Both recipes now count the
not(..)layers they unwrap, so the result above isassertNotNull(a); assertNull(b);andnot(not(nullValue()))becomesassertNull(..). The hamcrest tests no longer turn off the immutable execution context check, soRewriteTestguards against this coming back.Fixes item E1 of #1211.