diff options
author | Matteo Mara <matteo.mara@sonarsource.com> | 2024-10-08 10:31:31 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2024-10-14 20:03:04 +0000 |
commit | 1e315cf59823550446594a03ca13a6b175341d80 (patch) | |
tree | 50f00f41249ae09f11f574c5a4e60ecc3f455586 /server/sonar-server-common | |
parent | 1ad3667d30dd82213ae47bea2c267188f003b2c7 (diff) | |
download | sonarqube-1e315cf59823550446594a03ca13a6b175341d80.tar.gz sonarqube-1e315cf59823550446594a03ca13a6b175341d80.zip |
NO-JIRA Remove new code issues resulting from the update of the deprecated methods.
Diffstat (limited to 'server/sonar-server-common')
6 files changed, 37 insertions, 32 deletions
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/es/newindex/FieldAwareTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/es/newindex/FieldAwareTest.java index 59eef06c822..d1bc06593c4 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/es/newindex/FieldAwareTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/es/newindex/FieldAwareTest.java @@ -19,12 +19,10 @@ */ package org.sonar.server.es.newindex; -import java.util.Random; import java.util.function.BiConsumer; import java.util.stream.Stream; import org.junit.Test; -import static org.apache.commons.lang3.RandomStringUtils.secure; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Fail.fail; @@ -47,7 +45,7 @@ public class FieldAwareTest { fieldSetters.forEach(c -> { TestFieldAware underTest = new TestFieldAware(); // should not fail for other field name - c.accept(underTest, secure().nextAlphabetic(1 + new Random().nextInt(10))); + c.accept(underTest, "notIndexType"); // fails whatever the case Stream.of("indexType", "indextype", "InDexType", "INDEXTYPE") .forEach(illegalFieldName -> { diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/es/newindex/NewIndexTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/es/newindex/NewIndexTest.java index 8e33bbc620e..e8a2ee572b0 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/es/newindex/NewIndexTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/es/newindex/NewIndexTest.java @@ -45,9 +45,9 @@ import static org.sonar.server.es.newindex.SettingsConfiguration.newBuilder; public class NewIndexTest { - private static final String someIndexName = secure().nextAlphabetic(5).toLowerCase(); - private MapSettings settings = new MapSettings(); - private SettingsConfiguration defaultSettingsConfiguration = newBuilder(settings.asConfig()).build(); + private static final String SOME_INDEX_NAME = secure().nextAlphabetic(5).toLowerCase(); + private final MapSettings settings = new MapSettings(); + private final SettingsConfiguration defaultSettingsConfiguration = newBuilder(settings.asConfig()).build(); @Test @UseDataProvider("indexWithAndWithoutRelations") @@ -353,9 +353,9 @@ public class NewIndexTest { @Test public void createTypeMapping_with_IndexRelationType_fails_with_ISE_if_index_does_not_allow_relations() { - IndexType.IndexRelationType indexRelationType = IndexType.relation(IndexType.main(Index.withRelations(someIndexName), "bar"), "bar"); + IndexType.IndexRelationType indexRelationType = IndexType.relation(IndexType.main(Index.withRelations(SOME_INDEX_NAME), "bar"), "bar"); - Index index = Index.simple(someIndexName); + Index index = Index.simple(SOME_INDEX_NAME); IndexMainType mainType = IndexType.main(index, "foo"); NewIndex underTest = new NewIndex(index, defaultSettingsConfiguration) { @Override @@ -377,8 +377,8 @@ public class NewIndexTest { @DataProvider public static Object[][] indexWithAndWithoutRelations() { return new Object[][] { - {Index.simple(someIndexName)}, - {Index.withRelations(someIndexName)} + {Index.simple(SOME_INDEX_NAME)}, + {Index.withRelations(SOME_INDEX_NAME)} }; } diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/es/searchrequest/AllFiltersTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/es/searchrequest/AllFiltersTest.java index b6ec64e6e4f..d3ea1974056 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/es/searchrequest/AllFiltersTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/es/searchrequest/AllFiltersTest.java @@ -70,21 +70,20 @@ public class AllFiltersTest { @Test public void addFilter_fails_if_field_with_name_already_exists() { - String name1 = secure().nextAlphabetic(12); - String name2 = secure().nextAlphabetic(15); + String name = secure().nextAlphabetic(15); FilterScope filterScope1 = mock(FilterScope.class); FilterScope filterScope2 = mock(FilterScope.class); RequestFiltersComputer.AllFilters allFilters = RequestFiltersComputer.newAllFilters(); - allFilters.addFilter(name2, filterScope1, boolQuery()); + allFilters.addFilter(name, filterScope1, boolQuery()); Stream.<ThrowingCallable>of( // exact same call - () -> allFilters.addFilter(name2, filterScope1, boolQuery()), + () -> allFilters.addFilter(name, filterScope1, boolQuery()), // call with a different fieldName - () -> allFilters.addFilter(name2, filterScope2, boolQuery())) + () -> allFilters.addFilter(name, filterScope2, boolQuery())) .forEach(t -> assertThatThrownBy(t) .isInstanceOf(IllegalArgumentException.class) - .hasMessage("A filter with name " + name2 + " has already been added")); + .hasMessage("A filter with name " + name + " has already been added")); } @Test diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/ChangesOnMyIssuesNotificationTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/ChangesOnMyIssuesNotificationTest.java index ff9847b368a..42c29365318 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/ChangesOnMyIssuesNotificationTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/ChangesOnMyIssuesNotificationTest.java @@ -20,7 +20,6 @@ package org.sonar.server.issue.notification; import com.google.common.collect.ImmutableSet; -import java.util.Random; import org.junit.Test; import org.sonar.api.notifications.Notification; import org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.AnalysisChange; @@ -37,7 +36,7 @@ public class ChangesOnMyIssuesNotificationTest { @Test public void key_is_ChangesOnMyIssues() { ChangesOnMyIssuesNotification underTest = new ChangesOnMyIssuesNotification( - new UserChange(new Random().nextLong(), new User(secure().nextAlphabetic(2), secure().nextAlphabetic(3), secure().nextAlphabetic(4))), + new UserChange(1L, new User(secure().nextAlphabetic(2), secure().nextAlphabetic(3), secure().nextAlphabetic(4))), ImmutableSet.of()); assertThat(underTest.getType()).isEqualTo("ChangesOnMyIssues"); @@ -45,7 +44,7 @@ public class ChangesOnMyIssuesNotificationTest { @Test public void equals_is_based_on_change_and_issues() { - AnalysisChange analysisChange = new AnalysisChange(new Random().nextLong()); + AnalysisChange analysisChange = new AnalysisChange(1L); ChangedIssue changedIssue = IssuesChangesNotificationBuilderTesting.newChangedIssue("doo", IssuesChangesNotificationBuilderTesting.newProject("prj"), newRandomNotAHotspotRule("rul")); ChangesOnMyIssuesNotification underTest = new ChangesOnMyIssuesNotification(analysisChange, ImmutableSet.of(changedIssue)); @@ -60,7 +59,7 @@ public class ChangesOnMyIssuesNotificationTest { @Test public void hashcode_is_based_on_change_and_issues() { - AnalysisChange analysisChange = new AnalysisChange(new Random().nextLong()); + AnalysisChange analysisChange = new AnalysisChange(1L); ChangedIssue changedIssue = IssuesChangesNotificationBuilderTesting.newChangedIssue("doo", IssuesChangesNotificationBuilderTesting.newProject("prj"), newRandomNotAHotspotRule("rul")); ChangesOnMyIssuesNotification underTest = new ChangesOnMyIssuesNotification(analysisChange, ImmutableSet.of(changedIssue)); diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/FpPrAcceptedEmailTemplateTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/FpPrAcceptedEmailTemplateTest.java index 7a0d96b10ca..967e5955cd8 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/FpPrAcceptedEmailTemplateTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/FpPrAcceptedEmailTemplateTest.java @@ -23,6 +23,7 @@ import com.google.common.collect.ImmutableSet; import com.tngtech.java.junit.dataprovider.DataProvider; import com.tngtech.java.junit.dataprovider.DataProviderRunner; import com.tngtech.java.junit.dataprovider.UseDataProvider; +import java.time.Instant; import java.util.Collections; import java.util.List; import java.util.Locale; @@ -61,10 +62,12 @@ import static org.sonar.server.issue.notification.IssuesChangesNotificationBuild @RunWith(DataProviderRunner.class) public class FpPrAcceptedEmailTemplateTest { - private I18n i18n = mock(I18n.class); - private EmailSettings emailSettings = mock(EmailSettings.class); - private FpOrAcceptedEmailTemplate underTest = new FpOrAcceptedEmailTemplate(i18n, emailSettings); + private final I18n i18n = mock(I18n.class); + private final EmailSettings emailSettings = mock(EmailSettings.class); + private final FpOrAcceptedEmailTemplate underTest = new FpOrAcceptedEmailTemplate(i18n, emailSettings); + private static final long DATE_LONG = Instant.now().toEpochMilli(); + @Test public void format_returns_null_on_Notification() { EmailMessage emailMessage = underTest.format(mock(Notification.class)); @@ -102,7 +105,7 @@ public class FpPrAcceptedEmailTemplateTest { @Test public void format_sets_from_to_name_of_author_change_when_available() { - UserChange change = new UserChange(new Random().nextLong(), new User(secure().nextAlphabetic(5), secure().nextAlphabetic(6), secure().nextAlphabetic(7))); + UserChange change = new UserChange(DATE_LONG, new User(secure().nextAlphabetic(5), secure().nextAlphabetic(6), secure().nextAlphabetic(7))); EmailMessage emailMessage = underTest.format(new FPOrAcceptedNotification(change, Collections.emptySet(), ACCEPTED)); assertThat(emailMessage.getFrom()).isEqualTo(change.getUser().getName().get()); @@ -110,7 +113,7 @@ public class FpPrAcceptedEmailTemplateTest { @Test public void format_sets_from_to_login_of_author_change_when_name_is_not_available() { - UserChange change = new UserChange(new Random().nextLong(), new User(secure().nextAlphabetic(5), secure().nextAlphabetic(6), null)); + UserChange change = new UserChange(DATE_LONG, new User(secure().nextAlphabetic(5), secure().nextAlphabetic(6), null)); EmailMessage emailMessage = underTest.format(new FPOrAcceptedNotification(change, Collections.emptySet(), ACCEPTED)); assertThat(emailMessage.getFrom()).isEqualTo(change.getUser().getLogin()); @@ -118,7 +121,7 @@ public class FpPrAcceptedEmailTemplateTest { @Test public void format_sets_from_to_null_when_analysisChange() { - AnalysisChange change = new AnalysisChange(new Random().nextLong()); + AnalysisChange change = new AnalysisChange(DATE_LONG); EmailMessage emailMessage = underTest.format(new FPOrAcceptedNotification(change, Collections.emptySet(), ACCEPTED)); assertThat(emailMessage.getFrom()).isNull(); @@ -472,8 +475,8 @@ public class FpPrAcceptedEmailTemplateTest { @DataProvider public static Object[][] userOrAnalysisChange() { - AnalysisChange analysisChange = new AnalysisChange(new Random().nextLong()); - UserChange userChange = new UserChange(new Random().nextLong(), new User(secure().nextAlphabetic(5), secure().nextAlphabetic(6), + AnalysisChange analysisChange = new AnalysisChange(DATE_LONG); + UserChange userChange = new UserChange(DATE_LONG, new User(secure().nextAlphabetic(5), secure().nextAlphabetic(6), new Random().nextBoolean() ? null : secure().nextAlphabetic(7))); return new Object[][] { {analysisChange}, @@ -483,8 +486,8 @@ public class FpPrAcceptedEmailTemplateTest { @DataProvider public static Object[][] fpOrWontFixValuesByUserOrAnalysisChange() { - AnalysisChange analysisChange = new AnalysisChange(new Random().nextLong()); - UserChange userChange = new UserChange(new Random().nextLong(), new User(secure().nextAlphabetic(5), secure().nextAlphabetic(6), + AnalysisChange analysisChange = new AnalysisChange(DATE_LONG); + UserChange userChange = new UserChange(DATE_LONG, new User(secure().nextAlphabetic(5), secure().nextAlphabetic(6), new Random().nextBoolean() ? null : secure().nextAlphabetic(7))); return new Object[][] { {analysisChange, FP}, diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/permission/index/AuthorizationDocTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/permission/index/AuthorizationDocTest.java index 23e47a79507..2614352fdd5 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/permission/index/AuthorizationDocTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/permission/index/AuthorizationDocTest.java @@ -62,13 +62,19 @@ public class AuthorizationDocTest { public void projectUuidOf_returns_substring_if_starts_with_id_prefix() { assertThat(AuthorizationDoc.entityUuidOf("auth_")).isEmpty(); - String id = secure().nextAlphabetic(1 + new Random().nextInt(10)); + String id = "u"; + assertThat(AuthorizationDoc.entityUuidOf("auth_" + id)).isEqualTo(id); + + id = "uuid"; + assertThat(AuthorizationDoc.entityUuidOf("auth_" + id)).isEqualTo(id); + + id = "aMuchLongerUuid"; assertThat(AuthorizationDoc.entityUuidOf("auth_" + id)).isEqualTo(id); } @Test public void projectUuidOf_returns_argument_if_does_not_starts_with_id_prefix() { - String id = secure().nextAlphabetic(1 + new Random().nextInt(10)); + String id = "uuid"; assertThat(AuthorizationDoc.entityUuidOf(id)).isEqualTo(id); assertThat(AuthorizationDoc.entityUuidOf("")).isEmpty(); } |