Must-share information (formatted with Markdown):
- which versions are you using:
- SonarQube Enterprise Edition v10.6 (92116)
Hello Sonar team,
Looks like we have a false positive in our tests with java:S1144 Remove this unused private when using @ParametrizedTest
and @MethodSource
.
When using @MethodSource
without any parameter JUnit will search for a source method with the same name than the test method.
In our example, SQ raise an issue on the private static Stream<Arguments> should_throw_exception_on_unsuccessful_batch_status()
private static Stream<Arguments> should_throw_exception_on_unsuccessful_batch_status() {
return Stream.of(
Arguments.of(BatchStatus.FAILED),
Arguments.of(BatchStatus.ABANDONED),
Arguments.of(BatchStatus.UNKNOWN)
);
}
@ParameterizedTest
@MethodSource
void should_throw_exception_on_unsuccessful_batch_status(BatchStatus batchStatus) throws Exception {
//GIVEN
Job job = mock(Job.class);
doReturn(job).when(jobStrategyResolver).getJob(ReportingType.CRS);
JobExecution jobExecution = mock(JobExecution.class);
doReturn(batchStatus).when(jobExecution).getStatus();
doReturn(jobExecution).when(jobLauncher).run(eq(job), any());
//WHEN //THEN
assertThatExceptionOfType(BatchRuntimeException.class)
.isThrownBy(() -> commandLineJobRunner.run());
}
I believe this is clearly a false positive
With
Xav