Skip to content

SONARJAVA-6604 Implement S9016: Mock objects should not be created inline within "thenReturn()"#5794

Draft
NoemieBenard wants to merge 3 commits into
masterfrom
nb/sonarjava-6604-implement-S9016
Draft

SONARJAVA-6604 Implement S9016: Mock objects should not be created inline within "thenReturn()"#5794
NoemieBenard wants to merge 3 commits into
masterfrom
nb/sonarjava-6604-implement-S9016

Conversation

@NoemieBenard

@NoemieBenard NoemieBenard commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Summary by Gitar

  • New Rule Implementation:
    • Added MockitoInlineMockInThenReturnCheck to detect mock creation inside thenReturn() calls.
    • Created rule documentation and metadata files for S9016.
  • Testing & Infrastructure:
    • Implemented unit tests for the new rule including semantic analysis verification.
    • Integrated rule into the test suite and updated autoscan/ruling test expectations.

This will update automatically on new commits.

@hashicorp-vault-sonar-prod

hashicorp-vault-sonar-prod Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

SONARJAVA-6604

@github-actions

Copy link
Copy Markdown
Contributor

Ruling Diff Summary

Detected changes in 1 rule files: 0 issues removed, 7 issues added.

S9016 (java) on sonar-server - 0 issues removed, 7 issues added - new ruling file

Added src/test/java/org/sonar/server/app/TomcatContextsTest.java (line 60)

(source file not found at this revision: src/test/java/org/sonar/server/app/TomcatContextsTest.java)

Added src/test/java/org/sonar/server/authentication/OAuth2CallbackFilterTest.java (line 75)

(source file not found at this revision: src/test/java/org/sonar/server/authentication/OAuth2CallbackFilterTest.java)

Added src/test/java/org/sonar/server/issue/ws/ComponentTagsActionTest.java (line 93)

(source file not found at this revision: src/test/java/org/sonar/server/issue/ws/ComponentTagsActionTest.java)

Added src/test/java/org/sonar/server/issue/ws/ComponentTagsActionTest.java (line 117)

(source file not found at this revision: src/test/java/org/sonar/server/issue/ws/ComponentTagsActionTest.java)

Added src/test/java/org/sonar/server/plugins/StaticResourcesServletTest.java (line 145)

(source file not found at this revision: src/test/java/org/sonar/server/plugins/StaticResourcesServletTest.java)

Added src/test/java/org/sonar/server/rule/RegisterRulesTest.java (line 486)

(source file not found at this revision: src/test/java/org/sonar/server/rule/RegisterRulesTest.java)

Added src/test/java/org/sonar/server/rule/WebServerRuleFinderImplTest.java (line 41)

(source file not found at this revision: src/test/java/org/sonar/server/rule/WebServerRuleFinderImplTest.java)

@gitar-bot

gitar-bot Bot commented Jul 15, 2026

Copy link
Copy Markdown
Code Review ✅ Approved

Implements S9016 to prevent inline mock creation within thenReturn() calls, including full test coverage and rule metadata. No issues found.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing less information.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

@sonarqube-next

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant