SONARJAVA-5708 Implement rule S8924: Mockito core methods should be imported statically#5689
Conversation
rombirli
left a comment
There was a problem hiding this comment.
LGTM, small improvement suggestion
|
|
||
| private static final Set<String> MOCKITO_METHODS = Set.of( | ||
| "doReturn", "doThrow", "mock", "never", "spy", "times", "verify", "when" | ||
| ); |
There was a problem hiding this comment.
Optional : it would better to create method matchers like here
| } | ||
| MemberSelectExpressionTree mset = (MemberSelectExpressionTree) methodSelect; | ||
| String methodName = mset.identifier().name(); | ||
| if (MOCKITO_METHODS.contains(methodName) && mset.expression().symbolType().is(MOCKITO_CLASS)) { |
There was a problem hiding this comment.
this would become
MOCKITO_METHODS.matches(mit.methodSymbol())
|
Code Review ✅ Approved 3 resolved / 3 findingsImplements rule S8924 to enforce static imports for Mockito methods, resolving missing metadata files and redundant receiver-type checks. No issues remain. ✅ 3 resolved✅ Bug: Missing rule metadata files S8924.json / S8924.html
✅ Quality: Redundant receiver-type check after MethodMatchers migration
✅ Quality: S8924 declares "quickfix":"targeted" but no quick fix is implemented
OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change:
Was this helpful? React with 👍 / 👎 | Gitar |




Summary by Gitar
MockitoStaticImportCheck(ruleS8924) to enforce static imports for common Mockito methods.mock,when,verify,spy,any, andeqwhen called viaMockito.qualifier.MockitoStaticImportCheckTestand corresponding sample fileMockitoStaticImportCheckSample.javato verify rule reporting.This will update automatically on new commits.