diff options
author | Julien Camus <julien.camus@sonarsource.com> | 2024-12-19 14:14:10 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2024-12-19 20:03:04 +0000 |
commit | 8fe712960e07591f6cc2f8aa2e164a6eb9ad67fa (patch) | |
tree | 2dc4a7534b311092542ebacdbd22af13c47b823e /server/sonar-webserver-webapi | |
parent | 1b2aa4e56280456d456ef960671423f543dba283 (diff) | |
download | sonarqube-8fe712960e07591f6cc2f8aa2e164a6eb9ad67fa.tar.gz sonarqube-8fe712960e07591f6cc2f8aa2e164a6eb9ad67fa.zip |
SONAR-23990 Replace with text block
Diffstat (limited to 'server/sonar-webserver-webapi')
11 files changed, 446 insertions, 423 deletions
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/AppActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/AppActionIT.java index 3fbfbdb96b5..45f252a176f 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/AppActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/AppActionIT.java @@ -69,6 +69,7 @@ public class AppActionIT { projectData = db.components().insertPrivateProject(); mainBranchComponent = projectData.getMainBranchComponent(); } + @Test public void file_info() { ComponentDto directory = db.components().insertComponent(newDirectory(mainBranchComponent, "src")); @@ -134,9 +135,11 @@ public class AppActionIT { .execute() .getInput(); - assertJson(result).isSimilarTo("{\n" + - " \"measures\": {}\n" + - "}\n"); + assertJson(result).isSimilarTo(""" + { + "measures": {} + } + """); } @Test @@ -152,21 +155,22 @@ public class AppActionIT { userSession.logIn("john").addProjectPermission(USER, projectData.getProjectDto()) .registerBranches(projectData.getMainBranchDto()); - String result = ws.newRequest() .setParam("component", file.getKey()) .execute() .getInput(); - assertJson(result).isSimilarTo("{\n" + - " \"measures\": {\n" + - " \"lines\": \"200.0\",\n" + - " \"coverage\": \"95.4\",\n" + - " \"duplicationDensity\": \"7.4\",\n" + - " \"issues\": \"231.0\",\n" + - " \"tests\": \"3.0\"\n" + - " }" + - "}\n"); + assertJson(result).isSimilarTo(""" + { + "measures": { + "lines": "200.0", + "coverage": "95.4", + "duplicationDensity": "7.4", + "issues": "231.0", + "tests": "3.0" + }\ + } + """); } @Test @@ -200,9 +204,11 @@ public class AppActionIT { .execute() .getInput(); - assertJson(result).isSimilarTo("{\n" + - " \"canMarkAsFavorite\": true,\n" + - "}\n"); + assertJson(result).isSimilarTo(""" + { + "canMarkAsFavorite": true, + } + """); } @Test @@ -215,9 +221,11 @@ public class AppActionIT { .execute() .getInput(); - assertJson(result).isSimilarTo("{\n" + - " \"canMarkAsFavorite\": false,\n" + - "}\n"); + assertJson(result).isSimilarTo(""" + { + "canMarkAsFavorite": false, + } + """); } @Test @@ -234,9 +242,11 @@ public class AppActionIT { .execute() .getInput(); - assertJson(result).isSimilarTo("{\n" + - " \"fav\": true,\n" + - "}\n"); + assertJson(result).isSimilarTo(""" + { + "fav": true, + } + """); } @Test @@ -249,9 +259,11 @@ public class AppActionIT { .execute() .getInput(); - assertJson(result).isSimilarTo("{\n" + - " \"fav\": false,\n" + - "}\n"); + assertJson(result).isSimilarTo(""" + { + "fav": false, + } + """); } @Test diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/duplication/ws/DuplicationsParserIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/duplication/ws/DuplicationsParserIT.java index a53261fc569..695d72d6680 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/duplication/ws/DuplicationsParserIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/duplication/ws/DuplicationsParserIT.java @@ -55,12 +55,13 @@ public class DuplicationsParserIT { ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent(); ComponentDto file = db.components().insertComponent(newFileDto(project)); List<DuplicationsParser.Block> blocks = parser.parse(db.getSession(), file, null, null, - format("<duplications>\n" + - " <g>\n" + - " <b s=\"31\" l=\"5\" r=\"%s\"/>\n" + - " <b s=\"20\" l=\"5\" r=\"%s\"/>\n" + - " </g>\n" + - "</duplications>", file.getKey(), file.getKey())); + format(""" + <duplications> + <g> + <b s="31" l="5" r="%s"/> + <b s="20" l="5" r="%s"/> + </g> + </duplications>""", file.getKey(), file.getKey())); assertThat(blocks).hasSize(1); List<Duplication> duplications = blocks.get(0).getDuplications(); @@ -84,12 +85,13 @@ public class DuplicationsParserIT { ComponentDto file1 = db.components().insertComponent(newFileDto(project)); ComponentDto file2 = db.components().insertComponent(newFileDto(project)); List<DuplicationsParser.Block> blocks = parser.parse(db.getSession(), file1, null, null, - format("<duplications>\n" + - " <g>\n" + - " <b s=\"20\" l=\"5\" r=\"%s\"/>\n" + - " <b s=\"31\" l=\"5\" r=\"%s\"/>\n" + - " </g>\n" + - "</duplications>", file2.getKey(), file1.getKey())); + format(""" + <duplications> + <g> + <b s="20" l="5" r="%s"/> + <b s="31" l="5" r="%s"/> + </g> + </duplications>""", file2.getKey(), file1.getKey())); assertThat(blocks).hasSize(1); List<Duplication> duplications = blocks.get(0).getDuplications(); @@ -115,13 +117,14 @@ public class DuplicationsParserIT { ComponentDto project2 = db.components().insertPrivateProject().getMainBranchComponent(); ComponentDto fileOnProject2 = db.components().insertComponent(newFileDto(project2)); List<DuplicationsParser.Block> blocks = parser.parse(db.getSession(), file1, null, null, - format("<duplications>\n" + - " <g>\n" + - " <b s=\"148\" l=\"24\" r=\"%s\"/>\n" + - " <b s=\"137\" l=\"24\" r=\"%s\"/>\n" + - " <b s=\"111\" l=\"24\" r=\"%s\"/>\n" + - " </g>\n" + - "</duplications>", file1.getKey(), fileOnProject2.getKey(), file2.getKey())); + format(""" + <duplications> + <g> + <b s="148" l="24" r="%s"/> + <b s="137" l="24" r="%s"/> + <b s="111" l="24" r="%s"/> + </g> + </duplications>""", file1.getKey(), fileOnProject2.getKey(), file2.getKey())); assertThat(blocks).hasSize(1); List<Duplication> duplications = blocks.get(0).getDuplications(); @@ -158,16 +161,18 @@ public class DuplicationsParserIT { .setKey("com.sonarsource.orchestrator:sonar-orchestrator:src/main/java/com/sonar/orchestrator/util/CommandExecutor.java") .setLongName("CommandExecutor")); List<DuplicationsParser.Block> blocks = parser.parse(db.getSession(), file1, null, null, - format("<duplications>\n" + - " <g>\n" + - " <b s=\"94\" l=\"101\" r=\"%s\"/>\n" + - " <b s=\"83\" l=\"101\" r=\"%s\"/>\n" + - " </g>\n" + - " <g>\n" + - " <b s=\"38\" l=\"40\" r=\"%s\"/>\n" + - " <b s=\"29\" l=\"39\" r=\"%s\"/>\n" + - " </g>\n" + - "</duplications>\n", file2.getKey(), file1.getKey(), file2.getKey(), file1.getKey())); + format(""" + <duplications> + <g> + <b s="94" l="101" r="%s"/> + <b s="83" l="101" r="%s"/> + </g> + <g> + <b s="38" l="40" r="%s"/> + <b s="29" l="39" r="%s"/> + </g> + </duplications> + """, file2.getKey(), file1.getKey(), file2.getKey(), file1.getKey())); assertThat(blocks).hasSize(2); // Block with smaller line should come first @@ -184,12 +189,13 @@ public class DuplicationsParserIT { ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent(); ComponentDto file = db.components().insertComponent(newFileDto(project)); List<DuplicationsParser.Block> blocks = parser.parse(db.getSession(), file, null, null, - format("<duplications>\n" + - " <g>\n" + - " <b s=\"20\" l=\"5\" r=\"%s\"/>\n" + - " <b s=\"31\" l=\"5\" r=\"%s\"/>\n" + - " </g>\n" + - "</duplications>", file.getKey(), "not_existing")); + format(""" + <duplications> + <g> + <b s="20" l="5" r="%s"/> + <b s="31" l="5" r="%s"/> + </g> + </duplications>""", file.getKey(), "not_existing")); assertThat(blocks).hasSize(1); List<Duplication> duplications = blocks.get(0).getDuplications(); @@ -255,12 +261,13 @@ public class DuplicationsParserIT { ComponentDto file1 = db.components().insertComponent(newFileDto(branch, project.uuid())); ComponentDto file2 = db.components().insertComponent(newFileDto(branch, project.uuid())); List<DuplicationsParser.Block> blocks = parser.parse(db.getSession(), file1, branchName, null, - format("<duplications>\n" + - " <g>\n" + - " <b s=\"20\" l=\"5\" r=\"%s\"/>\n" + - " <b s=\"31\" l=\"5\" r=\"%s\"/>\n" + - " </g>\n" + - "</duplications>", file2.getKey(), file1.getKey())); + format(""" + <duplications> + <g> + <b s="20" l="5" r="%s"/> + <b s="31" l="5" r="%s"/> + </g> + </duplications>""", file2.getKey(), file1.getKey())); assertThat(blocks).hasSize(1); List<Duplication> duplications = blocks.get(0).getDuplications(); @@ -290,12 +297,13 @@ public class DuplicationsParserIT { ComponentDto file1 = db.components().insertComponent(newFileDto(pullRequest)); ComponentDto file2 = db.components().insertComponent(newFileDto(pullRequest)); List<DuplicationsParser.Block> blocks = parser.parse(db.getSession(), file1, null, pullRequestKey, - format("<duplications>\n" + - " <g>\n" + - " <b s=\"20\" l=\"5\" r=\"%s\"/>\n" + - " <b s=\"31\" l=\"5\" r=\"%s\"/>\n" + - " </g>\n" + - "</duplications>", file2.getKey(), file1.getKey())); + format(""" + <duplications> + <g> + <b s="20" l="5" r="%s"/> + <b s="31" l="5" r="%s"/> + </g> + </duplications>""", file2.getKey(), file1.getKey())); assertThat(blocks).hasSize(1); List<Duplication> duplications = blocks.get(0).getDuplications(); diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/permission/ws/GroupsActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/permission/ws/GroupsActionIT.java index d333314cb51..0bdc3d25816 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/permission/ws/GroupsActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/permission/ws/GroupsActionIT.java @@ -22,18 +22,18 @@ package org.sonar.server.permission.ws; import java.util.Set; import org.junit.Before; import org.junit.Test; -import org.sonar.db.component.ComponentQualifiers; -import org.sonar.server.component.ComponentTypes; import org.sonar.api.security.DefaultGroups; import org.sonar.api.server.ws.Change; import org.sonar.api.server.ws.WebService.Action; import org.sonar.api.web.UserRole; import org.sonar.db.component.ComponentDto; -import org.sonar.server.component.ComponentTypesRule; +import org.sonar.db.component.ComponentQualifiers; import org.sonar.db.permission.GlobalPermission; import org.sonar.db.portfolio.PortfolioDto; import org.sonar.db.project.ProjectDto; import org.sonar.db.user.GroupDto; +import org.sonar.server.component.ComponentTypes; +import org.sonar.server.component.ComponentTypesRule; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; @@ -297,25 +297,24 @@ public class GroupsActionIT extends BasePermissionWsIT<GroupsAction> { .execute() .getInput(); - assertJson(result).isSimilarTo( - "{\n" - + " \"paging\": {\n" - + " \"pageIndex\": 1,\n" - + " \"pageSize\": 20,\n" - + " \"total\": 2\n" - + " },\n" - + " \"groups\": [\n" - + " {\n" - + " \"name\": \"local-group\",\n" - + " \"managed\": false\n" - + " },\n" - + " {\n" - + " \"name\": \"managed-group\",\n" - + " \"managed\": true\n" - + " }\n" - + " ]\n" - + "}" - ); + assertJson(result).isSimilarTo(""" + { + "paging": { + "pageIndex": 1, + "pageSize": 20, + "total": 2 + }, + "groups": [ + { + "name": "local-group", + "managed": false + }, + { + "name": "managed-group", + "managed": true + } + ] + }"""); } @Test @@ -375,13 +374,11 @@ public class GroupsActionIT extends BasePermissionWsIT<GroupsAction> { } private void mockGroupsAsManaged(String... groupUuids) { - when(managedInstanceService.getGroupUuidToManaged(any(), any())).thenAnswer(invocation -> - { - Set<?> allGroupUuids = invocation.getArgument(1, Set.class); - return allGroupUuids.stream() - .map(groupUuid -> (String) groupUuid) - .collect(toMap(identity(), userUuid -> Set.of(groupUuids).contains(userUuid))); - } - ); + when(managedInstanceService.getGroupUuidToManaged(any(), any())).thenAnswer(invocation -> { + Set<?> allGroupUuids = invocation.getArgument(1, Set.class); + return allGroupUuids.stream() + .map(groupUuid -> (String) groupUuid) + .collect(toMap(identity(), userUuid -> Set.of(groupUuids).contains(userUuid))); + }); } } diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/permission/ws/UsersActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/permission/ws/UsersActionIT.java index d675080919e..08f78b290ab 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/permission/ws/UsersActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/permission/ws/UsersActionIT.java @@ -21,19 +21,19 @@ package org.sonar.server.permission.ws; import java.util.Set; import org.junit.Test; -import org.sonar.db.component.ComponentQualifiers; -import org.sonar.server.component.ComponentTypes; import org.sonar.api.server.ws.WebService.Param; import org.sonar.api.server.ws.WebService.SelectionMode; import org.sonar.api.web.UserRole; import org.sonar.db.component.BranchDto; import org.sonar.db.component.ComponentDto; +import org.sonar.db.component.ComponentQualifiers; import org.sonar.db.component.ProjectData; -import org.sonar.server.component.ComponentTypesRule; import org.sonar.db.permission.GlobalPermission; import org.sonar.db.project.ProjectDto; import org.sonar.db.user.UserDto; import org.sonar.server.common.avatar.AvatarResolverImpl; +import org.sonar.server.component.ComponentTypes; +import org.sonar.server.component.ComponentTypesRule; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; @@ -220,36 +220,38 @@ public class UsersActionIT extends BasePermissionWsIT<UsersAction> { } loginAsAdmin(); - assertJson(newRequest().setParam(PAGE, "1").setParam(PAGE_SIZE, "2").execute().getInput()).withStrictArrayOrder().isSimilarTo("{\n" + - " \"paging\": {\n" + - " \"pageIndex\": 1,\n" + - " \"pageSize\": 2,\n" + - " \"total\": 10\n" + - " },\n" + - " \"users\": [\n" + - " {\n" + - " \"name\": \"user-0\"\n" + - " },\n" + - " {\n" + - " \"name\": \"user-1\"\n" + - " }\n" + - " ]\n" + - "}"); - assertJson(newRequest().setParam(PAGE, "3").setParam(PAGE_SIZE, "4").execute().getInput()).withStrictArrayOrder().isSimilarTo("{\n" + - " \"paging\": {\n" + - " \"pageIndex\": 3,\n" + - " \"pageSize\": 4,\n" + - " \"total\": 10\n" + - " },\n" + - " \"users\": [\n" + - " {\n" + - " \"name\": \"user-8\"\n" + - " },\n" + - " {\n" + - " \"name\": \"user-9\"\n" + - " }\n" + - " ]\n" + - "}"); + assertJson(newRequest().setParam(PAGE, "1").setParam(PAGE_SIZE, "2").execute().getInput()).withStrictArrayOrder().isSimilarTo(""" + { + "paging": { + "pageIndex": 1, + "pageSize": 2, + "total": 10 + }, + "users": [ + { + "name": "user-0" + }, + { + "name": "user-1" + } + ] + }"""); + assertJson(newRequest().setParam(PAGE, "3").setParam(PAGE_SIZE, "4").execute().getInput()).withStrictArrayOrder().isSimilarTo(""" + { + "paging": { + "pageIndex": 3, + "pageSize": 4, + "total": 10 + }, + "users": [ + { + "name": "user-8" + }, + { + "name": "user-9" + } + ] + }"""); } @Test @@ -316,8 +318,8 @@ public class UsersActionIT extends BasePermissionWsIT<UsersAction> { .setParam(PARAM_PROJECT_ID, project.uuid()) .setParam(PARAM_PROJECT_KEY, project.getKey()) .execute()) - .isInstanceOf(BadRequestException.class) - .hasMessage("Project id or project key can be provided, not both."); + .isInstanceOf(BadRequestException.class) + .hasMessage("Project id or project key can be provided, not both."); } @Test @@ -359,13 +361,11 @@ public class UsersActionIT extends BasePermissionWsIT<UsersAction> { } 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(userUuid -> (String) userUuid) + .collect(toMap(identity(), userUuid -> Set.of(userUuids).contains(userUuid))); + }); } } diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualityprofile/ws/ChangelogActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualityprofile/ws/ChangelogActionIT.java index 184da7022de..efad6972423 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualityprofile/ws/ChangelogActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualityprofile/ws/ChangelogActionIT.java @@ -86,10 +86,10 @@ class ChangelogActionIT { RuleChangeDto ruleChange = insertRuleChange(CLEAR, TESTED, rule.getUuid(), Set.of(new RuleImpactChangeDto(MAINTAINABILITY, SECURITY, HIGH, MEDIUM))); insertChange(profile, ActiveRuleChange.Type.ACTIVATED, user, ImmutableMap.of( - "ruleUuid", rule.getUuid(), - "severity", "MINOR", - "param_foo", "foo_value", - "param_bar", "bar_value"), + "ruleUuid", rule.getUuid(), + "severity", "MINOR", + "param_foo", "foo_value", + "param_bar", "bar_value"), ruleChange); String response = ws.newRequest() @@ -154,10 +154,10 @@ class ChangelogActionIT { RuleChangeDto ruleChange = insertRuleChange(COMPLETE, FOCUSED, rule.getUuid(), Set.of(new RuleImpactChangeDto(MAINTAINABILITY, null, HIGH, null), new RuleImpactChangeDto(null, RELIABILITY, null, LOW))); insertChange(profile, ActiveRuleChange.Type.DEACTIVATED, user, ImmutableMap.of( - "ruleUuid", rule.getUuid(), - "severity", "MINOR", - "param_foo", "foo_value", - "param_bar", "bar_value"), + "ruleUuid", rule.getUuid(), + "severity", "MINOR", + "param_foo", "foo_value", + "param_bar", "bar_value"), ruleChange); String response = ws.newRequest() @@ -343,9 +343,10 @@ class ChangelogActionIT { .setParam(PARAM_QUALITY_PROFILE, qualityProfile.getName()) .setParam(PARAM_SINCE, "2011-04-25T01:15:43+0100") .execute() - .getInput()).isSimilarTo("{\n" + - " \"events\": []\n" + - "}"); + .getInput()).isSimilarTo(""" + { + "events": [] + }"""); } @Test @@ -452,7 +453,7 @@ class ChangelogActionIT { system2.setNow(DateUtils.parseDateTime(DATE).getTime()); RuleDto rule = db.rules().insert(); UserDto user = db.users().insertUser(); - //ACTIVATED and DEACTIVATED rules must always appear + // ACTIVATED and DEACTIVATED rules must always appear insertChange(qualityProfile, ActiveRuleChange.Type.ACTIVATED, user, Map.of("ruleUuid", rule.getUuid())); insertChange(qualityProfile, ActiveRuleChange.Type.DEACTIVATED, user, Map.of("ruleUuid", rule.getUuid())); // Changes with data must appear in STANDARD mode @@ -547,7 +548,7 @@ class ChangelogActionIT { system2.setNow(DateUtils.parseDateTime(DATE).getTime()); RuleDto rule = db.rules().insert(); UserDto user = db.users().insertUser(); - //ACTIVATED and DEACTIVATED rules must always appear + // ACTIVATED and DEACTIVATED rules must always appear insertChange(qualityProfile, ActiveRuleChange.Type.ACTIVATED, user, Map.of("ruleUuid", rule.getUuid())); insertChange(qualityProfile, ActiveRuleChange.Type.DEACTIVATED, user, Map.of("ruleUuid", rule.getUuid())); // Changes without rule_change must not appear in MQR mode @@ -670,8 +671,7 @@ class ChangelogActionIT { """.formatted(DATE, user.getLogin(), user.getName(), rule.getKey(), rule.getName(), DATE, user.getLogin(), user.getName(), rule.getKey(), rule.getName(), DATE, user.getLogin(), user.getName(), rule.getKey(), rule.getName(), - DATE, user.getLogin(), user.getName(), rule.getKey(), rule.getName() - )); + DATE, user.getLogin(), user.getName(), rule.getKey(), rule.getName())); } @Test @@ -734,7 +734,7 @@ class ChangelogActionIT { } private void insertChange(QProfileDto profile, ActiveRuleChange.Type type, @Nullable UserDto user, @Nullable Map<String, Object> data, - @Nullable RuleChangeDto ruleChange) { + @Nullable RuleChangeDto ruleChange) { insertChange(c -> c.setRulesProfileUuid(profile.getRulesProfileUuid()) .setUserUuid(user == null ? null : user.getUuid()) .setSqVersion("7.6") diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/rule/ws/CreateActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/rule/ws/CreateActionIT.java index 897136c0b45..981f07e5e7c 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/rule/ws/CreateActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/rule/ws/CreateActionIT.java @@ -224,16 +224,18 @@ public class CreateActionIT { .execute(); assertThat(response.getStatus()).isEqualTo(409); - assertJson(response.getInput()).isSimilarTo("{\n" + - " \"rule\": {\n" + - " \"key\": \"java:MY_CUSTOM\",\n" + - " \"repo\": \"java\",\n" + - " \"name\": \"My custom rule\",\n" + - " \"severity\": \"MAJOR\",\n" + - " \"status\": \"REMOVED\",\n" + - " \"isTemplate\": false\n" + - " }\n" + - "}\n"); + assertJson(response.getInput()).isSimilarTo(""" + { + "rule": { + "key": "java:MY_CUSTOM", + "repo": "java", + "name": "My custom rule", + "severity": "MAJOR", + "status": "REMOVED", + "isTemplate": false + } + } + """); } @Test @@ -308,11 +310,13 @@ public class CreateActionIT { .setParam("type", BUG.name()) .execute().getInput(); - assertJson(result).isSimilarTo("{\n" + - " \"rule\": {\n" + - " \"severity\": \"MAJOR\"" + - " }\n" + - "}\n"); + assertJson(result).isSimilarTo(""" + { + "rule": { + "severity": "MAJOR"\ + } + } + """); } @Test diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/IndexActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/IndexActionIT.java index ba218d3a3ce..ca624e8ce9f 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/IndexActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/IndexActionIT.java @@ -63,12 +63,13 @@ public class IndexActionIT { .setParam("resource", file.getKey()) .execute(); - assertJson(request.getInput()).isSimilarTo("[\n" + - " {\n" + - " \"1\": \"public class HelloWorld {\",\n" + - " \"2\": \"}\"\n" + - " }\n" + - "]"); + assertJson(request.getInput()).isSimilarTo(""" + [ + { + "1": "public class HelloWorld {", + "2": "}" + } + ]"""); } @Test @@ -84,12 +85,13 @@ public class IndexActionIT { .setParam("to", "5") .execute(); - assertJson(request.getInput()).isSimilarTo("[\n" + - " {\n" + - " \"3\": \"public class HelloWorld {\",\n" + - " \"4\": \"}\"\n" + - " }\n" + - "]"); + assertJson(request.getInput()).isSimilarTo(""" + [ + { + "3": "public class HelloWorld {", + "4": "}" + } + ]"""); } @Test @@ -101,7 +103,7 @@ public class IndexActionIT { assertThatThrownBy(() -> tester.newRequest() .setParam("resource", file.getKey()) .execute()) - .isInstanceOf(ForbiddenException.class); + .isInstanceOf(ForbiddenException.class); } @Test @@ -109,7 +111,7 @@ public class IndexActionIT { assertThatThrownBy(() -> tester.newRequest() .setParam("resource", "unknown") .execute()) - .isInstanceOf(NotFoundException.class); + .isInstanceOf(NotFoundException.class); } private static DbFileSources.Data newData(String... lines) { diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ui/ws/ComponentActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ui/ws/ComponentActionIT.java index 78b52883d9f..cc36de7dbde 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ui/ws/ComponentActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/ui/ws/ComponentActionIT.java @@ -28,10 +28,6 @@ import org.junit.Rule; import org.junit.Test; import org.sonar.api.CoreProperties; import org.sonar.api.config.Configuration; -import org.sonar.db.component.ComponentQualifiers; -import org.sonar.server.component.ComponentType; -import org.sonar.server.component.ComponentTypes; -import org.sonar.db.component.ComponentScopes; import org.sonar.api.server.ws.Change; import org.sonar.api.server.ws.WebService; import org.sonar.api.utils.System2; @@ -39,7 +35,6 @@ import org.sonar.api.web.UserRole; import org.sonar.api.web.page.Page; import org.sonar.api.web.page.Page.Qualifier; import org.sonar.api.web.page.PageDefinition; -import org.sonar.server.component.DefaultComponentTypes; import org.sonar.core.extension.CoreExtensionRepository; import org.sonar.core.platform.PluginInfo; import org.sonar.core.platform.PluginRepository; @@ -49,6 +44,8 @@ import org.sonar.db.component.BranchDto; import org.sonar.db.component.BranchType; import org.sonar.db.component.ComponentDbTester; import org.sonar.db.component.ComponentDto; +import org.sonar.db.component.ComponentQualifiers; +import org.sonar.db.component.ComponentScopes; import org.sonar.db.component.ProjectData; import org.sonar.db.component.SnapshotDto; import org.sonar.db.metric.MetricDto; @@ -60,6 +57,9 @@ import org.sonar.db.qualitygate.QualityGateDto; import org.sonar.db.qualityprofile.QProfileDto; import org.sonar.db.user.UserDto; import org.sonar.server.component.ComponentFinder; +import org.sonar.server.component.ComponentType; +import org.sonar.server.component.ComponentTypes; +import org.sonar.server.component.DefaultComponentTypes; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; @@ -187,14 +187,16 @@ public class ComponentActionIT { .execute() .getInput(); - assertJson(json).isSimilarTo("{\n" + - " \"key\": \"polop\",\n" + - " \"isFavorite\": true,\n" + - " \"id\": \"xyz\",\n" + - " \"branch\": \"feature1\"," + - " \"name\": \"Polop\",\n" + - " \"description\": \"test project\"\n" + - "}\n"); + assertJson(json).isSimilarTo(""" + { + "key": "polop", + "isFavorite": true, + "id": "xyz", + "branch": "feature1",\ + "name": "Polop", + "description": "test project" + } + """); } @Test @@ -218,11 +220,11 @@ public class ComponentActionIT { .getInput(); assertJson(json).isSimilarTo("{" + - " \"key\": \"" + subportfolio.getKey() + "\"," + - " \"isFavorite\": true," + - " \"id\": \"" + subportfolio.uuid() + "\"," + - " \"name\": \"" + subportfolio.name() + "\"" + - "}"); + " \"key\": \"" + subportfolio.getKey() + "\"," + + " \"isFavorite\": true," + + " \"id\": \"" + subportfolio.uuid() + "\"," + + " \"name\": \"" + subportfolio.name() + "\"" + + "}"); } @Test @@ -245,11 +247,11 @@ public class ComponentActionIT { .getInput(); assertJson(json).isSimilarTo("{" + - " \"key\": \"" + portfolio.getKey() + "\"," + - " \"isFavorite\": true," + - " \"id\": \"" + portfolio.uuid() + "\"," + - " \"name\": \"" + portfolio.name() + "\"" + - "}"); + " \"key\": \"" + portfolio.getKey() + "\"," + + " \"isFavorite\": true," + + " \"id\": \"" + portfolio.uuid() + "\"," + + " \"name\": \"" + portfolio.name() + "\"" + + "}"); } @Test @@ -280,14 +282,14 @@ public class ComponentActionIT { // access to all projects (project11, project12) String json = execute(application1.projectKey()); assertJson(json).isSimilarTo("{" + - "\"canBrowseAllChildProjects\":true" + - "}"); + "\"canBrowseAllChildProjects\":true" + + "}"); // access to some projects (project11) json = execute(application2.projectKey()); assertJson(json).isSimilarTo("{" + - "\"canBrowseAllChildProjects\":false" + - "}"); + "\"canBrowseAllChildProjects\":false" + + "}"); } @Test @@ -341,27 +343,27 @@ public class ComponentActionIT { .getInput(); assertJson(json).isSimilarTo("{\n" + - " \"key\": \"" + fileDto.getKey() + "\",\n" + - " \"branch\": \"feature1\",\n" + - " \"name\": \"Main.xoo\",\n" + - " \"breadcrumbs\": [\n" + - " {\n" + - " \"key\": \"sample\",\n" + - " \"name\": \"Sample\",\n" + - " \"qualifier\": \"TRK\"\n" + - " },\n" + - " {\n" + - " \"key\": \"sample:src\",\n" + - " \"name\": \"src\",\n" + - " \"qualifier\": \"DIR\"\n" + - " },\n" + - " {\n" + - " \"key\": \"" + fileDto.getKey() + "\",\n" + - " \"name\": \"Main.xoo\",\n" + - " \"qualifier\": \"FIL\"\n" + - " }\n" + - " ]\n" + - "}\n"); + " \"key\": \"" + fileDto.getKey() + "\",\n" + + " \"branch\": \"feature1\",\n" + + " \"name\": \"Main.xoo\",\n" + + " \"breadcrumbs\": [\n" + + " {\n" + + " \"key\": \"sample\",\n" + + " \"name\": \"Sample\",\n" + + " \"qualifier\": \"TRK\"\n" + + " },\n" + + " {\n" + + " \"key\": \"sample:src\",\n" + + " \"name\": \"src\",\n" + + " \"qualifier\": \"DIR\"\n" + + " },\n" + + " {\n" + + " \"key\": \"" + fileDto.getKey() + "\",\n" + + " \"name\": \"Main.xoo\",\n" + + " \"qualifier\": \"FIL\"\n" + + " }\n" + + " ]\n" + + "}\n"); } @Test @@ -566,21 +568,22 @@ public class ComponentActionIT { String json = execute(project.projectKey()); - assertJson(json).isSimilarTo("{\n" + - " \"configuration\": {\n" + - " \"showSettings\": true,\n" + - " \"showQualityProfiles\": true,\n" + - " \"showQualityGates\": true,\n" + - " \"showLinks\": true,\n" + - " \"showPermissions\": true,\n" + - " \"showHistory\": true,\n" + - " \"showUpdateKey\": true,\n" + - " \"showBackgroundTasks\": true,\n" + - " \"canApplyPermissionTemplate\": false,\n" + - " \"canBrowseProject\": true,\n" + - " \"canUpdateProjectVisibilityToPrivate\": true\n" + - " }\n" + - "}"); + assertJson(json).isSimilarTo(""" + { + "configuration": { + "showSettings": true, + "showQualityProfiles": true, + "showQualityGates": true, + "showLinks": true, + "showPermissions": true, + "showHistory": true, + "showUpdateKey": true, + "showBackgroundTasks": true, + "canApplyPermissionTemplate": false, + "canBrowseProject": true, + "canUpdateProjectVisibilityToPrivate": true + } + }"""); } @Test @@ -595,21 +598,22 @@ public class ComponentActionIT { String json = execute(project.projectKey()); - assertJson(json).isSimilarTo("{\n" + - " \"configuration\": {\n" + - " \"showSettings\": true,\n" + - " \"showQualityProfiles\": true,\n" + - " \"showQualityGates\": true,\n" + - " \"showLinks\": true,\n" + - " \"showPermissions\": false,\n" + - " \"showHistory\": true,\n" + - " \"showUpdateKey\": true,\n" + - " \"showBackgroundTasks\": true,\n" + - " \"canApplyPermissionTemplate\": false,\n" + - " \"canBrowseProject\": true,\n" + - " \"canUpdateProjectVisibilityToPrivate\": true\n" + - " }\n" + - "}"); + assertJson(json).isSimilarTo(""" + { + "configuration": { + "showSettings": true, + "showQualityProfiles": true, + "showQualityGates": true, + "showLinks": true, + "showPermissions": false, + "showHistory": true, + "showUpdateKey": true, + "showBackgroundTasks": true, + "canApplyPermissionTemplate": false, + "canBrowseProject": true, + "canUpdateProjectVisibilityToPrivate": true + } + }"""); } @Test @@ -818,7 +822,7 @@ public class ComponentActionIT { when(pluginRepository.getPluginInfo(any())).thenReturn(new PluginInfo("unused").setVersion(Version.create("1.0"))); CoreExtensionRepository coreExtensionRepository = mock(CoreExtensionRepository.class); when(coreExtensionRepository.isInstalled(any())).thenReturn(false); - PageRepository pageRepository = new PageRepository(pluginRepository, coreExtensionRepository, new PageDefinition[]{context -> { + PageRepository pageRepository = new PageRepository(pluginRepository, coreExtensionRepository, new PageDefinition[] {context -> { for (Page page : pages) { context.addPage(page); } @@ -866,7 +870,7 @@ public class ComponentActionIT { .setAdmin(true) .build(); - return new Page[]{page1, page2, adminPage}; + return new Page[] {page1, page2, adminPage}; } private void verifySuccess(String componentKey) { diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/QualityGateDetailsFormatterTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/QualityGateDetailsFormatterTest.java index fdf6475f025..95a0659a877 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/QualityGateDetailsFormatterTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/QualityGateDetailsFormatterTest.java @@ -97,20 +97,21 @@ public class QualityGateDetailsFormatterTest { @Test public void fail_when_measure_level_is_unknown() { - String measureData = "{\n" + - " \"level\": \"UNKNOWN\",\n" + - " \"conditions\": [\n" + - " {\n" + - " \"metric\": \"new_coverage\",\n" + - " \"op\": \"LT\",\n" + - " \"period\": 1,\n" + - " \"warning\": \"80\",\n" + - " \"error\": \"85\",\n" + - " \"actual\": \"82.2985024398452\",\n" + - " \"level\": \"ERROR\"\n" + - " }\n" + - " ]\n" + - "}"; + String measureData = """ + { + "level": "UNKNOWN", + "conditions": [ + { + "metric": "new_coverage", + "op": "LT", + "period": 1, + "warning": "80", + "error": "85", + "actual": "82.2985024398452", + "level": "ERROR" + } + ] + }"""; underTest = newQualityGateDetailsFormatter(measureData, new SnapshotDto()); assertThatThrownBy(() -> underTest.format()) @@ -120,20 +121,21 @@ public class QualityGateDetailsFormatterTest { @Test public void fail_when_measure_op_is_unknown() { - String measureData = "{\n" + - " \"level\": \"ERROR\",\n" + - " \"conditions\": [\n" + - " {\n" + - " \"metric\": \"new_coverage\",\n" + - " \"op\": \"UNKNOWN\",\n" + - " \"period\": 1,\n" + - " \"warning\": \"80\",\n" + - " \"error\": \"85\",\n" + - " \"actual\": \"82.2985024398452\",\n" + - " \"level\": \"ERROR\"\n" + - " }\n" + - " ]\n" + - "}"; + String measureData = """ + { + "level": "ERROR", + "conditions": [ + { + "metric": "new_coverage", + "op": "UNKNOWN", + "period": 1, + "warning": "80", + "error": "85", + "actual": "82.2985024398452", + "level": "ERROR" + } + ] + }"""; underTest = newQualityGateDetailsFormatter(measureData, new SnapshotDto()); assertThatThrownBy(() -> underTest.format()) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/builtin/BuiltInQPChangeNotificationTemplateTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/builtin/BuiltInQPChangeNotificationTemplateTest.java index 825714b097c..cbce966e1f4 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/builtin/BuiltInQPChangeNotificationTemplateTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/builtin/BuiltInQPChangeNotificationTemplateTest.java @@ -121,21 +121,21 @@ public class BuiltInQPChangeNotificationTemplateTest { String languageKey = newLanguageKey(); String languageName = newLanguageName(); BuiltInQPChangeNotificationBuilder notification = new BuiltInQPChangeNotificationBuilder() - .addProfile(Profile.newBuilder() - .setProfileName(profileName) - .setLanguageKey(languageKey) - .setLanguageName(languageName) - .setNewRules(1) - .setUpdatedRules(1) - .setRemovedRules(1) - .build()); + .addProfile(Profile.newBuilder() + .setProfileName(profileName) + .setLanguageKey(languageKey) + .setLanguageName(languageName) + .setNewRules(1) + .setUpdatedRules(1) + .setRemovedRules(1) + .build()); EmailMessage emailMessage = underTest.format(notification.build()); assertThat(emailMessage.getMessage()) - .contains("\n 1 new rule\n") - .contains("\n 1 rule has been updated\n") - .contains("\n 1 rule removed\n"); + .contains("\n 1 new rule\n") + .contains("\n 1 rule has been updated\n") + .contains("\n 1 rule removed\n"); } @Test @@ -155,11 +155,12 @@ public class BuiltInQPChangeNotificationTemplateTest { EmailMessage emailMessage = underTest.format(notification.build()); - assertMessage(emailMessage, - "\n" + - " 2 new rules\n" + - " 3 rules have been updated\n" + - " 4 rules removed\n"); + assertMessage(emailMessage, """ + + 2 new rules + 3 rules have been updated + 4 rules removed + """); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/HtmlTextDecoratorTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/HtmlTextDecoratorTest.java index 1f8372d7f17..8f9ef7beb96 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/HtmlTextDecoratorTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/HtmlTextDecoratorTest.java @@ -63,8 +63,7 @@ public class HtmlTextDecoratorTest { "<span class=\"cppd\">" + firstCommentLine + "</span>", "<span class=\"cppd\">" + secondCommentLine + "</span>", "<span class=\"cppd\">" + thirdCommentLine + "</span>", - "" - ); + ""); } @Test @@ -87,14 +86,13 @@ public class HtmlTextDecoratorTest { @Test public void should_allow_multiple_levels_highlighting() { - String javaDocSample = - "/**" + LF_END_OF_LINE + - " * Creates a FormulaDecorator" + LF_END_OF_LINE + - " *" + LF_END_OF_LINE + - " * @param metric the metric should have an associated formula" + LF_END_OF_LINE + - " * " + LF_END_OF_LINE + - " * @throws IllegalArgumentException if no formula is associated to the metric" + LF_END_OF_LINE + - " */" + LF_END_OF_LINE; + String javaDocSample = "/**" + LF_END_OF_LINE + + " * Creates a FormulaDecorator" + LF_END_OF_LINE + + " *" + LF_END_OF_LINE + + " * @param metric the metric should have an associated formula" + LF_END_OF_LINE + + " * " + LF_END_OF_LINE + + " * @throws IllegalArgumentException if no formula is associated to the metric" + LF_END_OF_LINE + + " */" + LF_END_OF_LINE; DecorationDataHolder decorationData = new DecorationDataHolder(); decorationData.loadSyntaxHighlightingData("0,184,cppd;47,53,k;"); @@ -110,21 +108,19 @@ public class HtmlTextDecoratorTest { "<span class=\"cppd\"> * </span>", "<span class=\"cppd\"> * @throws IllegalArgumentException if no formula is associated to the metric</span>", "<span class=\"cppd\"> */</span>", - "" - ); + ""); } @Test public void should_support_crlf_line_breaks() { - String crlfCodeSample = - "/**" + CR_END_OF_LINE + LF_END_OF_LINE + - "* @return metric generated by the decorator" + CR_END_OF_LINE + LF_END_OF_LINE + - "*/" + CR_END_OF_LINE + LF_END_OF_LINE + - "@DependedUpon" + CR_END_OF_LINE + LF_END_OF_LINE + - "public Metric generatesMetric() {" + CR_END_OF_LINE + LF_END_OF_LINE + - " return metric;" + CR_END_OF_LINE + LF_END_OF_LINE + - "}" + CR_END_OF_LINE + LF_END_OF_LINE; + String crlfCodeSample = "/**" + CR_END_OF_LINE + LF_END_OF_LINE + + "* @return metric generated by the decorator" + CR_END_OF_LINE + LF_END_OF_LINE + + "*/" + CR_END_OF_LINE + LF_END_OF_LINE + + "@DependedUpon" + CR_END_OF_LINE + LF_END_OF_LINE + + "public Metric generatesMetric() {" + CR_END_OF_LINE + LF_END_OF_LINE + + " return metric;" + CR_END_OF_LINE + LF_END_OF_LINE + + "}" + CR_END_OF_LINE + LF_END_OF_LINE; DecorationDataHolder decorationData = new DecorationDataHolder(); decorationData.loadSyntaxHighlightingData("0,52,cppd;54,67,a;69,75,k;106,112,k;"); @@ -140,20 +136,18 @@ public class HtmlTextDecoratorTest { "<span class=\"k\">public</span> Metric generatesMetric() {", " <span class=\"k\">return</span> metric;", "}", - "" - ); + ""); } @Test public void should_close_tags_at_end_of_file() { - String classDeclarationSample = - "/*" + LF_END_OF_LINE + - " * Header" + LF_END_OF_LINE + - " */" + LF_END_OF_LINE + - LF_END_OF_LINE + - "public class HelloWorld {" + LF_END_OF_LINE + - "}"; + String classDeclarationSample = "/*" + LF_END_OF_LINE + + " * Header" + LF_END_OF_LINE + + " */" + LF_END_OF_LINE + + LF_END_OF_LINE + + "public class HelloWorld {" + LF_END_OF_LINE + + "}"; DecorationDataHolder decorationData = new DecorationDataHolder(); decorationData.loadSyntaxHighlightingData("0,16,cppd;18,25,k;25,31,k;"); @@ -167,25 +161,25 @@ public class HtmlTextDecoratorTest { "<span class=\"cppd\"> */</span>", "", "<span class=\"k\">public </span><span class=\"k\">class </span>HelloWorld {", - "}" - ); + "}"); } @Test public void should_escape_markup_chars() { - String javadocWithHtml = - "/**\n" + - " * Provides a basic framework to sequentially read any kind of character stream in order to feed a generic OUTPUT.\n" + - " * \n" + - " * This framework can used for instance in order to :\n" + - " * <ul>\n" + - " * <li>Create a lexer in charge to generate a list of tokens from a character stream</li>\n" + - " * <li>Create a source code syntax highligther in charge to decorate a source code with HTML tags</li>\n" + - " * <li>Create a javadoc generator</li>\n" + - " * <li>...</li>\n" + - " * </ul>\n" + - " */\n"; + String javadocWithHtml = """ + /** + * Provides a basic framework to sequentially read any kind of character stream in order to feed a generic OUTPUT. + *\s + * This framework can used for instance in order to : + * <ul> + * <li>Create a lexer in charge to generate a list of tokens from a character stream</li> + * <li>Create a source code syntax highligther in charge to decorate a source code with HTML tags</li> + * <li>Create a javadoc generator</li> + * <li>...</li> + * </ul> + */ + """; DecorationDataHolder decorationData = new DecorationDataHolder(); decorationData.loadSyntaxHighlightingData("0,453,cppd;"); @@ -211,15 +205,16 @@ public class HtmlTextDecoratorTest { @Test public void should_escape_ampersand_char() { - String javadocWithAmpersandChar = - "/**\n" + - " * Definition of a dashboard.\n" + - " * <p/>\n" + - " * Its name and description can be retrieved using the i18n mechanism, using the keys \"dashboard.<id>.name\" and\n" + - " * \"dashboard.<id>.description\".\n" + - " *\n" + - " * @since 2.13\n" + - " */\n"; + String javadocWithAmpersandChar = """ + /** + * Definition of a dashboard. + * <p/> + * Its name and description can be retrieved using the i18n mechanism, using the keys "dashboard.<id>.name" and + * "dashboard.<id>.description". + * + * @since 2.13 + */ + """; DecorationDataHolder decorationData = new DecorationDataHolder(); decorationData.loadSyntaxHighlightingData("0,220,cppd;"); @@ -242,14 +237,13 @@ public class HtmlTextDecoratorTest { @Test public void should_support_cr_line_breaks() { - String crCodeSample = - "/**" + CR_END_OF_LINE + - "* @return metric generated by the decorator" + CR_END_OF_LINE + - "*/" + CR_END_OF_LINE + - "@DependedUpon" + CR_END_OF_LINE + - "public Metric generatesMetric() {" + CR_END_OF_LINE + - " return metric;" + CR_END_OF_LINE + - "}" + CR_END_OF_LINE; + String crCodeSample = "/**" + CR_END_OF_LINE + + "* @return metric generated by the decorator" + CR_END_OF_LINE + + "*/" + CR_END_OF_LINE + + "@DependedUpon" + CR_END_OF_LINE + + "public Metric generatesMetric() {" + CR_END_OF_LINE + + " return metric;" + CR_END_OF_LINE + + "}" + CR_END_OF_LINE; DecorationDataHolder decorationData = new DecorationDataHolder(); decorationData.loadSyntaxHighlightingData("0,50,cppd;51,64,a;65,71,k;101,107,k;"); @@ -265,21 +259,19 @@ public class HtmlTextDecoratorTest { "<span class=\"k\">public</span> Metric generatesMetric() {", " <span class=\"k\">return</span> metric;", "}", - "" - ); + ""); } @Test public void should_support_multiple_empty_lines_at_end_of_file() { - String classDeclarationSample = - "/*" + LF_END_OF_LINE + - " * Header" + LF_END_OF_LINE + - " */" + LF_END_OF_LINE + - LF_END_OF_LINE + - "public class HelloWorld {" + LF_END_OF_LINE + - "}" + LF_END_OF_LINE + LF_END_OF_LINE + LF_END_OF_LINE; + String classDeclarationSample = "/*" + LF_END_OF_LINE + + " * Header" + LF_END_OF_LINE + + " */" + LF_END_OF_LINE + + LF_END_OF_LINE + + "public class HelloWorld {" + LF_END_OF_LINE + + "}" + LF_END_OF_LINE + LF_END_OF_LINE + LF_END_OF_LINE; DecorationDataHolder decorationData = new DecorationDataHolder(); decorationData.loadSyntaxHighlightingData("0,16,cppd;18,25,k;25,31,k;"); @@ -296,25 +288,25 @@ public class HtmlTextDecoratorTest { "}", "", "", - "" - ); + ""); } @Test public void returned_code_begin_from_given_param() { - String javadocWithHtml = - "/**\n" + - " * Provides a basic framework to sequentially read any kind of character stream in order to feed a generic OUTPUT.\n" + - " * \n" + - " * This framework can used for instance in order to :\n" + - " * <ul>\n" + - " * <li>Create a lexer in charge to generate a list of tokens from a character stream</li>\n" + - " * <li>Create a source code syntax highligther in charge to decorate a source code with HTML tags</li>\n" + - " * <li>Create a javadoc generator</li>\n" + - " * <li>...</li>\n" + - " * </ul>\n" + - " */\n"; + String javadocWithHtml = """ + /** + * Provides a basic framework to sequentially read any kind of character stream in order to feed a generic OUTPUT. + *\s + * This framework can used for instance in order to : + * <ul> + * <li>Create a lexer in charge to generate a list of tokens from a character stream</li> + * <li>Create a source code syntax highligther in charge to decorate a source code with HTML tags</li> + * <li>Create a javadoc generator</li> + * <li>...</li> + * </ul> + */ + """; DecorationDataHolder decorationData = new DecorationDataHolder(); decorationData.loadSyntaxHighlightingData("0,453,cppd;"); @@ -339,18 +331,19 @@ public class HtmlTextDecoratorTest { @Test public void returned_code_end_to_given_param() { - String javadocWithHtml = - "/**\n" + - " * Provides a basic framework to sequentially read any kind of character stream in order to feed a generic OUTPUT.\n" + - " * \n" + - " * This framework can used for instance in order to :\n" + - " * <ul>\n" + - " * <li>Create a lexer in charge to generate a list of tokens from a character stream</li>\n" + - " * <li>Create a source code syntax highligther in charge to decorate a source code with HTML tags</li>\n" + - " * <li>Create a javadoc generator</li>\n" + - " * <li>...</li>\n" + - " * </ul>\n" + - " */\n"; + String javadocWithHtml = """ + /** + * Provides a basic framework to sequentially read any kind of character stream in order to feed a generic OUTPUT. + *\s + * This framework can used for instance in order to : + * <ul> + * <li>Create a lexer in charge to generate a list of tokens from a character stream</li> + * <li>Create a source code syntax highligther in charge to decorate a source code with HTML tags</li> + * <li>Create a javadoc generator</li> + * <li>...</li> + * </ul> + */ + """; DecorationDataHolder decorationData = new DecorationDataHolder(); decorationData.loadSyntaxHighlightingData("0,453,cppd;"); @@ -370,18 +363,19 @@ public class HtmlTextDecoratorTest { @Test public void returned_code_is_between_from_and_to_params() { - String javadocWithHtml = - "/**\n" + - " * Provides a basic framework to sequentially read any kind of character stream in order to feed a generic OUTPUT.\n" + - " * \n" + - " * This framework can used for instance in order to :\n" + - " * <ul>\n" + - " * <li>Create a lexer in charge to generate a list of tokens from a character stream</li>\n" + - " * <li>Create a source code syntax highligther in charge to decorate a source code with HTML tags</li>\n" + - " * <li>Create a javadoc generator</li>\n" + - " * <li>...</li>\n" + - " * </ul>\n" + - " */\n"; + String javadocWithHtml = """ + /** + * Provides a basic framework to sequentially read any kind of character stream in order to feed a generic OUTPUT. + *\s + * This framework can used for instance in order to : + * <ul> + * <li>Create a lexer in charge to generate a list of tokens from a character stream</li> + * <li>Create a source code syntax highligther in charge to decorate a source code with HTML tags</li> + * <li>Create a javadoc generator</li> + * <li>...</li> + * </ul> + */ + """; DecorationDataHolder decorationData = new DecorationDataHolder(); decorationData.loadSyntaxHighlightingData("0,453,cppd;"); @@ -396,7 +390,6 @@ public class HtmlTextDecoratorTest { "<span class=\"cppd\"> * <ul></span>", "<span class=\"cppd\"> * <li>Create a lexer in charge to generate a list of tokens from a character stream</li></span>", "<span class=\"cppd\"> * <li>Create a source code syntax highligther in charge to decorate a source code with HTML tags</li></span>", - "<span class=\"cppd\"> * <li>Create a javadoc generator</li></span>" - ); + "<span class=\"cppd\"> * <li>Create a javadoc generator</li></span>"); } } |