diff options
author | Julien Camus <julien.camus@sonarsource.com> | 2024-12-17 17:37:43 +0100 |
---|---|---|
committer | Steve Marion <steve.marion@sonarsource.com> | 2024-12-18 11:13:24 +0100 |
commit | 108e25bce0062be83ab15c587aecfa1e51ba5cf1 (patch) | |
tree | 8102236ce649305a1d270a56cc284d5d12a4c31c /server/sonar-webserver-webapi | |
parent | 16e6a0469c02298a8b5c478313dd68c93705922e (diff) | |
download | sonarqube-108e25bce0062be83ab15c587aecfa1e51ba5cf1.tar.gz sonarqube-108e25bce0062be83ab15c587aecfa1e51ba5cf1.zip |
SONAR-24004 Replace lambda with method reference
Diffstat (limited to 'server/sonar-webserver-webapi')
29 files changed, 264 insertions, 278 deletions
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/almsettings/ws/UpdateAzureActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/almsettings/ws/UpdateAzureActionIT.java index b62a28310d8..d8b03bd98d1 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/almsettings/ws/UpdateAzureActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/almsettings/ws/UpdateAzureActionIT.java @@ -119,7 +119,7 @@ public class UpdateAzureActionIT { .setParam("key", almSettingDto.getKey()) .setParam("url", AZURE_URL); - assertThatThrownBy(() -> request.execute()) + assertThatThrownBy(request::execute) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Please provide the Personal Access Token to update the URL."); } @@ -134,8 +134,8 @@ public class UpdateAzureActionIT { .setParam("personalAccessToken", "0123456789") .setParam("url", AZURE_URL) .execute()) - .isInstanceOf(NotFoundException.class) - .hasMessageContaining("DevOps Platform setting with key 'unknown' cannot be found"); + .isInstanceOf(NotFoundException.class) + .hasMessageContaining("DevOps Platform setting with key 'unknown' cannot be found"); } @Test @@ -151,8 +151,8 @@ public class UpdateAzureActionIT { .setParam("personalAccessToken", "0123456789") .setParam("url", AZURE_URL) .execute()) - .isInstanceOf(IllegalArgumentException.class) - .hasMessageContaining(format("An DevOps Platform setting with key '%s' already exists", almSetting2.getKey())); + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining(format("An DevOps Platform setting with key '%s' already exists", almSetting2.getKey())); } @Test @@ -166,7 +166,7 @@ public class UpdateAzureActionIT { .setParam("newKey", "Azure Server - Infra Team") .setParam("personalAccessToken", "0123456789") .execute()) - .isInstanceOf(ForbiddenException.class); + .isInstanceOf(ForbiddenException.class); } @Test diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/almsettings/ws/UpdateBitbucketActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/almsettings/ws/UpdateBitbucketActionIT.java index 880d49735f6..e2c50940ff6 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/almsettings/ws/UpdateBitbucketActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/almsettings/ws/UpdateBitbucketActionIT.java @@ -99,7 +99,7 @@ public class UpdateBitbucketActionIT { .setParam("key", almSettingDto.getKey()) .setParam("url", "https://bitbucket.enterprise-unicorn.com"); - assertThatThrownBy(() -> request.execute()) + assertThatThrownBy(request::execute) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Please provide the Personal Access Token to update the URL."); } @@ -126,14 +126,14 @@ public class UpdateBitbucketActionIT { public void fail_when_key_does_not_match_existing_alm_setting() { UserDto user = db.users().insertUser(); userSession.logIn(user).setSystemAdministrator(); - + assertThatThrownBy(() -> ws.newRequest() .setParam("key", "unknown") .setParam("url", "https://bitbucket.enterprise-unicorn.com") .setParam("personalAccessToken", "0123456789") .execute()) - .isInstanceOf(NotFoundException.class) - .hasMessageContaining("DevOps Platform setting with key 'unknown' cannot be found"); + .isInstanceOf(NotFoundException.class) + .hasMessageContaining("DevOps Platform setting with key 'unknown' cannot be found"); } @Test @@ -149,8 +149,8 @@ public class UpdateBitbucketActionIT { .setParam("url", "https://bitbucket.enterprise-unicorn.com") .setParam("personalAccessToken", "0123456789") .execute()) - .isInstanceOf(IllegalArgumentException.class) - .hasMessageContaining(format("An DevOps Platform setting with key '%s' already exists", almSetting2.getKey())); + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining(format("An DevOps Platform setting with key '%s' already exists", almSetting2.getKey())); } @Test @@ -165,7 +165,7 @@ public class UpdateBitbucketActionIT { .setParam("url", "https://bitbucket.enterprise-unicorn.com") .setParam("personalAccessToken", "0123456789") .execute()) - .isInstanceOf(ForbiddenException.class); + .isInstanceOf(ForbiddenException.class); } @Test diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/almsettings/ws/UpdateGitlabActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/almsettings/ws/UpdateGitlabActionIT.java index c476992d6ae..40d8213ec69 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/almsettings/ws/UpdateGitlabActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/almsettings/ws/UpdateGitlabActionIT.java @@ -124,7 +124,7 @@ public class UpdateGitlabActionIT { .setParam("key", almSettingDto.getKey()) .setParam("url", GITLAB_URL); - assertThatThrownBy(() -> request.execute()) + assertThatThrownBy(request::execute) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Please provide the Personal Access Token to update the URL."); } @@ -139,8 +139,8 @@ public class UpdateGitlabActionIT { .setParam("personalAccessToken", "0123456789") .setParam("url", GITLAB_URL) .execute()) - .isInstanceOf(NotFoundException.class) - .hasMessageContaining("DevOps Platform setting with key 'unknown' cannot be found"); + .isInstanceOf(NotFoundException.class) + .hasMessageContaining("DevOps Platform setting with key 'unknown' cannot be found"); } @Test @@ -156,8 +156,8 @@ public class UpdateGitlabActionIT { .setParam("personalAccessToken", "0123456789") .setParam("url", GITLAB_URL) .execute()) - .isInstanceOf(IllegalArgumentException.class) - .hasMessageContaining(format("An DevOps Platform setting with key '%s' already exists", almSetting2.getKey())); + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining(format("An DevOps Platform setting with key '%s' already exists", almSetting2.getKey())); } @Test @@ -172,7 +172,7 @@ public class UpdateGitlabActionIT { .setParam("personalAccessToken", "0123456789") .setParam("url", GITLAB_URL) .execute()) - .isInstanceOf(ForbiddenException.class); + .isInstanceOf(ForbiddenException.class); } @Test diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SearchActionComponentsIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SearchActionComponentsIT.java index e5d63e074de..462d716dc40 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SearchActionComponentsIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SearchActionComponentsIT.java @@ -27,13 +27,13 @@ import org.junit.jupiter.api.extension.RegisterExtension; import org.mockito.Mockito; import org.sonar.api.config.Configuration; import org.sonar.api.resources.Languages; -import org.sonar.db.component.ComponentQualifiers; import org.sonar.api.rule.RuleKey; import org.sonar.api.utils.Durations; import org.sonar.api.utils.System2; import org.sonar.db.DbClient; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; +import org.sonar.db.component.ComponentQualifiers; import org.sonar.db.component.ComponentTesting; import org.sonar.db.component.ProjectData; import org.sonar.db.issue.IssueDto; @@ -64,7 +64,6 @@ import org.sonarqube.ws.Issues.SearchWsResponse; import static org.apache.commons.lang3.RandomStringUtils.secure; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.tuple; -import static org.sonar.db.component.ComponentQualifiers.APP; import static org.sonar.api.utils.DateUtils.addDays; import static org.sonar.api.utils.DateUtils.parseDateTime; import static org.sonar.api.web.UserRole.USER; @@ -73,6 +72,7 @@ import static org.sonar.core.util.Uuids.UUID_EXAMPLE_02; import static org.sonar.db.component.BranchDto.DEFAULT_MAIN_BRANCH_NAME; import static org.sonar.db.component.BranchType.BRANCH; import static org.sonar.db.component.BranchType.PULL_REQUEST; +import static org.sonar.db.component.ComponentQualifiers.APP; import static org.sonar.db.component.ComponentTesting.newDirectory; import static org.sonar.db.component.ComponentTesting.newFileDto; import static org.sonar.db.component.ComponentTesting.newProjectCopy; @@ -92,7 +92,7 @@ class SearchActionComponentsIT { private final DbTester db = DbTester.create(); @RegisterExtension private final EsTester es = EsTester.create(); - + private final Configuration config = Mockito.mock(Configuration.class); private final DbClient dbClient = db.getDbClient(); @@ -709,17 +709,17 @@ class SearchActionComponentsIT { private void allowAnyoneOnProjects(ProjectDto... projects) { userSession.registerProjects(projects); - Arrays.stream(projects).forEach(p -> permissionIndexer.allowOnlyAnyone(p)); + Arrays.stream(projects).forEach(permissionIndexer::allowOnlyAnyone); } private void allowAnyoneOnPortfolios(ComponentDto... portfolios) { userSession.registerPortfolios(portfolios); - Arrays.stream(portfolios).forEach(p -> permissionIndexer.allowOnlyAnyone(p)); + Arrays.stream(portfolios).forEach(permissionIndexer::allowOnlyAnyone); } private void allowAnyoneOnApplication(ProjectDto application, ProjectDto... projects) { userSession.registerApplication(application); - Arrays.stream(projects).forEach(p -> permissionIndexer.allowOnlyAnyone(p)); + Arrays.stream(projects).forEach(permissionIndexer::allowOnlyAnyone); } private void indexIssues() { diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/ComponentTreeActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/ComponentTreeActionIT.java index 0fa15ae84a1..22b94dd1281 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/ComponentTreeActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/ComponentTreeActionIT.java @@ -1192,7 +1192,7 @@ class ComponentTreeActionIT { .setParam(PARAM_QUALIFIERS, "BRC") .setParam(PARAM_METRIC_KEYS, complexity.getKey()); - assertThatThrownBy(() -> testRequest.execute()).isInstanceOf(IllegalArgumentException.class) + assertThatThrownBy(testRequest::execute).isInstanceOf(IllegalArgumentException.class) .hasMessage("Value of parameter 'qualifiers' (BRC) must be one of: [UTS, FIL, DIR, TRK]"); } diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/ws/SetActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/ws/SetActionIT.java index e65d4c42860..2a89605770e 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/ws/SetActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/ws/SetActionIT.java @@ -43,7 +43,6 @@ import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ProjectData; import org.sonar.db.component.SnapshotDto; import org.sonar.db.newcodeperiod.NewCodePeriodDao; -import org.sonar.db.newcodeperiod.NewCodePeriodDbTester; import org.sonar.db.newcodeperiod.NewCodePeriodDto; import org.sonar.db.newcodeperiod.NewCodePeriodType; import org.sonar.db.project.ProjectDto; @@ -132,8 +131,8 @@ public class SetActionIT { .setParam("project", project.getKey()) .setParam("type", "specific_analysis") .execute()) - .isInstanceOf(IllegalArgumentException.class) - .hasMessageContaining("Invalid type 'SPECIFIC_ANALYSIS'. Projects can only be set with types: [PREVIOUS_VERSION, NUMBER_OF_DAYS, REFERENCE_BRANCH]"); + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("Invalid type 'SPECIFIC_ANALYSIS'. Projects can only be set with types: [PREVIOUS_VERSION, NUMBER_OF_DAYS, REFERENCE_BRANCH]"); } @Test @@ -146,8 +145,8 @@ public class SetActionIT { .setParam("branch", DEFAULT_MAIN_BRANCH_NAME) .setParam("type", "number_of_days") .execute()) - .isInstanceOf(IllegalArgumentException.class) - .hasMessageContaining("New code definition type 'NUMBER_OF_DAYS' requires a value"); + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("New code definition type 'NUMBER_OF_DAYS' requires a value"); } @Test @@ -160,8 +159,8 @@ public class SetActionIT { .setParam("type", "specific_analysis") .setParam("branch", DEFAULT_MAIN_BRANCH_NAME) .execute()) - .isInstanceOf(IllegalArgumentException.class) - .hasMessageContaining("New code definition type 'SPECIFIC_ANALYSIS' requires a value"); + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("New code definition type 'SPECIFIC_ANALYSIS' requires a value"); } @Test @@ -175,8 +174,8 @@ public class SetActionIT { .setParam("branch", DEFAULT_MAIN_BRANCH_NAME) .setParam("value", "unknown") .execute()) - .isInstanceOf(IllegalArgumentException.class) - .hasMessageContaining("Failed to parse number of days: unknown"); + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("Failed to parse number of days: unknown"); } @Test @@ -189,8 +188,7 @@ public class SetActionIT { .setParam("type", "number_of_days") .setParam("branch", DEFAULT_MAIN_BRANCH_NAME) .setParam("value", "92"); - assertThatThrownBy(() -> request - .execute()) + assertThatThrownBy(request::execute) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("Failed to set the New Code Definition. The given value is not compatible with the Clean as You Code methodology. " + "Please refer to the documentation for compliant options."); @@ -221,8 +219,8 @@ public class SetActionIT { .setParam("branch", DEFAULT_MAIN_BRANCH_NAME) .setParam("value", "unknown") .execute()) - .isInstanceOf(NotFoundException.class) - .hasMessageContaining("Analysis 'unknown' is not found"); + .isInstanceOf(NotFoundException.class) + .hasMessageContaining("Analysis 'unknown' is not found"); } @Test @@ -242,9 +240,9 @@ public class SetActionIT { .setParam("branch", DEFAULT_MAIN_BRANCH_NAME) .setParam("value", analysisBranch.getUuid()) .execute()) - .isInstanceOf(IllegalArgumentException.class) - .hasMessageContaining("Analysis '" + analysisBranch.getUuid() + "' does not belong to branch '" + DEFAULT_MAIN_BRANCH_NAME + - "' of project '" + project.getKey() + "'"); + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("Analysis '" + analysisBranch.getUuid() + "' does not belong to branch '" + DEFAULT_MAIN_BRANCH_NAME + + "' of project '" + project.getKey() + "'"); } // validation of project/branch @@ -253,8 +251,8 @@ public class SetActionIT { assertThatThrownBy(() -> ws.newRequest() .setParam("branch", "branch") .execute()) - .isInstanceOf(IllegalArgumentException.class) - .hasMessageContaining("If branch key is specified, project key needs to be specified too"); + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("If branch key is specified, project key needs to be specified too"); } @Test @@ -263,8 +261,8 @@ public class SetActionIT { .setParam("type", "previous_version") .setParam("project", "unknown") .execute()) - .isInstanceOf(NotFoundException.class) - .hasMessageContaining("Project 'unknown' not found"); + .isInstanceOf(NotFoundException.class) + .hasMessageContaining("Project 'unknown' not found"); } @Test @@ -277,8 +275,8 @@ public class SetActionIT { .setParam("type", "previous_version") .setParam("branch", "unknown") .execute()) - .isInstanceOf(NotFoundException.class) - .hasMessageContaining("Branch 'unknown' in project '" + project.getKey() + "' not found"); + .isInstanceOf(NotFoundException.class) + .hasMessageContaining("Branch 'unknown' in project '" + project.getKey() + "' not found"); } // permission @@ -290,8 +288,8 @@ public class SetActionIT { .setParam("project", project.getKey()) .setParam("type", "previous_version") .execute()) - .isInstanceOf(ForbiddenException.class) - .hasMessageContaining("Insufficient privileges"); + .isInstanceOf(ForbiddenException.class) + .hasMessageContaining("Insufficient privileges"); } @Test @@ -299,8 +297,8 @@ public class SetActionIT { assertThatThrownBy(() -> ws.newRequest() .setParam("type", "previous_version") .execute()) - .isInstanceOf(ForbiddenException.class) - .hasMessageContaining("Insufficient privileges"); + .isInstanceOf(ForbiddenException.class) + .hasMessageContaining("Insufficient privileges"); } // success cases diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/ws/UnsetActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/ws/UnsetActionIT.java index bb7a5a75581..bec4270a046 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/ws/UnsetActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/ws/UnsetActionIT.java @@ -68,7 +68,7 @@ public class UnsetActionIT { private WsActionTester ws; @Before - public void setup(){ + public void setup() { when(documentationLinkGenerator.getDocumentationLink(any())).thenReturn("https://docs.sonarsource.com/someddoc"); ws = new WsActionTester(new UnsetAction(dbClient, userSession, componentFinder, editionProvider, dao, documentationLinkGenerator)); } @@ -95,7 +95,7 @@ public class UnsetActionIT { TestRequest request = ws.newRequest() .setParam("branch", "branch"); - assertThatThrownBy(() -> request.execute()) + assertThatThrownBy(request::execute) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("If branch key is specified, project key needs to be specified too"); } @@ -106,8 +106,8 @@ public class UnsetActionIT { .setParam("type", "previous_version") .setParam("project", "unknown") .execute()) - .isInstanceOf(NotFoundException.class) - .hasMessageContaining("Project 'unknown' not found"); + .isInstanceOf(NotFoundException.class) + .hasMessageContaining("Project 'unknown' not found"); } @Test @@ -120,8 +120,8 @@ public class UnsetActionIT { .setParam("type", "previous_version") .setParam("branch", "unknown") .execute()) - .isInstanceOf(NotFoundException.class) - .hasMessageContaining("Branch 'unknown' in project '" + project.getKey() + "' not found"); + .isInstanceOf(NotFoundException.class) + .hasMessageContaining("Branch 'unknown' in project '" + project.getKey() + "' not found"); } // permission @@ -133,8 +133,8 @@ public class UnsetActionIT { .setParam("project", project.getKey()) .setParam("type", "previous_version") .execute()) - .isInstanceOf(ForbiddenException.class) - .hasMessageContaining("Insufficient privileges"); + .isInstanceOf(ForbiddenException.class) + .hasMessageContaining("Insufficient privileges"); } @Test @@ -142,8 +142,8 @@ public class UnsetActionIT { assertThatThrownBy(() -> ws.newRequest() .setParam("type", "previous_version") .execute()) - .isInstanceOf(ForbiddenException.class) - .hasMessageContaining("Insufficient privileges"); + .isInstanceOf(ForbiddenException.class) + .hasMessageContaining("Insufficient privileges"); } // success cases @@ -236,7 +236,7 @@ public class UnsetActionIT { .setParam("branch", "branch"); logInAsProjectAdministrator(project); - assertThatThrownBy(() -> request.execute()) + assertThatThrownBy(request::execute) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("Failed to unset the New Code Definition. Your project " + "New Code Definition is not compatible with the Clean as You Code methodology. Please update your project New Code Definition"); @@ -255,7 +255,7 @@ public class UnsetActionIT { .setParam("branch", "branch"); logInAsProjectAdministrator(project); - assertThatThrownBy(() -> request.execute()) + assertThatThrownBy(request::execute) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("Failed to unset the New Code Definition. Your instance " + "New Code Definition is not compatible with the Clean as You Code methodology. Please update your instance New Code Definition"); @@ -271,7 +271,7 @@ public class UnsetActionIT { TestRequest request = ws.newRequest() .setParam("project", project.getKey()); - assertThatThrownBy(() -> request.execute()) + assertThatThrownBy(request::execute) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("Failed to unset the New Code Definition. Your instance " + "New Code Definition is not compatible with the Clean as You Code methodology. Please update your instance New Code Definition"); diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/ws/CopyActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/ws/CopyActionIT.java index f13c6647947..8bdf03e35f3 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/ws/CopyActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/ws/CopyActionIT.java @@ -147,7 +147,7 @@ public class CopyActionIT { .setParam(PARAM_SOURCE_NAME, qualityGate.getName()) .setParam(PARAM_NAME, "new-name") .execute()) - .isInstanceOf(ForbiddenException.class); + .isInstanceOf(ForbiddenException.class); } @Test @@ -157,8 +157,8 @@ public class CopyActionIT { assertThatThrownBy(() -> ws.newRequest() .setParam(PARAM_NAME, "new-name") .execute()) - .isInstanceOf(IllegalArgumentException.class) - .hasMessageContaining("The 'sourceName' parameter is missing"); + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("The 'sourceName' parameter is missing"); } @Test @@ -169,8 +169,8 @@ public class CopyActionIT { .setParam(PARAM_SOURCE_NAME, "unknown") .setParam(PARAM_NAME, "new-name") .execute()) - .isInstanceOf(NotFoundException.class) - .hasMessageContaining("No quality gate has been found for name unknown"); + .isInstanceOf(NotFoundException.class) + .hasMessageContaining("No quality gate has been found for name unknown"); } @Test @@ -183,14 +183,14 @@ public class CopyActionIT { .setParam(PARAM_SOURCE_NAME, qualityGate.getName()); ofNullable(nameParameter).ifPresent(t -> request.setParam(PARAM_NAME, t)); - assertThatThrownBy(() -> request.execute()) + assertThatThrownBy(request::execute) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("The 'name' parameter is missing"); } @DataProvider public static Object[][] nullOrEmpty() { - return new Object[][]{ + return new Object[][] { {null}, {""}, {" "} @@ -207,7 +207,7 @@ public class CopyActionIT { .setParam(PARAM_SOURCE_NAME, qualityGate.getName()) .setParam(PARAM_NAME, existingQualityGate.getName()) .execute()) - .isInstanceOf(IllegalArgumentException.class) - .hasMessageContaining("Name has already been taken"); + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("Name has already been taken"); } } diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/ws/CreateActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/ws/CreateActionIT.java index 227157807ba..9589c94c873 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/ws/CreateActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/ws/CreateActionIT.java @@ -131,7 +131,7 @@ public class CreateActionIT { TestRequest request = ws.newRequest(); Optional.ofNullable(nameParameter).ifPresent(t -> request.setParam(PARAM_NAME, "")); - assertThatThrownBy(() -> request.execute()) + assertThatThrownBy(request::execute) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("The 'name' parameter is missing"); } diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualityprofile/ws/ActivateRuleActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualityprofile/ws/ActivateRuleActionIT.java index e13a7d15b66..f317eeaff4d 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualityprofile/ws/ActivateRuleActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualityprofile/ws/ActivateRuleActionIT.java @@ -100,7 +100,7 @@ class ActivateRuleActionIT { .setParam(PARAM_RULE, RuleTesting.newRule().getKey().toString()) .setParam(PARAM_KEY, secure().nextAlphanumeric(UUID_SIZE)); - assertThatThrownBy(() -> request.execute()) + assertThatThrownBy(request::execute) .isInstanceOf(UnauthorizedException.class); } @@ -113,7 +113,7 @@ class ActivateRuleActionIT { .setParam(PARAM_RULE, RuleTesting.newRule().getKey().toString()) .setParam(PARAM_KEY, qualityProfile.getKee()); - assertThatThrownBy(() -> request.execute()) + assertThatThrownBy(request::execute) .isInstanceOf(ForbiddenException.class); } @@ -128,7 +128,7 @@ class ActivateRuleActionIT { .setParam(PARAM_RULE, RuleTesting.newRule().getKey().toString()) .setParam(PARAM_KEY, qualityProfile.getKee()); - assertThatThrownBy(() -> request.execute()) + assertThatThrownBy(request::execute) .isInstanceOf(BadRequestException.class) .hasMessage("Operation forbidden for built-in Quality Profile 'Xoo profile' with language 'xoo'"); } @@ -144,7 +144,7 @@ class ActivateRuleActionIT { .setParam(PARAM_RULE, rule.getKey().toString()) .setParam(PARAM_KEY, qualityProfile.getKee()); - assertThatThrownBy(() -> request.execute()) + assertThatThrownBy(request::execute) .isInstanceOf(BadRequestException.class) .hasMessage(String.format("Operation forbidden for rule '%s' imported from an external rule engine.", rule.getKey())); } @@ -162,7 +162,7 @@ class ActivateRuleActionIT { .setParam(PARAM_SEVERITY, "BLOCKER") .setParam(PARAM_IMPACTS, "MAINTAINABILITY=BLOCKER"); - assertThatThrownBy(() -> request.execute()) + assertThatThrownBy(request::execute) .isInstanceOf(BadRequestException.class) .hasMessage("'severity' and 'impacts' parameters can't be provided both at the same time"); } @@ -179,7 +179,7 @@ class ActivateRuleActionIT { .setParam(PARAM_KEY, qualityProfile.getKee()) .setParam(PARAM_IMPACTS, "MAINTAINABILITY=UNKNOWN_SEVERITY"); - assertThatThrownBy(() -> request.execute()) + assertThatThrownBy(request::execute) .isInstanceOf(BadRequestException.class) .hasMessage("Unexpected value for parameter 'impacts': MAINTAINABILITY=UNKNOWN_SEVERITY"); } @@ -198,7 +198,7 @@ class ActivateRuleActionIT { .setParam(PARAM_KEY, qualityProfile.getKee()) .setParam(PARAM_IMPACTS, "MAINTAINABILITY=BLOCKER;SECURITY=MEDIUM"); - assertThatThrownBy(() -> request.execute()) + assertThatThrownBy(request::execute) .isInstanceOf(BadRequestException.class) .hasMessage("Only impacts defined on the rule can be overridden. (MAINTAINABILITY)"); } diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualityprofile/ws/ActivateRulesActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualityprofile/ws/ActivateRulesActionIT.java index 4cbf8dd889d..3382d28c636 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualityprofile/ws/ActivateRulesActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualityprofile/ws/ActivateRulesActionIT.java @@ -19,7 +19,6 @@ */ package org.sonar.server.qualityprofile.ws; - import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import org.mockito.Mockito; @@ -136,7 +135,7 @@ class ActivateRulesActionIT { .setMethod("POST") .setParam(PARAM_TARGET_KEY, secure().nextAlphanumeric(UUID_SIZE)); - assertThatThrownBy(() -> request.execute()) + assertThatThrownBy(request::execute) .isInstanceOf(UnauthorizedException.class); } @@ -148,7 +147,7 @@ class ActivateRulesActionIT { .setMethod("POST") .setParam(PARAM_TARGET_KEY, qualityProfile.getKee()); - assertThatThrownBy(() -> request.execute()) + assertThatThrownBy(request::execute) .isInstanceOf(BadRequestException.class); } diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualityprofile/ws/DeactivateRuleActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualityprofile/ws/DeactivateRuleActionIT.java index e950a21bab8..7362e8b78b8 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualityprofile/ws/DeactivateRuleActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualityprofile/ws/DeactivateRuleActionIT.java @@ -140,7 +140,7 @@ public class DeactivateRuleActionIT { .setParam(PARAM_RULE, rule.getKey().toString()) .setParam(PARAM_KEY, qualityProfile.getKee()); - assertThatThrownBy(() -> request.execute()) + assertThatThrownBy(request::execute) .isInstanceOf(BadRequestException.class) .hasMessage(String.format("Operation forbidden for rule '%s' imported from an external rule engine.", rule.getKey())); } diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/setting/ws/CheckSecretKeyActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/setting/ws/CheckSecretKeyActionIT.java index f9560146990..428a573b6d1 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/setting/ws/CheckSecretKeyActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/setting/ws/CheckSecretKeyActionIT.java @@ -88,7 +88,7 @@ public class CheckSecretKeyActionIT { public void throw_ForbiddenException_if_not_system_administrator() { userSession.logIn().setNonSystemAdministrator(); - assertThatThrownBy(() -> call()) + assertThatThrownBy(this::call) .isInstanceOf(ForbiddenException.class) .hasMessage("Insufficient privileges"); } diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/setting/ws/GenerateSecretKeyActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/setting/ws/GenerateSecretKeyActionIT.java index 826d2f7fcf7..87a5044603e 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/setting/ws/GenerateSecretKeyActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/setting/ws/GenerateSecretKeyActionIT.java @@ -83,12 +83,11 @@ public class GenerateSecretKeyActionIT { public void throw_ForbiddenException_if_not_system_administrator() { userSession.logIn().setNonSystemAdministrator(); - assertThatThrownBy(() -> call()) + assertThatThrownBy(this::call) .isInstanceOf(ForbiddenException.class) .hasMessage("Insufficient privileges"); } - private GenerateSecretKeyWsResponse call() { return ws.newRequest() .setMethod("GET") diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/setting/ws/ResetActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/setting/ws/ResetActionIT.java index 6824bee5de7..4b07ab5483e 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/setting/ws/ResetActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/setting/ws/ResetActionIT.java @@ -54,10 +54,10 @@ import static java.lang.String.format; import static java.net.HttpURLConnection.HTTP_NO_CONTENT; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.sonar.db.component.ComponentQualifiers.PROJECT; -import static org.sonar.db.component.ComponentQualifiers.VIEW; import static org.sonar.api.web.UserRole.ADMIN; import static org.sonar.api.web.UserRole.USER; +import static org.sonar.db.component.ComponentQualifiers.PROJECT; +import static org.sonar.db.component.ComponentQualifiers.VIEW; import static org.sonar.db.property.PropertyTesting.newComponentPropertyDto; import static org.sonar.db.property.PropertyTesting.newGlobalPropertyDto; import static org.sonar.db.property.PropertyTesting.newUserPropertyDto; @@ -303,7 +303,7 @@ public class ResetActionIT { .setParam("keys", "foo") .setParam("component", "unknown"); - assertThatThrownBy(() -> request.execute()) + assertThatThrownBy(request::execute) .isInstanceOf(NotFoundException.class) .hasMessage("Component key 'unknown' not found"); } @@ -317,7 +317,7 @@ public class ResetActionIT { TestRequest request = ws.newRequest() .setParam("keys", settingKey) .setParam("component", project.getKey()); - assertThatThrownBy(() -> request.execute()) + assertThatThrownBy(request::execute) .isInstanceOf(IllegalArgumentException.class) .hasMessage(format("Setting '%s' can only be used in sonar.properties", settingKey)); } @@ -392,9 +392,9 @@ public class ResetActionIT { private void assertUserPropertyExists(String key, UserDto user) { assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder() - .setKey(key) - .setUserUuid(user.getUuid()) - .build(), + .setKey(key) + .setUserUuid(user.getUuid()) + .build(), dbSession)).isNotEmpty(); } diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/LinesActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/LinesActionIT.java index fea1aa3d69b..f10046d3680 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/LinesActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/LinesActionIT.java @@ -102,7 +102,7 @@ public class LinesActionIT { TestRequest request = tester.newRequest() .setParam("uuid", file.uuid()); - assertThatThrownBy(() -> request.execute()) + assertThatThrownBy(request::execute) .isInstanceOf(NotFoundException.class); } @@ -319,8 +319,8 @@ public class LinesActionIT { .setParam("key", file.getKey()) .setParam("branch", "another_branch") .execute()) - .isInstanceOf(NotFoundException.class) - .hasMessageContaining(String.format("Component '%s' on branch '%s' not found", file.getKey(), "another_branch")); + .isInstanceOf(NotFoundException.class) + .hasMessageContaining(String.format("Component '%s' on branch '%s' not found", file.getKey(), "another_branch")); } @Test @@ -334,8 +334,8 @@ public class LinesActionIT { .setParam("uuid", file.uuid()) .setParam("branch", "another_branch") .execute()) - .isInstanceOf(IllegalArgumentException.class) - .hasMessageContaining("Parameter 'uuid' cannot be used at the same time as 'branch' or 'pullRequest'"); + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("Parameter 'uuid' cannot be used at the same time as 'branch' or 'pullRequest'"); } @Test @@ -347,8 +347,8 @@ public class LinesActionIT { assertThatThrownBy(() -> tester.newRequest() .setParam("uuid", branch.getUuid()) .execute()) - .isInstanceOf(NotFoundException.class) - .hasMessageContaining(format("Component id '%s' not found", branch.getUuid())); + .isInstanceOf(NotFoundException.class) + .hasMessageContaining(format("Component id '%s' not found", branch.getUuid())); } @Test diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ui/ws/MarketplaceActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ui/ws/MarketplaceActionIT.java index 97f71ebb8df..63265c04cbb 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ui/ws/MarketplaceActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ui/ws/MarketplaceActionIT.java @@ -72,7 +72,7 @@ public class MarketplaceActionIT { userSessionRule.anonymous(); TestRequest request = ws.newRequest(); - assertThatThrownBy(() -> request.execute()) + assertThatThrownBy(request::execute) .isInstanceOf(UnauthorizedException.class) .hasMessageContaining("Authentication is required"); } @@ -82,7 +82,7 @@ public class MarketplaceActionIT { userSessionRule.logIn(); TestRequest request = ws.newRequest(); - assertThatThrownBy(() -> request.execute()) + assertThatThrownBy(request::execute) .isInstanceOf(ForbiddenException.class) .hasMessageContaining("Insufficient privileges"); } diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/user/ws/CreateActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/user/ws/CreateActionIT.java index 88c1a1766c2..e54c8e38864 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/user/ws/CreateActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/user/ws/CreateActionIT.java @@ -80,7 +80,8 @@ public class CreateActionIT { private final ManagedInstanceService managedInstanceService = mock(ManagedInstanceService.class); private final IdentityProviderRepository identityProviderRepository = mock(); private final UserService userService = new UserService(db.getDbClient(), new AvatarResolverImpl(), managedInstanceService, managedInstanceChecker, mock(UserDeactivator.class), - new UserUpdater(mock(NewUserNotifier.class), db.getDbClient(), new DefaultGroupFinder(db.getDbClient()), settings.asConfig(), new NoOpAuditPersister(), localAuthentication), identityProviderRepository); + new UserUpdater(mock(NewUserNotifier.class), db.getDbClient(), new DefaultGroupFinder(db.getDbClient()), settings.asConfig(), new NoOpAuditPersister(), localAuthentication), + identityProviderRepository); private final WsActionTester tester = new WsActionTester(new CreateAction(userSessionRule, managedInstanceChecker, userService)); @Before @@ -305,15 +306,13 @@ public class CreateActionIT { public void fail_when_password_is_set_on_none_local_user() { logInAsSystemAdministrator(); - TestRequest request =tester.newRequest() - .setParam("login","john") - .setParam("name","John") + TestRequest request = tester.newRequest() + .setParam("login", "john") + .setParam("name", "John") .setParam("password", "1234") .setParam("local", "false"); - assertThatThrownBy(() -> { - request.execute(); - }) + assertThatThrownBy(request::execute) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Password should only be set on local user"); } diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/user/ws/SearchActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/user/ws/SearchActionIT.java index 972e08e521f..923746bd59c 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/user/ws/SearchActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/user/ws/SearchActionIT.java @@ -139,18 +139,18 @@ public class SearchActionIT { assertThat(ws.newRequest() .setParam("q", "user-%_%-") .executeProtobuf(SearchWsResponse.class).getUsersList()) - .extracting(User::getLogin) - .containsExactlyInAnyOrder(user.getLogin()); + .extracting(User::getLogin) + .containsExactlyInAnyOrder(user.getLogin()); assertThat(ws.newRequest() .setParam("q", "user@MAIL.com") .executeProtobuf(SearchWsResponse.class).getUsersList()) - .extracting(User::getLogin) - .containsExactlyInAnyOrder(user.getLogin()); + .extracting(User::getLogin) + .containsExactlyInAnyOrder(user.getLogin()); assertThat(ws.newRequest() .setParam("q", "user-name") .executeProtobuf(SearchWsResponse.class).getUsersList()) - .extracting(User::getLogin) - .containsExactlyInAnyOrder(user.getLogin()); + .extracting(User::getLogin) + .containsExactlyInAnyOrder(user.getLogin()); } @Test @@ -265,14 +265,14 @@ public class SearchActionIT { userSession.logIn().setSystemAdministrator(); assertThat(ws.newRequest() .executeProtobuf(SearchWsResponse.class).getUsersList()) - .extracting(User::getLogin, User::getTokensCount) - .containsExactlyInAnyOrder(tuple(user.getLogin(), 2)); + .extracting(User::getLogin, User::getTokensCount) + .containsExactlyInAnyOrder(tuple(user.getLogin(), 2)); userSession.logIn(); assertThat(ws.newRequest() .executeProtobuf(SearchWsResponse.class).getUsersList()) - .extracting(User::getLogin, User::hasTokensCount) - .containsExactlyInAnyOrder(tuple(user.getLogin(), false)); + .extracting(User::getLogin, User::hasTokensCount) + .containsExactlyInAnyOrder(tuple(user.getLogin(), false)); } @Test @@ -282,14 +282,14 @@ public class SearchActionIT { userSession.logIn().setSystemAdministrator(); assertThat(ws.newRequest() .executeProtobuf(SearchWsResponse.class).getUsersList()) - .extracting(User::getLogin, User::getEmail) - .containsExactlyInAnyOrder(tuple(user.getLogin(), user.getEmail())); + .extracting(User::getLogin, User::getEmail) + .containsExactlyInAnyOrder(tuple(user.getLogin(), user.getEmail())); userSession.logIn(); assertThat(ws.newRequest() .executeProtobuf(SearchWsResponse.class).getUsersList()) - .extracting(User::getLogin, User::hasEmail) - .containsExactlyInAnyOrder(tuple(user.getLogin(), false)); + .extracting(User::getLogin, User::hasEmail) + .containsExactlyInAnyOrder(tuple(user.getLogin(), false)); } @Test @@ -317,14 +317,14 @@ public class SearchActionIT { userSession.logIn().setSystemAdministrator(); assertThat(ws.newRequest() .executeProtobuf(SearchWsResponse.class).getUsersList()) - .extracting(User::getLogin, u -> u.getGroups().getGroupsList()) - .containsExactlyInAnyOrder(tuple(user.getLogin(), asList(group1.getName(), group2.getName()))); + .extracting(User::getLogin, u -> u.getGroups().getGroupsList()) + .containsExactlyInAnyOrder(tuple(user.getLogin(), asList(group1.getName(), group2.getName()))); userSession.logIn(); assertThat(ws.newRequest() .executeProtobuf(SearchWsResponse.class).getUsersList()) - .extracting(User::getLogin, User::hasGroups) - .containsExactlyInAnyOrder(tuple(user.getLogin(), false)); + .extracting(User::getLogin, User::hasGroups) + .containsExactlyInAnyOrder(tuple(user.getLogin(), false)); } @Test @@ -347,14 +347,14 @@ public class SearchActionIT { userSession.logIn().setSystemAdministrator(); assertThat(ws.newRequest() .executeProtobuf(SearchWsResponse.class).getUsersList()) - .extracting(User::getLogin, User::getExternalIdentity) - .containsExactlyInAnyOrder(tuple(user.getLogin(), user.getExternalLogin())); + .extracting(User::getLogin, User::getExternalIdentity) + .containsExactlyInAnyOrder(tuple(user.getLogin(), user.getExternalLogin())); userSession.logIn(); assertThat(ws.newRequest() .executeProtobuf(SearchWsResponse.class).getUsersList()) - .extracting(User::getLogin, User::hasExternalIdentity) - .containsExactlyInAnyOrder(tuple(user.getLogin(), false)); + .extracting(User::getLogin, User::hasExternalIdentity) + .containsExactlyInAnyOrder(tuple(user.getLogin(), false)); } @Test @@ -403,18 +403,18 @@ public class SearchActionIT { userSession.logIn(user); assertThat(ws.newRequest().setParam("q", user.getLogin()) .executeProtobuf(SearchWsResponse.class).getUsersList()) - .extracting(User::getLogin, User::getName, User::getEmail, User::getExternalIdentity, User::getExternalProvider, - User::hasScmAccounts, User::hasAvatar, User::hasGroups, User::getTokensCount, User::hasLastConnectionDate, User::hasManaged) - .containsExactlyInAnyOrder( - tuple(user.getLogin(), user.getName(), user.getEmail(), user.getExternalLogin(), user.getExternalIdentityProvider(), true, true, true, 2, true, true)); + .extracting(User::getLogin, User::getName, User::getEmail, User::getExternalIdentity, User::getExternalProvider, + User::hasScmAccounts, User::hasAvatar, User::hasGroups, User::getTokensCount, User::hasLastConnectionDate, User::hasManaged) + .containsExactlyInAnyOrder( + tuple(user.getLogin(), user.getName(), user.getEmail(), user.getExternalLogin(), user.getExternalIdentityProvider(), true, true, true, 2, true, true)); userSession.logIn(otherUser); assertThat(ws.newRequest().setParam("q", user.getLogin()) .executeProtobuf(SearchWsResponse.class).getUsersList()) - .extracting(User::getLogin, User::getName, User::hasEmail, User::hasExternalIdentity, User::hasExternalProvider, - User::hasScmAccounts, User::hasAvatar, User::hasGroups, User::hasTokensCount, User::hasLastConnectionDate) - .containsExactlyInAnyOrder( - tuple(user.getLogin(), user.getName(), false, false, true, true, true, false, false, false)); + .extracting(User::getLogin, User::getName, User::hasEmail, User::hasExternalIdentity, User::hasExternalProvider, + User::hasScmAccounts, User::hasAvatar, User::hasGroups, User::hasTokensCount, User::hasLastConnectionDate) + .containsExactlyInAnyOrder( + tuple(user.getLogin(), user.getName(), false, false, true, true, true, false, false, false)); } @Test @@ -527,8 +527,8 @@ public class SearchActionIT { assertThat(ws.newRequest() .setParam("q", "user-%_%-") .executeProtobuf(SearchWsResponse.class).getUsersList()) - .extracting(User::getLogin) - .containsExactlyInAnyOrder(user.getLogin()); + .extracting(User::getLogin) + .containsExactlyInAnyOrder(user.getLogin()); assertUserWithFilter(SearchAction.LAST_CONNECTION_DATE_FROM, lastConnection.minus(1, ChronoUnit.DAYS), user.getLogin(), true); assertUserWithFilter(SearchAction.LAST_CONNECTION_DATE_FROM, lastConnection.plus(1, ChronoUnit.DAYS), user.getLogin(), false); @@ -587,14 +587,12 @@ public class SearchActionIT { } private void mockUsersAsManaged(String... userUuids) { - when(managedInstanceService.getUserUuidToManaged(any(), any())).thenAnswer(invocation -> - { - Set<?> allUsersUuids = invocation.getArgument(1, Set.class); - return allUsersUuids.stream() - .map(userUuid -> (String) userUuid) - .collect(toMap(identity(), userUuid -> Set.of(userUuids).contains(userUuid))); - } - ); + when(managedInstanceService.getUserUuidToManaged(any(), any())).thenAnswer(invocation -> { + Set<?> allUsersUuids = invocation.getArgument(1, Set.class); + return allUsersUuids.stream() + .map(String.class::cast) + .collect(toMap(identity(), userUuid -> Set.of(userUuids).contains(userUuid))); + }); } @Test diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/user/ws/UpdateActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/user/ws/UpdateActionIT.java index e44b54ffe51..6293fc839d9 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/user/ws/UpdateActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/user/ws/UpdateActionIT.java @@ -266,9 +266,7 @@ public class UpdateActionIT { TestRequest request = ws.newRequest() .setParam("login", USER_LOGIN); - assertThatThrownBy(() -> { - request.execute(); - }) + assertThatThrownBy(request::execute) .isInstanceOf(NotFoundException.class) .hasMessage("User 'john' doesn't exist"); } @@ -280,9 +278,7 @@ public class UpdateActionIT { TestRequest request = ws.newRequest() .setParam("login", USER_LOGIN) .setParam("email", "invalid-email"); - assertThatThrownBy(() -> { - request.execute(); - }) + assertThatThrownBy(request::execute) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Email 'invalid-email' is not valid"); } diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/usergroups/ws/UsersActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/usergroups/ws/UsersActionIT.java index 41982265143..8df4d9f277b 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/usergroups/ws/UsersActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/usergroups/ws/UsersActionIT.java @@ -201,22 +201,22 @@ public class UsersActionIT { .setParam(PARAM_GROUP_NAME, group.getName()) .execute() .getInput()).isSimilarTo(""" - { - "users": [ - {"login": "ada", "name": "Ada Lovelace", "selected": true} - ] - }"""); + { + "users": [ + {"login": "ada", "name": "Ada Lovelace", "selected": true} + ] + }"""); assertJson(newUsersRequest() .setParam(PARAM_GROUP_NAME, group.getName()) .setParam(Param.SELECTED, SelectionMode.SELECTED.value()) .execute() .getInput()).isSimilarTo(""" - { - "users": [ - {"login": "ada", "name": "Ada Lovelace", "selected": true} - ] - }"""); + { + "users": [ + {"login": "ada", "name": "Ada Lovelace", "selected": true} + ] + }"""); } @Test @@ -255,18 +255,18 @@ public class UsersActionIT { .setParam(Param.SELECTED, SelectionMode.ALL.value()) .execute() .getInput()).isSimilarTo(""" - { - "p": 1, - "ps": 1, - "total": 2, - "paging": { - "pageIndex": 1, - "pageSize": 1, - "total": 2 - }, "users": [ - {"login": "ada", "name": "Ada Lovelace", "selected": true} - ] - }"""); + { + "p": 1, + "ps": 1, + "total": 2, + "paging": { + "pageIndex": 1, + "pageSize": 1, + "total": 2 + }, "users": [ + {"login": "ada", "name": "Ada Lovelace", "selected": true} + ] + }"""); assertJson(newUsersRequest() .setParam(PARAM_GROUP_NAME, group.getName()) @@ -275,18 +275,18 @@ public class UsersActionIT { .setParam(Param.SELECTED, SelectionMode.ALL.value()) .execute() .getInput()).isSimilarTo(""" - { - "p": 2, - "ps": 1, - "total": 2, - "paging": { - "pageIndex": 2, - "pageSize": 1, - "total": 2 - }, "users": [ - {"login": "grace", "name": "Grace Hopper", "selected": false} - ] - }"""); + { + "p": 2, + "ps": 1, + "total": 2, + "paging": { + "pageIndex": 2, + "pageSize": 1, + "total": 2 + }, "users": [ + {"login": "grace", "name": "Grace Hopper", "selected": false} + ] + }"""); } @Test @@ -303,58 +303,58 @@ public class UsersActionIT { .setParam(Param.SELECTED, SelectionMode.ALL.value()) .execute() .getInput()).isSimilarTo(""" - { - "users": [ - {"login": "ada.login", "name": "Ada Lovelace", "selected": true}, - {"login": "grace", "name": "Grace Hopper", "selected": false} - ] - } - """); + { + "users": [ + {"login": "ada.login", "name": "Ada Lovelace", "selected": true}, + {"login": "grace", "name": "Grace Hopper", "selected": false} + ] + } + """); assertJson(newUsersRequest().setParam(PARAM_GROUP_NAME, group.getName()) .setParam("q", ".logi") .execute() .getInput()).isSimilarTo(""" - { - "users": [ - { - "login": "ada.login", - "name": "Ada Lovelace", - "selected": true - } - ] - } - """); + { + "users": [ + { + "login": "ada.login", + "name": "Ada Lovelace", + "selected": true + } + ] + } + """); assertJson(newUsersRequest().setParam(PARAM_GROUP_NAME, group.getName()) .setParam("q", "OvE") .execute() .getInput()).isSimilarTo(""" - { - "users": [ - { - "login": "ada.login", - "name": "Ada Lovelace", - "selected": true - } - ] - } - """); + { + "users": [ + { + "login": "ada.login", + "name": "Ada Lovelace", + "selected": true + } + ] + } + """); assertJson(newUsersRequest().setParam(PARAM_GROUP_NAME, group.getName()) .setParam("q", "mail") .execute() .getInput()).isSimilarTo(""" - { - "users": [ - { - "login": "ada.login", - "name": "Ada Lovelace", - "selected": true - } - ] - } - """); + { + "users": [ + { + "login": "ada.login", + "name": "Ada Lovelace", + "selected": true + } + ] + } + """); } @Test @@ -385,14 +385,12 @@ public class UsersActionIT { } private void mockUsersAsManaged(String... userUuids) { - when(managedInstanceService.getUserUuidToManaged(any(), any())).thenAnswer(invocation -> - { - Set<?> allUsersUuids = invocation.getArgument(1, Set.class); - return allUsersUuids.stream() - .map(userUuid -> (String) userUuid) - .collect(toMap(identity(), userUuid -> Set.of(userUuids).contains(userUuid))); - } - ); + when(managedInstanceService.getUserUuidToManaged(any(), any())).thenAnswer(invocation -> { + Set<?> allUsersUuids = invocation.getArgument(1, Set.class); + return allUsersUuids.stream() + .map(String.class::cast) + .collect(toMap(identity(), userUuid -> Set.of(userUuids).contains(userUuid))); + }); } } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/SubmitActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/SubmitActionTest.java index 7e6c98453c4..5268fbe8b32 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/SubmitActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/SubmitActionTest.java @@ -93,13 +93,13 @@ public class SubmitActionTest { String devOpsPlatformUrl = "https://github.com"; String devOpsPlatformProjectIdentifier = "foo/bar"; - + String[] characteristics = { buildCharacteristicParam(BRANCH, "foo"), buildCharacteristicParam(PULL_REQUEST, "123"), buildCharacteristicParam("unsupported", "bar"), buildCharacteristicParam(DEVOPS_PLATFORM_URL, devOpsPlatformUrl), - buildCharacteristicParam(DEVOPS_PLATFORM_PROJECT_IDENTIFIER, devOpsPlatformProjectIdentifier) }; + buildCharacteristicParam(DEVOPS_PLATFORM_PROJECT_IDENTIFIER, devOpsPlatformProjectIdentifier)}; Ce.SubmitResponse submitResponse = tester.newRequest() .setParam("projectKey", "my_project") .setParam("projectName", "My Project") @@ -186,7 +186,7 @@ public class SubmitActionTest { .setMediaType(MediaTypes.PROTOBUF) .setMethod("POST"); - assertThatThrownBy(() -> request.execute()) + assertThatThrownBy(request::execute) .isInstanceOf(ServerException.class) .hasMessage("Error message"); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/health/HealthCheckerImplTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/health/HealthCheckerImplTest.java index edbd4a67eb6..d2854ebaaf6 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/health/HealthCheckerImplTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/health/HealthCheckerImplTest.java @@ -90,10 +90,10 @@ public class HealthCheckerImplTest { public void checkNode_returns_RED_status_if_at_least_one_RED_status_returned_by_NodeHealthCheck() { List<Health.Status> statuses = new ArrayList<>(); Stream.of( - IntStream.range(0, 1 + random.nextInt(20)).mapToObj(i -> RED), // at least 1 RED - IntStream.range(0, random.nextInt(20)).mapToObj(i -> YELLOW), // between 0 and 19 YELLOW - IntStream.range(0, random.nextInt(20)).mapToObj(i -> GREEN) // between 0 and 19 GREEN - ).flatMap(s -> s) + IntStream.range(0, 1 + random.nextInt(20)).mapToObj(i -> RED), // at least 1 RED + IntStream.range(0, random.nextInt(20)).mapToObj(i -> YELLOW), // between 0 and 19 YELLOW + IntStream.range(0, random.nextInt(20)).mapToObj(i -> GREEN) // between 0 and 19 GREEN + ).flatMap(s -> s) .forEach(statuses::add); Collections.shuffle(statuses); HealthCheckerImpl underTest = newNodeHealthCheckerImpl(statuses.stream()); @@ -121,7 +121,7 @@ public class HealthCheckerImplTest { when(nodeInformation.isStandalone()).thenReturn(true); HealthCheckerImpl underTest = new HealthCheckerImpl(nodeInformation, new NodeHealthCheck[0], new ClusterHealthCheck[0], sharedHealthState); - assertThatThrownBy(() -> underTest.checkCluster()) + assertThatThrownBy(underTest::checkCluster) .isInstanceOf(IllegalStateException.class) .hasMessageContaining("Clustering is not enabled"); } @@ -131,7 +131,7 @@ public class HealthCheckerImplTest { when(nodeInformation.isStandalone()).thenReturn(false); HealthCheckerImpl underTest = new HealthCheckerImpl(nodeInformation, new NodeHealthCheck[0], new ClusterHealthCheck[0], null); - assertThatThrownBy(() -> underTest.checkCluster()) + assertThatThrownBy(underTest::checkCluster) .isInstanceOf(IllegalStateException.class) .hasMessageContaining("HealthState instance can't be null when clustering is enabled"); } @@ -175,10 +175,10 @@ public class HealthCheckerImplTest { when(nodeInformation.isStandalone()).thenReturn(false); List<Health.Status> statuses = new ArrayList<>(); Stream.of( - IntStream.range(0, 1 + random.nextInt(20)).mapToObj(i -> RED), // at least 1 RED - IntStream.range(0, random.nextInt(20)).mapToObj(i -> YELLOW), // between 0 and 19 YELLOW - IntStream.range(0, random.nextInt(20)).mapToObj(i -> GREEN) // between 0 and 19 GREEN - ).flatMap(s -> s) + IntStream.range(0, 1 + random.nextInt(20)).mapToObj(i -> RED), // at least 1 RED + IntStream.range(0, random.nextInt(20)).mapToObj(i -> YELLOW), // between 0 and 19 YELLOW + IntStream.range(0, random.nextInt(20)).mapToObj(i -> GREEN) // between 0 and 19 GREEN + ).flatMap(s -> s) .forEach(statuses::add); Collections.shuffle(statuses); HealthCheckerImpl underTest = newClusterHealthCheckerImpl(statuses.stream()); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/health/HealthTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/health/HealthTest.java index 9417a15e888..8d996890f70 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/health/HealthTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/health/HealthTest.java @@ -42,7 +42,7 @@ public class HealthTest { public void build_throws_NPE_if_status_is_null() { Health.Builder builder = Health.builder(); - expectStatusNotNullNPE(() -> builder.build()); + expectStatusNotNullNPE(builder::build); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/HealthActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/HealthActionTest.java index e9d4a57c786..c4a78f599a2 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/HealthActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/HealthActionTest.java @@ -89,7 +89,7 @@ public class HealthActionTest { public void request_fails_with_ForbiddenException_when_anonymous() { TestRequest request = underTest.newRequest(); - expectForbiddenException(() -> request.execute()); + expectForbiddenException(request::execute); } @@ -98,7 +98,7 @@ public class HealthActionTest { when(systemPasscode.isValid(any())).thenReturn(false); TestRequest request = underTest.newRequest(); - expectForbiddenException(() -> request.execute()); + expectForbiddenException(request::execute); } @Test @@ -108,7 +108,7 @@ public class HealthActionTest { when(healthChecker.checkCluster()).thenReturn(randomStatusMinimalClusterHealth()); TestRequest request = underTest.newRequest(); - expectForbiddenException(() -> request.execute()); + expectForbiddenException(request::execute); } @Test @@ -269,13 +269,13 @@ public class HealthActionTest { .setStatus(NodeHealth.Status.values()[random.nextInt(NodeHealth.Status.values().length)]); IntStream.range(0, random.nextInt(4)).mapToObj(i -> secure().nextAlphabetic(5)).forEach(builder::addCause); return builder.setDetails( - newNodeDetailsBuilder() - .setType(random.nextBoolean() ? NodeDetails.Type.APPLICATION : NodeDetails.Type.SEARCH) - .setName(secure().nextAlphanumeric(3)) - .setHost(secure().nextAlphanumeric(4)) - .setPort(1 + random.nextInt(3)) - .setStartedAt(1 + random.nextInt(23)) - .build()) + newNodeDetailsBuilder() + .setType(random.nextBoolean() ? NodeDetails.Type.APPLICATION : NodeDetails.Type.SEARCH) + .setName(secure().nextAlphanumeric(3)) + .setHost(secure().nextAlphanumeric(4)) + .setPort(1 + random.nextInt(3)) + .setStartedAt(1 + random.nextInt(23)) + .build()) .build(); } @@ -284,13 +284,13 @@ public class HealthActionTest { .setStatus(NodeHealth.Status.values()[random.nextInt(NodeHealth.Status.values().length)]); IntStream.range(0, random.nextInt(4)).mapToObj(i -> secure().nextAlphabetic(5)).forEach(builder::addCause); return builder.setDetails( - newNodeDetailsBuilder() - .setType(type) - .setName(name) - .setHost(host) - .setPort(port) - .setStartedAt(started) - .build()) + newNodeDetailsBuilder() + .setType(type) + .setName(name) + .setHost(host) + .setPort(port) + .setStartedAt(started) + .build()) .build(); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/HealthCheckerModuleTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/HealthCheckerModuleTest.java index d17fb1a4ff6..cdce3b64794 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/HealthCheckerModuleTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/HealthCheckerModuleTest.java @@ -30,9 +30,9 @@ import org.sonar.server.common.health.ClusterHealthCheck; import org.sonar.server.common.health.DbConnectionNodeCheck; import org.sonar.server.common.health.EsStatusClusterCheck; import org.sonar.server.common.health.EsStatusNodeCheck; -import org.sonar.server.health.HealthCheckerImpl; import org.sonar.server.common.health.NodeHealthCheck; import org.sonar.server.common.health.WebServerStatusNodeCheck; +import org.sonar.server.health.HealthCheckerImpl; import org.sonar.server.platform.NodeInformation; import static org.assertj.core.api.Assertions.assertThat; @@ -67,7 +67,7 @@ public class HealthCheckerModuleTest { underTest.configure(container); List<Class<?>> checks = container.getAddedObjects().stream() - .filter(o -> o instanceof Class) + .filter(Class.class::isInstance) .map(o -> (Class<?>) o) .filter(NodeHealthCheck.class::isAssignableFrom).collect(Collectors.toList()); assertThat(checks).containsOnly(WebServerStatusNodeCheck.class, DbConnectionNodeCheck.class, EsStatusNodeCheck.class, CeStatusNodeCheck.class); @@ -81,7 +81,7 @@ public class HealthCheckerModuleTest { underTest.configure(container); List<Class<?>> checks = container.getAddedObjects().stream() - .filter(o -> o instanceof Class) + .filter(Class.class::isInstance) .map(o -> (Class<?>) o) .filter(NodeHealthCheck.class::isAssignableFrom).collect(Collectors.toList()); assertThat(checks).containsOnly(WebServerStatusNodeCheck.class, DbConnectionNodeCheck.class, CeStatusNodeCheck.class); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/SafeModeHealthActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/SafeModeHealthActionTest.java index e750f8ea2d7..6764890dc9c 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/SafeModeHealthActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/SafeModeHealthActionTest.java @@ -69,7 +69,7 @@ class SafeModeHealthActionTest { when(systemPasscode.isValid(any())).thenReturn(false); TestRequest request = underTest.newRequest(); - expectForbiddenException(() -> request.execute()); + expectForbiddenException(request::execute); } @ParameterizedTest diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/SafeModeHealthCheckerModuleTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/SafeModeHealthCheckerModuleTest.java index b3e988bd56c..270a0cdd371 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/SafeModeHealthCheckerModuleTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/SafeModeHealthCheckerModuleTest.java @@ -25,9 +25,9 @@ import org.junit.Test; import org.sonar.core.platform.ListContainer; import org.sonar.server.common.health.DbConnectionNodeCheck; import org.sonar.server.common.health.EsStatusNodeCheck; -import org.sonar.server.health.HealthCheckerImpl; import org.sonar.server.common.health.NodeHealthCheck; import org.sonar.server.common.health.WebServerSafemodeNodeCheck; +import org.sonar.server.health.HealthCheckerImpl; import static org.assertj.core.api.Assertions.assertThat; @@ -54,7 +54,7 @@ public class SafeModeHealthCheckerModuleTest { underTest.configure(container); List<Class<?>> checks = container.getAddedObjects().stream() - .filter(o -> o instanceof Class) + .filter(Class.class::isInstance) .map(o -> (Class<?>) o) .filter(NodeHealthCheck.class::isAssignableFrom) .collect(Collectors.toList()); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/QProfileReferenceTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/QProfileReferenceTest.java index 4b1ee2c733f..bba1b558bfc 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/QProfileReferenceTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/QProfileReferenceTest.java @@ -30,7 +30,6 @@ import static org.sonar.server.language.LanguageTesting.newLanguage; public class QProfileReferenceTest { - @Test public void fromKey_creates_reference_by_key() { QProfileReference ref = QProfileReference.fromKey("foo"); @@ -42,7 +41,7 @@ public class QProfileReferenceTest { public void getLanguage_throws_ISE_on_reference_by_key() { QProfileReference ref = QProfileReference.fromKey("foo"); - assertThatThrownBy(() -> ref.getLanguage()) + assertThatThrownBy(ref::getLanguage) .isInstanceOf(IllegalStateException.class) .hasMessage("Language is not defined. Please call hasKey()."); } @@ -51,7 +50,7 @@ public class QProfileReferenceTest { public void getName_throws_ISE_on_reference_by_key() { QProfileReference ref = QProfileReference.fromKey("foo"); - assertThatThrownBy(() -> ref.getName()) + assertThatThrownBy(ref::getName) .isInstanceOf(IllegalStateException.class) .hasMessage("Name is not defined. Please call hasKey()."); } @@ -68,7 +67,7 @@ public class QProfileReferenceTest { public void getKey_throws_ISE_on_reference_by_name() { QProfileReference ref = QProfileReference.fromName("js", "Sonar way"); - assertThatThrownBy(() -> ref.getKey()) + assertThatThrownBy(ref::getKey) .isInstanceOf(IllegalStateException.class) .hasMessage("Key is not defined. Please call hasKey()."); } |