diff options
author | Léo Geoffroy <99647462+leo-geoffroy-sonarsource@users.noreply.github.com> | 2022-10-11 11:00:11 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2022-10-12 20:03:44 +0000 |
commit | b6bffded1c8e125cb2621b47ddcb9ddb0799b98f (patch) | |
tree | b4242b18429340ad702cfcf5e602d215f1edaea9 | |
parent | 2843c9415ea0308b1a5aea003f04f27e78f01f8b (diff) | |
download | sonarqube-b6bffded1c8e125cb2621b47ddcb9ddb0799b98f.tar.gz sonarqube-b6bffded1c8e125cb2621b47ddcb9ddb0799b98f.zip |
SONAR-17352 Fix quality issues
Co-authored-by: Duarte Meneses <duarte.meneses@sonarsource.com>
11 files changed, 26 insertions, 20 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java index c561e71775e..4eb3b7e177d 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java @@ -392,7 +392,7 @@ public class ComponentDao implements Dao { mapper(session).setPrivateForRootComponentUuid(branchUuid, isPrivate); } - public void setPrivateForRootComponentUuid(DbSession session, String branchUuid, boolean isPrivate, @Nullable String qualifier, String componentKey, String componentName) { + public void setPrivateForRootComponentUuid(DbSession session, String branchUuid, boolean isPrivate, String qualifier, String componentKey, String componentName) { ComponentNewValue componentNewValue = new ComponentNewValue(branchUuid, componentName, componentKey, isPrivate, qualifier); auditPersister.updateComponentVisibility(session, componentNewValue); mapper(session).setPrivateForRootComponentUuid(branchUuid, isPrivate); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java index 3533a00faea..706b1012917 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java @@ -299,7 +299,9 @@ public class ComponentDaoTest { @Test public void select_by_keys_throws_ISE_if_both_branch_and_pr_are_passed() { - assertThatThrownBy(() -> underTest.selectByKeys(db.getSession(), List.of("key"), "branch", "pr")) + DbSession session = db.getSession(); + List<String> keys = List.of("key"); + assertThatThrownBy(() -> underTest.selectByKeys(session, keys, "branch", "pr")) .isInstanceOf(IllegalStateException.class); } diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/issue/index/IssueIteratorFactoryTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/issue/index/IssueIteratorFactoryTest.java index f77fa99816d..98e203b5341 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/issue/index/IssueIteratorFactoryTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/issue/index/IssueIteratorFactoryTest.java @@ -142,10 +142,10 @@ public class IssueIteratorFactoryTest { .map(project2Component -> dbTester.issues().insert(rule, project2, project2Component).getKey()) .toArray(String[]::new); - assertThat(issuesByKey(factory -> factory.createForBranch(project1.uuid())).keySet()) - .containsOnly(project1IssueKeys); - assertThat(issuesByKey(factory -> factory.createForBranch(project2.uuid())).keySet()) - .containsOnly(project2IssueKeys); + assertThat(issuesByKey(factory -> factory.createForBranch(project1.uuid()))) + .containsOnlyKeys(project1IssueKeys); + assertThat(issuesByKey(factory -> factory.createForBranch(project2.uuid()))) + .containsOnlyKeys(project2IssueKeys); assertThat(issuesByKey(factory -> factory.createForBranch("does not exist"))) .isEmpty(); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/HotspotWsResponseFormatter.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/HotspotWsResponseFormatter.java index 2171dfeabb0..7a2a6eab358 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/HotspotWsResponseFormatter.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/HotspotWsResponseFormatter.java @@ -45,8 +45,8 @@ public class HotspotWsResponseFormatter { return builder.build(); } - Hotspots.Component formatComponent(Hotspots.Component.Builder builder, ComponentDto component, BranchDto branchDto) { - if (branchDto.isMain()) { + Hotspots.Component formatComponent(Hotspots.Component.Builder builder, ComponentDto component, @Nullable BranchDto branchDto) { + if (branchDto == null || branchDto.isMain()) { return formatComponent(builder, component, null, null); } return formatComponent(builder, component, branchDto.getBranchKey(), branchDto.getPullRequestKey()); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeData.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeData.java index 151c322bddf..83141c2f6b7 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeData.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeData.java @@ -72,7 +72,6 @@ class ComponentTreeData { return componentCount; } - @CheckForNull public Map<String, ComponentDto> getReferenceComponentsByUuid() { return referenceComponentsByUuid; } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/ValuesAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/ValuesAction.java index 6048974fec2..038bbe20bac 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/ValuesAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/ValuesAction.java @@ -123,7 +123,6 @@ public class ValuesAction implements SettingsWsAction { try (DbSession dbSession = dbClient.openSession(true)) { ValuesRequest valuesRequest = ValuesRequest.from(request); Optional<ComponentDto> component = loadComponent(dbSession, valuesRequest); - // TODO can portfolios fail here? BranchDto branchDto = component.map(c -> componentFinder.getBranchByUuid(dbSession, c.branchUuid())).orElse(null); Set<String> keys = loadKeys(valuesRequest); @@ -177,7 +176,7 @@ public class ValuesAction implements SettingsWsAction { } @CheckForNull - private String getBranchKeySafely(@Nullable BranchDto branchDto) { + private static String getBranchKeySafely(@Nullable BranchDto branchDto) { if (branchDto != null) { return branchDto.isMain() ? null : branchDto.getBranchKey(); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/branch/ws/ListActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/branch/ws/ListActionTest.java index dd17b32b942..1ef0af77e4d 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/branch/ws/ListActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/branch/ws/ListActionTest.java @@ -39,6 +39,7 @@ import org.sonar.server.issue.index.IssueIndexer; import org.sonar.server.issue.index.IssueIteratorFactory; import org.sonar.server.permission.index.PermissionIndexerTester; import org.sonar.server.tester.UserSessionRule; +import org.sonar.server.ws.TestRequest; import org.sonar.server.ws.WsActionTester; import org.sonarqube.ws.Common.BranchType; import org.sonarqube.ws.ProjectBranches; @@ -274,8 +275,8 @@ public class ListActionTest { ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(project)); userSession.logIn().addProjectPermission(USER, project); - - assertThatThrownBy(() -> ws.newRequest().setParam("project", file.getKey()).execute()) + TestRequest request = ws.newRequest().setParam("project", file.getKey()); + assertThatThrownBy(request::execute) .isInstanceOf(NotFoundException.class) .hasMessageContaining("Project '" + file.getKey() + "' not found"); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/notification/ws/AddActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/notification/ws/AddActionTest.java index 05cc511c98d..8f5d78402f5 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/notification/ws/AddActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/notification/ws/AddActionTest.java @@ -318,8 +318,9 @@ public class AddActionTest { userSession.logIn().setNonSystemAdministrator(); when(dispatchers.getGlobalDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES)); when(dispatchers.getProjectDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES)); - - assertThatThrownBy(() -> call(NOTIF_MY_NEW_ISSUES, null, project.getKey(), userSession.getLogin())) + String key = project.getKey(); + String login = userSession.getLogin(); + assertThatThrownBy(() -> call(NOTIF_MY_NEW_ISSUES, null, key, login)) .isInstanceOf(ForbiddenException.class); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectanalysis/ws/UnsetBaselineActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectanalysis/ws/UnsetBaselineActionTest.java index 25d6eb6c67b..335363f7e5e 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectanalysis/ws/UnsetBaselineActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectanalysis/ws/UnsetBaselineActionTest.java @@ -143,7 +143,8 @@ public class UnsetBaselineActionTest { String branchName = randomAlphanumeric(248); db.components().insertProjectBranch(project, b -> b.setKey(branchName)); - assertThatThrownBy(() -> call(project.getKey(), branchName)) + String key = project.getKey(); + assertThatThrownBy(() -> call(key, branchName)) .isInstanceOf(ForbiddenException.class) .hasMessage("Insufficient privileges"); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectdump/ws/ExportActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectdump/ws/ExportActionTest.java index c70f5026e17..f70f3ff900e 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectdump/ws/ExportActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectdump/ws/ExportActionTest.java @@ -34,6 +34,7 @@ import org.sonar.server.ce.projectdump.ExportSubmitter; import org.sonar.server.component.ComponentFinder; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.tester.UserSessionRule; +import org.sonar.server.ws.TestRequest; import org.sonar.server.ws.TestResponse; import org.sonar.server.ws.WsActionTester; @@ -86,7 +87,8 @@ public class ExportActionTest { public void fails_if_not_project_administrator() { userSession.logIn(); - assertThatThrownBy(() -> actionTester.newRequest().setMethod("POST").setParam("key", project.getKey()).execute()) + TestRequest request = actionTester.newRequest().setMethod("POST").setParam("key", project.getKey()); + assertThatThrownBy(request::execute) .isInstanceOf(ForbiddenException.class); } @@ -105,7 +107,8 @@ public class ExportActionTest { public void fails_to_trigger_task_if_anonymous() { userSession.anonymous(); - assertThatThrownBy(() -> actionTester.newRequest().setMethod("POST").setParam("key", project.getKey()).execute()) + TestRequest request = actionTester.newRequest().setMethod("POST").setParam("key", project.getKey()); + assertThatThrownBy(request::execute) .isInstanceOf(ForbiddenException.class) .hasMessage("Insufficient privileges"); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java index f817b25019c..851f98214bc 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java @@ -772,8 +772,8 @@ public class ComponentActionTest { ComponentDto directory = componentDbTester.insertComponent(newDirectory(module, "src/main/xoo")); userSession.addProjectPermission(UserRole.USER, project); init(); - - assertThatThrownBy(() -> execute(directory.getKey())) + String dirKey = directory.getKey(); + assertThatThrownBy(() -> execute(dirKey)) .isInstanceOf(BadRequestException.class); } |