After the update to 8.7.1. a new issue is reported. “Add an “eq()” argument matcher on this parameter.” java:S6073 but it is not the case. We know this because the test runs. The reason seems to be that the argument matcher is created in the extracted method, that is used serveral times in the tests class.
-
version used
SonarQube ID information
Server ID: A7EE8CF2-AWNfJ7jrUMoe9cI1imbB
Version: 8.7.1.42226
Date: 2021-03-18 -
This code raises the issue.
@Test
void testAddDataSetFavorite() throws Exception {
// when added to the service
favoriteService.addFavorite(dataset2Favorite);
// then it is added and persisted
assertThat(favoriteService.getFavorites()).containsOnly(bundle1Favorite, dataset1Favorite, dataset2Favorite);
verify(spiedPersistedStateMap).put(eq(FavoriteService.FAVORITE_SERVICE_FAVORITES),
contains(bundle1Favorite, dataset1Favorite, dataset2Favorite));
verifyEventPosted(bundle1Favorite, dataset1Favorite, dataset2Favorite);
}
private String contains(Favorite... favorites) {
ArgumentMatcher<String> matcher = actualJson -> Stream.of(favorites)
.allMatch(favorite -> actualJson.contains(favorite.getName()));
return argThat(matcher);
}
- This code does not raise the issue
@Test
void testAddDataSetFavorite() throws Exception {
// when added to the service
favoriteService.addFavorite(dataset2Favorite);
// then it is added and persisted
assertThat(favoriteService.getFavorites()).containsOnly(bundle1Favorite, dataset1Favorite, dataset2Favorite);
verify(spiedPersistedStateMap).put(eq(FavoriteService.FAVORITE_SERVICE_FAVORITES),
argThat(contains(bundle1Favorite, dataset1Favorite, dataset2Favorite)));
verifyEventPosted(bundle1Favorite, dataset1Favorite, dataset2Favorite);
}
private ArgumentMatcher<String> contains(Favorite... favorites) {
ArgumentMatcher<String> matcher = actualJson -> Stream.of(favorites)
.allMatch(favorite -> actualJson.contains(favorite.getName()));
return matcher;
}
Wrap code around triple quote ``` for proper formatting