Hi,
I’m using Java with SonarCloud & SonarLint (plugin 7.4.0.60471 for IntelliJ).
I am having what I consider false-positive for the rule java:S5778 “Only one method invocation is expected when testing runtime exceptions”
I think there are some cases where it can be known that some method won’t raise an exception and it should be accepted in order to increase readability. I think it could work as a whitelist of methods.
@Test
public void testAnswerWithNonExistingTask() throws ServiceException {
Assertions.assertThatThrownBy(() -> service.answer("not-a-task", "user", Collections.emptyMap()))
.isInstanceOf(NotFoundException.class);
}
In this case, I know that Collections.emptyMap()
won’t fail and adding a temporary variable to hold it does not improve readability. I also tried with Map.of()
instead but the same issue exists.
Regards,