Add quick fix for Map.get(key) isEqualTo/isNotEqualTo(value)#5607
Add quick fix for Map.get(key) isEqualTo/isNotEqualTo(value)#56070 commit merged intoSonarSource:masterfrom
Map.get(key) isEqualTo/isNotEqualTo(value)#5607Conversation
SummaryAdds a new quick fix for AssertJ chain simplifications targeting What reviewers should knowKey files to review:
Testing:
Watch for:
|
There was a problem hiding this comment.
The PR introduces two duplicate simplifier registrations in the index — both sandwiching the newly inserted MAP_GET entries — which is a clear sign of copy-paste error during insertion. The test fixture also carries a stale [[quickfixes=!]] annotation on the Map case that will break once the quick fix is wired in.
Note: the ActualKeyExpectedQuickFix class and the updated quick-fix wiring (changing msgWithActualCustom to use the new class) could not be confirmed in the available repository state, so reviewers should verify those additions are present and correct in the actual diff.
Note — the following observations could not be attached as inline comments:
java-checks/src/main/java/org/sonar/java/checks/tests/AssertJChainSimplificationIndex.java:156: This line is a duplicate of line 154 — both registerPATH_GET_PARENT_AND_PARENT_FILE→hasParentRawin theIS_EQUAL_TOblock. TheMAP_GETentry was inserted between them, but the trailing copy was not removed. The second occurrence is dead code becausefindFirst()incheckPredicatesForSimplificationwill always match line 154 first.
Remove this line.
java-checks/src/main/java/org/sonar/java/checks/tests/AssertJChainSimplificationIndex.java:199: This line is a duplicate of line 197 — both registerTRIM/isEmptyString→isNotBlankin theIS_NOT_EQUAL_TOblock. Same pattern as thehasParentRawduplicate: theMAP_GETentry was inserted between two copies of what should have been a single entry. The second occurrence is dead code.
Remove this line.
java-checks-test-sources/default/src/test/java/checks/tests/AssertJChainSimplificationCheckTest_QuickFix.java:109: This line currently asserts[[quickfixes=!]]— i.e., that no quick fix is available for theMap.getcase. OnceActualKeyExpectedQuickFixis wired in, this test will fail because a quick fix will be offered.
This line must be updated (or moved to the new Map-specific quick-fix fixture) to assert the expected fix@ and edit@ annotations for the containsEntry rewrite. Leaving it as-is will cause the test suite to fail.
4d4c321
|
@NoemieBenard hey, I'm sorry, I'm not sure what happened here — somehow there are 0 changes in my PR, should I create a new one with the fixes requested? |
Wires a quick fix for the AssertJ chain simplifications targeting
Map.get(key): rewritesassertThat(map.get(k)).isEqualTo(v)toassertThat(map).containsEntry(k, v), and theisNotEqualTovariant todoesNotContainEntry. Adds the new
ActualKeyExpectedQuickFixwhichcombines the inner-call argument with the predicate argument, plus
positive (
Map,HashMap) and negative (non-Map.get) tests.