False positive on Java S5979 when using TestNG

Hey SonarSource team :kissing_heart:

I think I found a false positive for the rule 5979 - Annotated Mockito objects should be initialized

The rule is raised on the declaration of my mock in this code

import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.testng.MockitoTestNGListener;

public class TestClass {
   private MyMockedClass mockedClass;

   private MyClassWithInjectdMocks myClass;


I believe that using the @Listeners(MockitoTestNGListener.class) is the equivalent of @RunWith(MockitoJUnitRunner.class) when using JUnit and this rule should not be raised here.

with :heart:


PS: Iā€™m using SonarLint for IntelliJ version :wink:


Hello @Xav,
Thanks for reporting the issue and welcome to the community :wink:
Indeed, the current implementation of the rule does not take TestNG annotations into account.
A ticket has been created to handle the issue.



1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.