False positive on java:S6073

Hi SonarLint & Language team,

Found a false positive on rule S6073 - Mockito argument matchers should be used on all parameters

An issue is raised by this rule when I use an argument matcher defined in another method, example:

import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;

import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.BDDMockito.given;

@Test
public void dummyTest() {
   given(dummyClass.findAll(eqCollection(1L), eq(17))).willReturn(emptyList())
}

private Collection<Long> eqCollection(Long... items) {
   argThat( c -> c.size() == items.length() && c.containsAll(asList(items)))
}

With the message Add an eq() argument matcher on this parameter
on the line

given(dummyClass.findAll(eqCollection(1L), eq(17))).willReturn(emptyList())

Looks like my method eqCollection is not recognized as an argumentMatcher

Using:

  • SonarLint for IntelliJ version 4.14.2.28348
  • Java Code analyzer version 6.12.0.24852
  • Java 15.0.2

With :heart:
Xavier

4 Likes

Hey @Xav,

Thank you for reporting the issue. There is indeed an issue with the current implementation of the rule as it only checks the return type of the method invoked and not the actual value.
To suppress the noise, the rule has been moved out of the SonarWay profile and a ticket has been created to handle it.

Cheers,

Dorian

2 Likes

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