I think I may have stumbled across a false positive of the rule java:S5979 / Annotated Mockito objects should be initialized.
We use the mockito rule with additional configuration of strict stubs (see example). If I remove the strictness call the violation disappears.
import org.junit.Rule;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.mockito.quality.Strictness;
public class SomeTest {
@Rule
public MockitoRule mockitoRule = MockitoJUnit.rule().strictness(Strictness.STRICT_STUBS);
@Mock
private SomeType someMock;
@Test
public void someTest() {
// ...
}
}
This is running against sonarcloud.io.