Repository navigation
Only replace assertNotEquals(false, <boolean>) when the second argument is a primitive boolean - #1220
Merged
Merged
Conversation
…ment is a primitive `boolean`
`AssertNotEqualsBooleanToAssertBoolean` rewrote `assertNotEquals(false, x)` to `assertTrue(x)` for any `x`. With a `Map<String, Object>`, `assertNotEquals(false, map.get("k"))` became `assertTrue(map.get("k"))`, which does not compile, and with a `Boolean` holding `null` a passing assertion became an unboxing `NullPointerException`. Require a primitive `boolean`, as `AssertEqualsBooleanToAssertBoolean` already does.
10 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.
AssertNotEqualsBooleanToAssertBooleanrewroteassertNotEquals(false, x)toassertTrue(x)without checking the type ofx, unlike its siblingAssertEqualsBooleanToAssertBoolean. With aMap<String, Object> map,assertNotEquals(false, map.get("k"))becameassertTrue(map.get("k")), which does not compile.The recipe now only rewrites when the second argument is a primitive
boolean, the same check the sibling uses. Boxedjava.lang.Booleanis left alone on purpose:assertNotEquals(false, (Boolean) null)passes, butassertTrue((Boolean) null)throws aNullPointerExceptionon unboxing, so the rewrite would turn a passing test into a failing one. This is stricter than the sibling needs to be, but it matches what the sibling already does withBoolean. New no-change tests cover theObjectandBooleancases. Both fail without the fix.Verified with
./gradlew test --tests 'org.openrewrite.java.testing.cleanup.*' --tests 'org.openrewrite.java.testing.junit5.CleanupAssertionsTest': 162 tests, 0 failures.This covers only the probed part of C7; the other C7 entries (
AssertionsArgumentOrder,SimplifyTestThrowsand the suspected ones) are left for separate PRs.Fixes item C7 of #1211.