SONARJAVA-6605 Implement S9017: Mockito stubbing chains should be complete#5782
Conversation
| Boolean previous = isChained; | ||
| isChained = true; | ||
| scan(mit.methodSelect()); | ||
| // Scan lambda/anonymous-class arguments as independent chains (reset isChained so | ||
| // incomplete stubs inside their bodies are detected, but they are not part of this chain) | ||
| isChained = null; |
There was a problem hiding this comment.
Using an instance variable isChained and calling scan directly doesn't fill clean. Couldn't we have a recursive version of visitMethodInvocation that takes the equivalent of isChained as an argument.
romainbrenguier
left a comment
There was a problem hiding this comment.
It looks better. Thanks
Code Review ✅ Approved 3 resolved / 3 findingsImplements S9017 to detect incomplete Mockito stubbing chains with full test coverage, addressing previous issues regarding redundant parameters, variable assignments, and lambda scoping. ✅ 3 resolved✅ Edge Case: False positive: stub assigned to pre-declared variable
✅ Edge Case: Incomplete stubbings inside lambda/anonymous args not detected
✅ Quality: Redundant isChained parameter in isIncompleteStubbing
OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Gitar |
|
Code Review ✅ Approved 3 resolved / 3 findingsImplements S9017 to detect incomplete Mockito stubbing chains with full test coverage, addressing previous issues regarding redundant parameters, variable assignments, and lambda scoping. ✅ 3 resolved✅ Edge Case: False positive: stub assigned to pre-declared variable
✅ Edge Case: Incomplete stubbings inside lambda/anonymous args not detected
✅ Quality: Redundant isChained parameter in isIncompleteStubbing
OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Gitar |




Summary by Gitar
S9017to detect incomplete Mockito stubbing chains usingwhen()ordo*()methods.MockitoStubbingChainCheckSample.java.This will update automatically on new commits.