Skip to content

Use @InjectMocks in controller tests#69

Merged
igorsatsyuk merged 1 commit into
masterfrom
agent/sonar-injectmocks-tests
Jul 22, 2026
Merged

Use @InjectMocks in controller tests#69
igorsatsyuk merged 1 commit into
masterfrom
agent/sonar-injectmocks-tests

Conversation

@igorsatsyuk

Copy link
Copy Markdown
Owner

What changed

  • switched AccountControllerTest to Mockito-managed injection with @InjectMocks
  • switched GlobalExceptionHandlerTest to Mockito-managed injection with @InjectMocks
  • removed manual test object construction that Sonar flagged as a maintainability smell

Why

Sonar reported both tests for declaring mock fields but manually constructing the class under test instead of letting Mockito inject those mocks.

Impact

The tests keep the same behavior, but align better with the Mockito setup already declared in each class and remove redundant setup code.

Validation

  • mvn -B "-Dtest=AccountControllerTest,GlobalExceptionHandlerTest" test

@igorsatsyuk igorsatsyuk self-assigned this Jul 22, 2026
@igorsatsyuk
igorsatsyuk marked this pull request as ready for review July 22, 2026 14:35
@igorsatsyuk
igorsatsyuk merged commit e0d5ad7 into master Jul 22, 2026
2 checks passed
@igorsatsyuk
igorsatsyuk deleted the agent/sonar-injectmocks-tests branch July 22, 2026 14:36
@sonarqubecloud

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