aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-dao
diff options
context:
space:
mode:
authorMatteo Mara <matteo.mara@sonarsource.com>2023-01-10 15:16:50 +0100
committersonartech <sonartech@sonarsource.com>2023-01-10 20:03:01 +0000
commit54b60b1adac5b703398163ee5edf5a621efc0d24 (patch)
tree2c4595fea6ddefca2b5f33cc9c26000ffb5750ce /server/sonar-db-dao
parent295a87208f8c9898fbdc733a438587dc03a16877 (diff)
downloadsonarqube-54b60b1adac5b703398163ee5edf5a621efc0d24.tar.gz
sonarqube-54b60b1adac5b703398163ee5edf5a621efc0d24.zip
[NO-JIRA] Remove reported code smells about usages of toList
Diffstat (limited to 'server/sonar-db-dao')
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java3
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDao.java3
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDao.java2
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/component/ScrollForFileMoveComponentDaoTest.java3
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotDaoTest.java6
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/event/EventDaoTest.java2
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/metric/MetricDaoTest.java9
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java4
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/source/FileSourceDaoTest.java4
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/webhook/WebhookDeliveryTesting.java3
10 files changed, 17 insertions, 22 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java
index f09ae4a1191..782981eacad 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java
@@ -26,7 +26,6 @@ import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.function.Predicate;
-import java.util.stream.Collectors;
import javax.annotation.Nullable;
import org.sonar.api.utils.DateUtils;
import org.sonar.api.utils.System2;
@@ -199,7 +198,7 @@ public class PurgeDao implements Dao {
List<String> branchUuids = session.getMapper(BranchMapper.class).selectByProjectUuid(uuid).stream()
.map(BranchDto::getUuid)
.filter(branchUuid -> !uuid.equals(branchUuid))
- .collect(Collectors.toList());
+ .toList();
branchUuids.forEach(id -> deleteRootComponent(id, purgeMapper, purgeCommands));
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDao.java
index 9a04bb540b3..8a332eeba65 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDao.java
@@ -28,7 +28,6 @@ import java.util.Optional;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Function;
-import java.util.stream.Collectors;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rules.RuleQuery;
import org.sonar.core.util.UuidFactory;
@@ -159,7 +158,7 @@ public class RuleDao implements Dao {
List<String> templateRuleUuids = ruleDtos.stream()
.map(RuleDto::getTemplateUuid)
.filter(Objects::nonNull)
- .collect(Collectors.toList());
+ .toList();
Map<String, RuleDto> templateDtos = findTemplateDtos(mapper, templateRuleUuids);
ruleDtos.stream().map(r -> toRuleForIndexingDto(r, templateDtos)).forEach(consumer);
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDao.java
index 12df2a2a179..22beed6aea9 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDao.java
@@ -95,7 +95,7 @@ public class UserDao implements Dao {
return logins.stream()
.map(new LoginToUser(unordered))
.filter(Objects::nonNull)
- .collect(Collectors.toList());
+ .toList();
}
public List<UserDto> selectUsers(DbSession dbSession, UserQuery query) {
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ScrollForFileMoveComponentDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ScrollForFileMoveComponentDaoTest.java
index 8eb96fe9eda..789584f4406 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ScrollForFileMoveComponentDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ScrollForFileMoveComponentDaoTest.java
@@ -25,7 +25,6 @@ import com.tngtech.java.junit.dataprovider.UseDataProvider;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
-import java.util.stream.Collectors;
import java.util.stream.IntStream;
import org.apache.ibatis.session.ResultContext;
import org.apache.ibatis.session.ResultHandler;
@@ -129,7 +128,7 @@ public class ScrollForFileMoveComponentDaoTest {
FileSourceDto fileSource = db.fileSources().insertFileSource(file);
return new ComponentAndSource(file, fileSource);
})
- .collect(Collectors.toList());
+ .toList();
RecordingResultHandler resultHandler = new RecordingResultHandler();
underTest.scrollAllFilesForFileMove(dbSession, project.uuid(), resultHandler);
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotDaoTest.java
index d62e758b6f8..04b691f84d2 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotDaoTest.java
@@ -230,7 +230,7 @@ public class SnapshotDaoTest {
.mapToObj(j -> db.components().insertSnapshot(project));
})
.flatMap(t -> t)
- .collect(toList());
+ .toList();
assertThat(underTest.selectAnalysesByQuery(db.getSession(), new SnapshotQuery()))
.extracting(SnapshotDto::getUuid)
@@ -244,10 +244,10 @@ public class SnapshotDaoTest {
ComponentDto project2 = db.components().insertPrivateProject();
List<SnapshotDto> snapshots1 = IntStream.range(0, 1 + random.nextInt(20))
.mapToObj(j -> db.components().insertSnapshot(project1))
- .collect(toList());
+ .toList();
List<SnapshotDto> snapshots2 = IntStream.range(0, 1 + random.nextInt(20))
.mapToObj(j -> db.components().insertSnapshot(project2))
- .collect(toList());
+ .toList();
assertThat(underTest.selectAnalysesByQuery(db.getSession(), new SnapshotQuery().setComponentUuid(project1.uuid())))
.extracting(SnapshotDto::getUuid)
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/event/EventDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/event/EventDaoTest.java
index c0c804091ee..6c41d79d051 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/event/EventDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/event/EventDaoTest.java
@@ -152,7 +152,7 @@ public class EventDaoTest {
SnapshotDto analysis = dbTester.components().insertProjectAndSnapshot(project);
List<EventDto> events = IntStream.range(0, 1 + new Random().nextInt(10))
.mapToObj(i -> dbTester.events().insertEvent(newEvent(analysis).setCategory("cat_" + i)))
- .collect(toList());
+ .toList();
List<EventDto> dtos = underTest.selectByComponentUuid(dbTester.getSession(), project.uuid());
assertThat(dtos)
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/metric/MetricDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/metric/MetricDaoTest.java
index 951733e8d82..b8da7e7bc35 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/metric/MetricDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/metric/MetricDaoTest.java
@@ -24,7 +24,6 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Random;
-import java.util.stream.Collectors;
import java.util.stream.IntStream;
import org.junit.Rule;
import org.junit.Test;
@@ -72,10 +71,10 @@ public class MetricDaoTest {
public void find_all_enabled() {
List<MetricDto> enabledMetrics = IntStream.range(0, 1 + new Random().nextInt(10))
.mapToObj(i -> MetricTesting.newMetricDto().setEnabled(true))
- .collect(Collectors.toList());
+ .toList();
List<MetricDto> disabledMetrics = IntStream.range(0, 1 + new Random().nextInt(10))
.mapToObj(i -> MetricTesting.newMetricDto().setEnabled(false))
- .collect(Collectors.toList());
+ .toList();
List<MetricDto> all = new ArrayList<>(enabledMetrics);
all.addAll(disabledMetrics);
@@ -92,10 +91,10 @@ public class MetricDaoTest {
public void find_all() {
List<MetricDto> enabledMetrics = IntStream.range(0, 1 + new Random().nextInt(10))
.mapToObj(i -> MetricTesting.newMetricDto().setEnabled(true))
- .collect(Collectors.toList());
+ .toList();
List<MetricDto> disabledMetrics = IntStream.range(0, 1 + new Random().nextInt(10))
.mapToObj(i -> MetricTesting.newMetricDto().setEnabled(false))
- .collect(Collectors.toList());
+ .toList();
List<MetricDto> all = new ArrayList<>(enabledMetrics);
all.addAll(disabledMetrics);
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java
index 28699396ba9..b48926f58a9 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java
@@ -475,7 +475,7 @@ public class AuthorizationDaoTest {
@Test
public void keepAuthorizedProjectUuids_should_be_able_to_handle_lots_of_projects() {
- List<ComponentDto> projects = IntStream.range(0, 2000).mapToObj(i -> db.components().insertPublicProject()).collect(Collectors.toList());
+ List<ComponentDto> projects = IntStream.range(0, 2000).mapToObj(i -> db.components().insertPublicProject()).toList();
Collection<String> uuids = projects.stream().map(ComponentDto::uuid).collect(Collectors.toSet());
assertThat(underTest.keepAuthorizedProjectUuids(dbSession, uuids, null, UserRole.USER))
@@ -665,7 +665,7 @@ public class AuthorizationDaoTest {
@Test
public void keepAuthorizedUsersForRoleAndProject_should_be_able_to_handle_lots_of_users() {
- List<UserDto> users = IntStream.range(0, 2000).mapToObj(i -> db.users().insertUser()).collect(Collectors.toList());
+ List<UserDto> users = IntStream.range(0, 2000).mapToObj(i -> db.users().insertUser()).toList();
assertThat(underTest.keepAuthorizedUsersForRoleAndProject(dbSession,
users.stream().map(UserDto::getUuid).collect(Collectors.toSet()), "user", PROJECT_UUID)).isEmpty();
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/source/FileSourceDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/source/FileSourceDaoTest.java
index 8ab7e6fdd32..01398aec0c3 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/source/FileSourceDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/source/FileSourceDaoTest.java
@@ -242,7 +242,7 @@ public class FileSourceDaoTest {
dbTester.fileSources().insertFileSource(file);
return file;
})
- .collect(Collectors.toList());
+ .toList();
Map<String, FileHashesDto> fileSourcesByUuid = new HashMap<>();
underTest.scrollFileHashesByProjectUuid(dbSession, project.branchUuid(), result -> fileSourcesByUuid.put(result.getResultObject().getFileUuid(), result.getResultObject()));
@@ -279,7 +279,7 @@ public class FileSourceDaoTest {
dbTester.fileSources().insertFileSource(file);
return file;
})
- .collect(Collectors.toList());
+ .toList();
LineHashesWithKeyDtoHandler handler = new LineHashesWithKeyDtoHandler();
underTest.scrollLineHashes(dbSession, files.stream().map(ComponentDto::uuid).collect(Collectors.toSet()), handler);
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/webhook/WebhookDeliveryTesting.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/webhook/WebhookDeliveryTesting.java
index c0b1cfc2a61..ae149ffefc9 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/webhook/WebhookDeliveryTesting.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/webhook/WebhookDeliveryTesting.java
@@ -20,7 +20,6 @@
package org.sonar.db.webhook;
import java.util.List;
-import java.util.stream.Collectors;
import org.sonar.core.util.Uuids;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
@@ -68,6 +67,6 @@ public class WebhookDeliveryTesting {
return dbTester.select(dbSession, "select uuid as \"uuid\" from webhook_deliveries")
.stream()
.map(columns -> (String) columns.get("uuid"))
- .collect(Collectors.toList());
+ .toList();
}
}