diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2021-11-18 16:45:02 -0600 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2021-11-20 20:03:51 +0000 |
commit | 3f9445c25962f914ccdd889c002ddd8e19b0cf89 (patch) | |
tree | eb4f34a62b7164a71fd0bbe34d6f59621a687d8d /server | |
parent | aa640be9e2b9cfa2c027ef0768940b31ebb5536c (diff) | |
download | sonarqube-3f9445c25962f914ccdd889c002ddd8e19b0cf89.tar.gz sonarqube-3f9445c25962f914ccdd889c002ddd8e19b0cf89.zip |
Improve code quality
Diffstat (limited to 'server')
336 files changed, 1145 insertions, 1236 deletions
diff --git a/server/sonar-alm-client/src/test/java/org/sonar/alm/client/bitbucket/bitbucketcloud/BitbucketCloudRestClientTest.java b/server/sonar-alm-client/src/test/java/org/sonar/alm/client/bitbucket/bitbucketcloud/BitbucketCloudRestClientTest.java index 6268a0da493..1f581e608b6 100644 --- a/server/sonar-alm-client/src/test/java/org/sonar/alm/client/bitbucket/bitbucketcloud/BitbucketCloudRestClientTest.java +++ b/server/sonar-alm-client/src/test/java/org/sonar/alm/client/bitbucket/bitbucketcloud/BitbucketCloudRestClientTest.java @@ -145,7 +145,7 @@ public class BitbucketCloudRestClientTest { RepositoryList repositoryList = underTest.searchRepos("user:apppwd", "", null, 1, 100); assertThat(repositoryList.getNext()).isNull(); - assertThat(repositoryList.getPage()).isEqualTo(1); + assertThat(repositoryList.getPage()).isOne(); assertThat(repositoryList.getPagelen()).isEqualTo(100); assertThat(repositoryList.getValues()) .hasSize(1) diff --git a/server/sonar-alm-client/src/test/java/org/sonar/alm/client/bitbucketserver/BitbucketServerRestClientTest.java b/server/sonar-alm-client/src/test/java/org/sonar/alm/client/bitbucketserver/BitbucketServerRestClientTest.java index 45b49116f3e..92368e4528c 100644 --- a/server/sonar-alm-client/src/test/java/org/sonar/alm/client/bitbucketserver/BitbucketServerRestClientTest.java +++ b/server/sonar-alm-client/src/test/java/org/sonar/alm/client/bitbucketserver/BitbucketServerRestClientTest.java @@ -514,9 +514,7 @@ public class BitbucketServerRestClientTest { .setBody("this is not a json payload")); String serverUrl = server.url("/").toString(); - assertThatThrownBy(() -> { - underTest.validateUrl(serverUrl); - }) + assertThatThrownBy(() -> underTest.validateUrl(serverUrl)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Unable to contact Bitbucket server, got an unexpected response"); } diff --git a/server/sonar-alm-client/src/test/java/org/sonar/alm/client/gitlab/GitlabHttpClientTest.java b/server/sonar-alm-client/src/test/java/org/sonar/alm/client/gitlab/GitlabHttpClientTest.java index 0c07902d70a..f306fbdf19b 100644 --- a/server/sonar-alm-client/src/test/java/org/sonar/alm/client/gitlab/GitlabHttpClientTest.java +++ b/server/sonar-alm-client/src/test/java/org/sonar/alm/client/gitlab/GitlabHttpClientTest.java @@ -223,7 +223,7 @@ public class GitlabHttpClientTest { ProjectList projectList = underTest.searchProjects(gitlabUrl, "pat", "example", 1, 10); - assertThat(projectList.getPageNumber()).isEqualTo(1); + assertThat(projectList.getPageNumber()).isOne(); assertThat(projectList.getPageSize()).isEqualTo(10); assertThat(projectList.getTotal()).isEqualTo(3); @@ -263,7 +263,7 @@ public class GitlabHttpClientTest { ProjectList projectList = underTest.searchProjects(gitlabUrl, "pat", "example", 1, 10); - assertThat(projectList.getPageNumber()).isEqualTo(1); + assertThat(projectList.getPageNumber()).isOne(); assertThat(projectList.getPageSize()).isEqualTo(10); assertThat(projectList.getTotal()).isNull(); @@ -300,8 +300,8 @@ public class GitlabHttpClientTest { ProjectList projectList = underTest.searchProjects(gitlabUrl, "pat", "example", 1, 10); - assertThat(projectList.getPageNumber()).isEqualTo(1); - assertThat(projectList.getPageSize()).isEqualTo(1); + assertThat(projectList.getPageNumber()).isOne(); + assertThat(projectList.getPageSize()).isOne(); assertThat(projectList.getTotal()).isEqualTo(2); assertThat(projectList.getProjects()).hasSize(1); diff --git a/server/sonar-auth-bitbucket/src/main/java/org/sonar/auth/bitbucket/BitbucketSettings.java b/server/sonar-auth-bitbucket/src/main/java/org/sonar/auth/bitbucket/BitbucketSettings.java index f017f6a311b..0ef3c994b5a 100755 --- a/server/sonar-auth-bitbucket/src/main/java/org/sonar/auth/bitbucket/BitbucketSettings.java +++ b/server/sonar-auth-bitbucket/src/main/java/org/sonar/auth/bitbucket/BitbucketSettings.java @@ -29,8 +29,6 @@ import org.sonar.api.config.Configuration; import org.sonar.api.config.PropertyDefinition; import org.sonar.api.server.ServerSide; -import static java.lang.String.format; - @ServerSide public class BitbucketSettings { diff --git a/server/sonar-auth-bitbucket/src/main/java/org/sonar/auth/bitbucket/UserIdentityFactory.java b/server/sonar-auth-bitbucket/src/main/java/org/sonar/auth/bitbucket/UserIdentityFactory.java index 96e1e34dd5e..c4165250203 100755 --- a/server/sonar-auth-bitbucket/src/main/java/org/sonar/auth/bitbucket/UserIdentityFactory.java +++ b/server/sonar-auth-bitbucket/src/main/java/org/sonar/auth/bitbucket/UserIdentityFactory.java @@ -23,8 +23,6 @@ import javax.annotation.Nullable; import org.sonar.api.server.ServerSide; import org.sonar.api.server.authentication.UserIdentity; -import static java.lang.String.format; - @ServerSide public class UserIdentityFactory { diff --git a/server/sonar-auth-gitlab/src/test/java/org/sonar/auth/gitlab/GsonGroupTest.java b/server/sonar-auth-gitlab/src/test/java/org/sonar/auth/gitlab/GsonGroupTest.java index 110b86a071e..64798ac96e4 100644 --- a/server/sonar-auth-gitlab/src/test/java/org/sonar/auth/gitlab/GsonGroupTest.java +++ b/server/sonar-auth-gitlab/src/test/java/org/sonar/auth/gitlab/GsonGroupTest.java @@ -46,7 +46,7 @@ public class GsonGroupTest { "}]"); assertThat(groups).isNotNull(); - assertThat(groups.size()).isEqualTo(1); + assertThat(groups.size()).isOne(); assertThat(groups.get(0).getFullPath()).isEqualTo("my-awesome-group/my-project"); } } diff --git a/server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/LdapSearchTest.java b/server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/LdapSearchTest.java index 367f0759a8b..367859b3c3a 100644 --- a/server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/LdapSearchTest.java +++ b/server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/LdapSearchTest.java @@ -59,9 +59,10 @@ public class LdapSearchTest { assertThat(search.toString()).isEqualTo("LdapSearch{baseDn=dc=example,dc=org, scope=subtree, request=(objectClass={0}), parameters=[inetOrgPerson], attributes=[objectClass]}"); assertThat(enumerationToArrayList(search.find()).size()).isEqualTo(3); - assertThatThrownBy(() -> search.findUnique()) + assertThatThrownBy(search::findUnique) .isInstanceOf(NamingException.class) .hasMessage("Non unique result for " + search.toString()); + } @Test @@ -78,7 +79,7 @@ public class LdapSearchTest { assertThat(search.getRequest()).isEqualTo("(objectClass={0})"); assertThat(search.getParameters()).isEqualTo(new String[] {"inetOrgPerson"}); assertThat(search.getReturningAttributes()).isEqualTo(new String[] {"cn"}); - assertThat(search.toString()).isEqualTo("LdapSearch{baseDn=dc=example,dc=org, scope=onelevel, request=(objectClass={0}), parameters=[inetOrgPerson], attributes=[cn]}"); + assertThat(search).hasToString("LdapSearch{baseDn=dc=example,dc=org, scope=onelevel, request=(objectClass={0}), parameters=[inetOrgPerson], attributes=[cn]}"); assertThat(enumerationToArrayList(search.find()).size()).isZero(); assertThat(search.findUnique()).isNull(); } @@ -97,9 +98,9 @@ public class LdapSearchTest { assertThat(search.getRequest()).isEqualTo("(objectClass={0})"); assertThat(search.getParameters()).isEqualTo(new String[] {"uidObject"}); assertThat(search.getReturningAttributes()).isEqualTo(new String[] {"uid"}); - assertThat(search.toString()).isEqualTo( + assertThat(search).hasToString( "LdapSearch{baseDn=cn=bind,ou=users,dc=example,dc=org, scope=object, request=(objectClass={0}), parameters=[uidObject], attributes=[uid]}"); - assertThat(enumerationToArrayList(search.find()).size()).isEqualTo(1); + assertThat(enumerationToArrayList(search.find())).hasSize(1); assertThat(search.findUnique()).isNotNull(); } diff --git a/server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/LdapSettingsManagerTest.java b/server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/LdapSettingsManagerTest.java index 446b09b3462..8dfb35e893a 100644 --- a/server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/LdapSettingsManagerTest.java +++ b/server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/LdapSettingsManagerTest.java @@ -57,7 +57,7 @@ public class LdapSettingsManagerTest { public void testContextFactoriesWithSingleLdap() { LdapSettingsManager settingsManager = new LdapSettingsManager( generateSingleLdapSettingsWithUserAndGroupMapping().asConfig(), new LdapAutodiscovery()); - assertThat(settingsManager.getContextFactories().size()).isEqualTo(1); + assertThat(settingsManager.getContextFactories()).hasSize(1); } /** @@ -68,9 +68,9 @@ public class LdapSettingsManagerTest { public void testContextFactoriesWithMultipleLdap() { LdapSettingsManager settingsManager = new LdapSettingsManager( generateMultipleLdapSettingsWithUserAndGroupMapping().asConfig(), new LdapAutodiscovery()); - assertThat(settingsManager.getContextFactories().size()).isEqualTo(2); + assertThat(settingsManager.getContextFactories()).hasSize(2); // We do it twice to make sure the settings keep the same. - assertThat(settingsManager.getContextFactories().size()).isEqualTo(2); + assertThat(settingsManager.getContextFactories()).hasSize(2); } @Test @@ -81,7 +81,7 @@ public class LdapSettingsManagerTest { when(ldapAutodiscovery.getLdapServers("example.org")).thenReturn(Arrays.asList(ldap1, ldap2)); LdapSettingsManager settingsManager = new LdapSettingsManager( generateAutodiscoverSettings().asConfig(), ldapAutodiscovery); - assertThat(settingsManager.getContextFactories().size()).isEqualTo(2); + assertThat(settingsManager.getContextFactories()).hasSize(2); } @Test @@ -104,9 +104,9 @@ public class LdapSettingsManagerTest { public void testUserMappings() { LdapSettingsManager settingsManager = new LdapSettingsManager( generateMultipleLdapSettingsWithUserAndGroupMapping().asConfig(), new LdapAutodiscovery()); - assertThat(settingsManager.getUserMappings().size()).isEqualTo(2); + assertThat(settingsManager.getUserMappings()).hasSize(2); // We do it twice to make sure the settings keep the same. - assertThat(settingsManager.getUserMappings().size()).isEqualTo(2); + assertThat(settingsManager.getUserMappings()).hasSize(2); } /** @@ -117,9 +117,9 @@ public class LdapSettingsManagerTest { public void testGroupMappings() { LdapSettingsManager settingsManager = new LdapSettingsManager( generateMultipleLdapSettingsWithUserAndGroupMapping().asConfig(), new LdapAutodiscovery()); - assertThat(settingsManager.getGroupMappings().size()).isEqualTo(2); + assertThat(settingsManager.getGroupMappings()).hasSize(2); // We do it twice to make sure the settings keep the same. - assertThat(settingsManager.getGroupMappings().size()).isEqualTo(2); + assertThat(settingsManager.getGroupMappings()).hasSize(2); } /** diff --git a/server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/LdapUserMappingTest.java b/server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/LdapUserMappingTest.java index c74f3746b0c..26d8df97e54 100644 --- a/server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/LdapUserMappingTest.java +++ b/server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/LdapUserMappingTest.java @@ -34,7 +34,7 @@ public class LdapUserMappingTest { assertThat(userMapping.getRealNameAttribute()).isEqualTo("cn"); assertThat(userMapping.getEmailAttribute()).isEqualTo("mail"); - assertThat(userMapping.toString()).isEqualTo("LdapUserMapping{" + + assertThat(userMapping).hasToString("LdapUserMapping{" + "baseDn=null," + " request=(&(objectClass=inetOrgPerson)(uid={0}))," + " realNameAttribute=cn," + @@ -54,7 +54,7 @@ public class LdapUserMappingTest { assertThat(search.getParameters()).isEqualTo(new String[] {"tester"}); assertThat(search.getReturningAttributes()).isNull(); - assertThat(userMapping.toString()).isEqualTo("LdapUserMapping{" + + assertThat(userMapping).hasToString("LdapUserMapping{" + "baseDn=cn=users," + " request=(&(objectClass=user)(sAMAccountName={0}))," + " realNameAttribute=cn," + diff --git a/server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/LdapUsersProviderTest.java b/server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/LdapUsersProviderTest.java index 5e99c223187..e82a602f05b 100644 --- a/server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/LdapUsersProviderTest.java +++ b/server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/LdapUsersProviderTest.java @@ -60,7 +60,7 @@ public class LdapUsersProviderTest { details = usersProvider.getUserDetails("without_email"); assertThat(details.getName()).isEqualTo("Without Email"); - assertThat(details.getEmail()).isEqualTo(""); + assertThat(details.getEmail()).isEmpty(); details = usersProvider.getUserDetails("notfound"); assertThat(details).isNull(); diff --git a/server/sonar-auth-saml/src/test/java/org/sonar/auth/saml/SamlSettingsTest.java b/server/sonar-auth-saml/src/test/java/org/sonar/auth/saml/SamlSettingsTest.java index 89d35c7554c..0c9bb0e4921 100644 --- a/server/sonar-auth-saml/src/test/java/org/sonar/auth/saml/SamlSettingsTest.java +++ b/server/sonar-auth-saml/src/test/java/org/sonar/auth/saml/SamlSettingsTest.java @@ -104,7 +104,7 @@ public class SamlSettingsTest { public void return_user_email_attribute() { settings.setProperty("sonar.auth.saml.user.email", "userEmail"); - assertThat(underTest.getUserEmail().get()).isEqualTo("userEmail"); + assertThat(underTest.getUserEmail()).contains("userEmail"); } @Test @@ -116,7 +116,7 @@ public class SamlSettingsTest { public void return_group_name_attribute() { settings.setProperty("sonar.auth.saml.group.name", "groupName"); - assertThat(underTest.getGroupName().get()).isEqualTo("groupName"); + assertThat(underTest.getGroupName()).contains("groupName"); } @Test diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MeasureComputersHolderImpl.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MeasureComputersHolderImpl.java index 68dea5471bd..012d7b7bdf5 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MeasureComputersHolderImpl.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MeasureComputersHolderImpl.java @@ -19,12 +19,13 @@ */ package org.sonar.ce.task.projectanalysis.measure; -import com.google.common.base.Predicates; +import java.util.Objects; +import java.util.stream.Collectors; +import java.util.stream.StreamSupport; import javax.annotation.CheckForNull; import org.sonar.ce.task.projectanalysis.api.measurecomputer.MeasureComputerWrapper; import static com.google.common.base.Preconditions.checkState; -import static com.google.common.collect.FluentIterable.from; import static java.util.Objects.requireNonNull; public class MeasureComputersHolderImpl implements MutableMeasureComputersHolder { @@ -42,6 +43,6 @@ public class MeasureComputersHolderImpl implements MutableMeasureComputersHolder public void setMeasureComputers(Iterable<MeasureComputerWrapper> measureComputers) { requireNonNull(measureComputers, "Measure computers cannot be null"); checkState(this.measureComputers == null, "Measure computers have already been initialized"); - this.measureComputers = from(measureComputers).filter(Predicates.notNull()).toList(); + this.measureComputers = StreamSupport.stream(measureComputers.spliterator(), false).filter(Objects::nonNull).collect(Collectors.toList()); } } diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitygate/EvaluationResultTextConverterImpl.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitygate/EvaluationResultTextConverterImpl.java index cf3d82052e5..617959fca19 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitygate/EvaluationResultTextConverterImpl.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitygate/EvaluationResultTextConverterImpl.java @@ -19,7 +19,6 @@ */ package org.sonar.ce.task.projectanalysis.qualitygate; -import com.google.common.collect.ImmutableMap; import java.util.Locale; import java.util.Map; import javax.annotation.CheckForNull; @@ -32,7 +31,7 @@ import org.sonar.core.i18n.I18n; import static java.util.Objects.requireNonNull; public final class EvaluationResultTextConverterImpl implements EvaluationResultTextConverter { - private static final Map<Condition.Operator, String> OPERATOR_LABELS = ImmutableMap.of( + private static final Map<Condition.Operator, String> OPERATOR_LABELS = Map.of( Condition.Operator.GREATER_THAN, ">", Condition.Operator.LESS_THAN, "<"); diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/linereader/SymbolsLineReader.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/linereader/SymbolsLineReader.java index ee1bc530644..d7335b68136 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/linereader/SymbolsLineReader.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/linereader/SymbolsLineReader.java @@ -40,7 +40,7 @@ import static org.sonar.ce.task.projectanalysis.source.linereader.RangeOffsetCon public class SymbolsLineReader implements LineReader { - private static final Logger LOG = Loggers.get(HighlightingLineReader.class); + private static final Logger LOG = Loggers.get(SymbolsLineReader.class); private final Component file; private final RangeOffsetConverter rangeOffsetConverter; diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistAnalysisPropertiesStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistAnalysisPropertiesStep.java index 633f2ff9e01..b90471781b5 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistAnalysisPropertiesStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistAnalysisPropertiesStep.java @@ -19,7 +19,6 @@ */ package org.sonar.ce.task.projectanalysis.step; -import com.google.common.collect.ImmutableSet; import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -43,7 +42,7 @@ import static org.sonar.core.config.CorePropertyDefinitions.SONAR_ANALYSIS_DETEC public class PersistAnalysisPropertiesStep implements ComputationStep { private static final String SONAR_PULL_REQUEST = "sonar.pullrequest."; - private static final Set<String> ANALYSIS_PROPERTIES_TO_PERSIST = ImmutableSet.of(SONAR_ANALYSIS_DETECTEDSCM, SONAR_ANALYSIS_DETECTEDCI); + private static final Set<String> ANALYSIS_PROPERTIES_TO_PERSIST = Set.of(SONAR_ANALYSIS_DETECTEDSCM, SONAR_ANALYSIS_DETECTEDCI); private final DbClient dbClient; private final AnalysisMetadataHolder analysisMetadataHolder; diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStep.java index 4481a4d3587..2595b1707f5 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStep.java @@ -53,9 +53,7 @@ public class PersistLiveMeasuresStep implements ComputationStep { /** * List of metrics that should not be persisted on file measure. */ - private static final Set<String> NOT_TO_PERSIST_ON_FILE_METRIC_KEYS = unmodifiableSet(new HashSet<>(asList( - FILE_COMPLEXITY_DISTRIBUTION_KEY, - FUNCTION_COMPLEXITY_DISTRIBUTION_KEY))); + private static final Set<String> NOT_TO_PERSIST_ON_FILE_METRIC_KEYS = Set.of(FILE_COMPLEXITY_DISTRIBUTION_KEY, FUNCTION_COMPLEXITY_DISTRIBUTION_KEY); private final DbClient dbClient; private final MetricRepository metricRepository; diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistProjectLinksStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistProjectLinksStep.java index 9947202798b..038ff74c7d1 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistProjectLinksStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistProjectLinksStep.java @@ -19,7 +19,6 @@ */ package org.sonar.ce.task.projectanalysis.step; -import com.google.common.collect.ImmutableMap; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -40,7 +39,7 @@ import org.sonar.scanner.protocol.output.ScannerReport.ComponentLink.ComponentLi import static com.google.common.base.Preconditions.checkArgument; public class PersistProjectLinksStep implements ComputationStep { - private static final Map<ComponentLinkType, String> typesConverter = ImmutableMap.of( + private static final Map<ComponentLinkType, String> typesConverter = Map.of( ComponentLinkType.HOME, ProjectLinkDto.TYPE_HOME_PAGE, ComponentLinkType.SCM, ProjectLinkDto.TYPE_SOURCES, ComponentLinkType.CI, ProjectLinkDto.TYPE_CI, diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/analysis/AnalysisImplTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/analysis/AnalysisImplTest.java index c4492e01a06..f17ec7728e4 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/analysis/AnalysisImplTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/analysis/AnalysisImplTest.java @@ -26,7 +26,6 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; public class AnalysisImplTest { - private static final long ID = 10; private static final String UUID = "uuid "; private static final long CREATED_AT = 123456789L; @@ -62,7 +61,7 @@ public class AnalysisImplTest { .setUuid(UUID) .setCreatedAt(CREATED_AT) .build().toString()) - .isEqualTo("Analysis{uuid='uuid ', createdAt=123456789}"); + .isEqualTo("Analysis{uuid='uuid ', createdAt=123456789}"); } @Test @@ -80,13 +79,13 @@ public class AnalysisImplTest { .setCreatedAt(CREATED_AT) .build(); - assertThat(analysis).isEqualTo(analysis); - assertThat(analysis).isEqualTo(sameAnalysis); - assertThat(analysis).isNotEqualTo(otherAnalysis); - assertThat(analysis).isNotEqualTo(null); - - assertThat(analysis.hashCode()).isEqualTo(analysis.hashCode()); - assertThat(analysis.hashCode()).isEqualTo(sameAnalysis.hashCode()); + assertThat(analysis) + .isEqualTo(analysis) + .isEqualTo(sameAnalysis) + .isNotEqualTo(otherAnalysis) + .isNotNull() + .hasSameHashCodeAs(analysis.hashCode()) + .hasSameHashCodeAs(sameAnalysis.hashCode()); assertThat(analysis.hashCode()).isNotEqualTo(otherAnalysis.hashCode()); } } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/analysis/AnalysisMetadataHolderImplTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/analysis/AnalysisMetadataHolderImplTest.java index 80432155a24..a08f58076c7 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/analysis/AnalysisMetadataHolderImplTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/analysis/AnalysisMetadataHolderImplTest.java @@ -177,7 +177,7 @@ public class AnalysisMetadataHolderImplTest { underTest.setCrossProjectDuplicationEnabled(true); - assertThat(underTest.isCrossProjectDuplicationEnabled()).isEqualTo(true); + assertThat(underTest.isCrossProjectDuplicationEnabled()).isTrue(); } @Test @@ -186,7 +186,7 @@ public class AnalysisMetadataHolderImplTest { underTest.setCrossProjectDuplicationEnabled(false); - assertThat(underTest.isCrossProjectDuplicationEnabled()).isEqualTo(false); + assertThat(underTest.isCrossProjectDuplicationEnabled()).isFalse(); } @Test diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/analysis/ScannerPluginTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/analysis/ScannerPluginTest.java index 3bd4fa87edd..308953ddf3c 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/analysis/ScannerPluginTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/analysis/ScannerPluginTest.java @@ -38,24 +38,25 @@ public class ScannerPluginTest { public void verify_toString() { ScannerPlugin plugin = new ScannerPlugin("key", "base", 12345L); - assertThat(plugin.toString()).isEqualTo("ScannerPlugin{key='key', basePluginKey='base', updatedAt='12345'}"); + assertThat(plugin).hasToString("ScannerPlugin{key='key', basePluginKey='base', updatedAt='12345'}"); } @Test public void equals_is_based_on_key_only() { ScannerPlugin plugin = new ScannerPlugin("key", "base", 12345L); - assertThat(plugin).isEqualTo(plugin); - assertThat(plugin).isEqualTo(new ScannerPlugin("key", null, 45678L)); - assertThat(plugin).isNotEqualTo(new ScannerPlugin("key2", "base", 12345L)); - assertThat(plugin).isNotEqualTo(null); - assertThat(plugin).isNotEqualTo("toto"); + assertThat(plugin) + .isEqualTo(plugin) + .isEqualTo(new ScannerPlugin("key", null, 45678L)) + .isNotEqualTo(new ScannerPlugin("key2", "base", 12345L)) + .isNotNull() + .isNotEqualTo("toto"); } @Test public void hashcode_is_based_on_key_only() { ScannerPlugin plugin = new ScannerPlugin("key", "base", 12345L); - assertThat(plugin.hashCode()).isEqualTo("key".hashCode()); + assertThat(plugin).hasSameHashCodeAs("key"); } } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/measurecomputer/ComponentImplTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/measurecomputer/ComponentImplTest.java index e31f23ee65c..e752ec477b7 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/measurecomputer/ComponentImplTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/measurecomputer/ComponentImplTest.java @@ -97,19 +97,19 @@ public class ComponentImplTest { ComponentImpl sameComponent = new ComponentImpl("Project1", Component.Type.PROJECT, null); ComponentImpl anotherComponent = new ComponentImpl("Project2", Component.Type.PROJECT, null); - assertThat(component).isEqualTo(component); - assertThat(component).isEqualTo(sameComponent); - assertThat(component).isNotEqualTo(anotherComponent); - assertThat(component).isNotEqualTo(null); - - assertThat(component.hashCode()).isEqualTo(component.hashCode()); - assertThat(component.hashCode()).isEqualTo(sameComponent.hashCode()); + assertThat(component) + .isEqualTo(component) + .isEqualTo(sameComponent) + .isNotEqualTo(anotherComponent) + .isNotNull() + .hasSameHashCodeAs(component) + .hasSameHashCodeAs(sameComponent); assertThat(component.hashCode()).isNotEqualTo(anotherComponent.hashCode()); } @Test public void test_to_string() { - assertThat(new ComponentImpl("File", Component.Type.FILE, new ComponentImpl.FileAttributesImpl("xoo", true)).toString()) - .isEqualTo("ComponentImpl{key=File, type='FILE', fileAttributes=FileAttributesImpl{languageKey='xoo', unitTest=true}}"); + assertThat(new ComponentImpl("File", Component.Type.FILE, new ComponentImpl.FileAttributesImpl("xoo", true))) + .hasToString("ComponentImpl{key=File, type='FILE', fileAttributes=FileAttributesImpl{languageKey='xoo', unitTest=true}}"); } } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/measurecomputer/MeasureComputerContextImplTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/measurecomputer/MeasureComputerContextImplTest.java index 63c9458539c..5e74d6964e9 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/measurecomputer/MeasureComputerContextImplTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/measurecomputer/MeasureComputerContextImplTest.java @@ -257,7 +257,7 @@ public class MeasureComputerContextImplTest { .setSeverity("MAJOR") .setStatus("CLOSED") .setResolution("FIXED") - .setEffort(Duration.create(10l)); + .setEffort(Duration.create(10L)); MeasureComputerContextImpl underTest = newContext(PROJECT_REF, Arrays.asList(issue)); @@ -268,7 +268,7 @@ public class MeasureComputerContextImplTest { assertThat(result.severity()).isEqualTo("MAJOR"); assertThat(result.status()).isEqualTo("CLOSED"); assertThat(result.resolution()).isEqualTo("FIXED"); - assertThat(result.effort()).isEqualTo(Duration.create(10l)); + assertThat(result.effort()).isEqualTo(Duration.create(10L)); } private MeasureComputerContextImpl newContext(int componentRef) { diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/measurecomputer/MeasureComputerDefinitionImplTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/measurecomputer/MeasureComputerDefinitionImplTest.java index f1ecae09d98..d775f89bf44 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/measurecomputer/MeasureComputerDefinitionImplTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/measurecomputer/MeasureComputerDefinitionImplTest.java @@ -159,7 +159,7 @@ public class MeasureComputerDefinitionImplTest { assertThat(computer).isEqualTo(computer) .isEqualTo(sameComputer) .isNotEqualTo(anotherComputer) - .isNotEqualTo(null); + .isNotNull(); assertThat(computer) .hasSameHashCodeAs(computer) diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/measurecomputer/MeasureImplTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/measurecomputer/MeasureImplTest.java index 623fc2f6735..7b039c1b52d 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/measurecomputer/MeasureImplTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/measurecomputer/MeasureImplTest.java @@ -31,7 +31,7 @@ public class MeasureImplTest { @Test public void get_int_value() { MeasureImpl measure = new MeasureImpl(Measure.newMeasureBuilder().create(1)); - assertThat(measure.getIntValue()).isEqualTo(1); + assertThat(measure.getIntValue()).isOne(); } @Test @@ -63,7 +63,7 @@ public class MeasureImplTest { @Test public void get_long_value() { MeasureImpl measure = new MeasureImpl(Measure.newMeasureBuilder().create(1L)); - assertThat(measure.getLongValue()).isEqualTo(1L); + assertThat(measure.getLongValue()).isOne(); } @Test diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/posttask/CeTaskImplTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/posttask/CeTaskImplTest.java index 6fb8cd070e0..06e53d9e921 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/posttask/CeTaskImplTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/posttask/CeTaskImplTest.java @@ -52,6 +52,6 @@ public class CeTaskImplTest { @Test public void verify_toString() { - assertThat(new CeTaskImpl(SOME_ID, CeTask.Status.SUCCESS).toString()).isEqualTo("CeTaskImpl{id='some id', status=SUCCESS}"); + assertThat(new CeTaskImpl(SOME_ID, CeTask.Status.SUCCESS)).hasToString("CeTaskImpl{id='some id', status=SUCCESS}"); } } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/posttask/ConditionImplTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/posttask/ConditionImplTest.java index 49a2eaf329c..5b193b70599 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/posttask/ConditionImplTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/posttask/ConditionImplTest.java @@ -124,8 +124,8 @@ public class ConditionImplTest { @Test public void toString_ConditionImpl_of_type_different_from_NO_VALUE() { - assertThat(builder.build().toString()) - .isEqualTo( + assertThat(builder.build()) + .hasToString( "ConditionImpl{status=OK, metricKey='metricKey', operator=GREATER_THAN, errorThreshold='error threshold', value='value'}"); } @@ -134,8 +134,8 @@ public class ConditionImplTest { builder.setStatus(QualityGate.EvaluationStatus.NO_VALUE) .setValue(null); - assertThat(builder.build().toString()) - .isEqualTo( + assertThat(builder.build()) + .hasToString( "ConditionImpl{status=NO_VALUE, metricKey='metricKey', operator=GREATER_THAN, errorThreshold='error threshold', value='null'}"); } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/posttask/ProjectImplTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/posttask/ProjectImplTest.java index cf820975992..7615ad8235f 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/posttask/ProjectImplTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/posttask/ProjectImplTest.java @@ -62,8 +62,8 @@ public class ProjectImplTest { @Test public void verify_toString() { - assertThat(new ProjectImpl(SOME_UUID, SOME_KEY, SOME_NAME).toString()) - .isEqualTo("ProjectImpl{uuid='some uuid', key='some key', name='some name'}"); + assertThat(new ProjectImpl(SOME_UUID, SOME_KEY, SOME_NAME)) + .hasToString("ProjectImpl{uuid='some uuid', key='some key', name='some name'}"); } } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/posttask/QualityGateImplTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/posttask/QualityGateImplTest.java index b95cf7083b1..6abab92ee7b 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/posttask/QualityGateImplTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/posttask/QualityGateImplTest.java @@ -83,7 +83,7 @@ public class QualityGateImplTest { public void verify_toString() { when(condition.toString()).thenReturn("{Condition}"); - assertThat(underTest.toString()) - .isEqualTo("QualityGateImpl{id='some id', name='some name', status=OK, conditions=[{Condition}]}"); + assertThat(underTest) + .hasToString("QualityGateImpl{id='some id', name='some name', status=OK, conditions=[{Condition}]}"); } } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/CallRecorderPathAwareVisitor.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/CallRecorderPathAwareVisitor.java index e9a39e6c9d2..6cb2e6b2f7c 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/CallRecorderPathAwareVisitor.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/CallRecorderPathAwareVisitor.java @@ -19,14 +19,13 @@ */ package org.sonar.ce.task.projectanalysis.component; -import com.google.common.base.Function; import java.util.ArrayList; import java.util.List; import java.util.NoSuchElementException; -import javax.annotation.Nonnull; +import java.util.stream.Collectors; +import java.util.stream.StreamSupport; import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.collect.FluentIterable.from; class CallRecorderPathAwareVisitor extends PathAwareVisitorAdapter<Integer> { final List<PathAwareCallRecord> callsRecords = new ArrayList<>(); @@ -86,13 +85,7 @@ class CallRecorderPathAwareVisitor extends PathAwareVisitorAdapter<Integer> { } private static List<Integer> toValueList(Path<Integer> path) { - return from(path.getCurrentPath()).transform(new Function<PathElement<Integer>, Integer>() { - @Nonnull - @Override - public Integer apply(@Nonnull PathElement<Integer> input) { - return input.getElement(); - } - }).toList(); + return StreamSupport.stream(path.getCurrentPath().spliterator(), false).map(PathElement::getElement).collect(Collectors.toList()); } private static Integer getParent(Path<Integer> path) { diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ComponentImplTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ComponentImplTest.java index 3e8255d4f7b..cc5e809c4a4 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ComponentImplTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ComponentImplTest.java @@ -226,9 +226,9 @@ public class ComponentImplTest { public void hashCode_is_hashcode_of_uuid() { ComponentImpl.Builder builder = buildSimpleComponent(FILE, "1").setUuid(UUID); - assertThat(builder.build().hashCode()).isEqualTo(builder.build().hashCode()); - assertThat(builder.build().hashCode()).isEqualTo(buildSimpleComponent(FILE, "2").setUuid(UUID).build().hashCode()); - assertThat(builder.build().hashCode()).isEqualTo(UUID.hashCode()); + assertThat(builder.build()).hasSameHashCodeAs(builder.build().hashCode()); + assertThat(builder.build()).hasSameHashCodeAs(buildSimpleComponent(FILE, "2").setUuid(UUID).build().hashCode()); + assertThat(builder.build()).hasSameHashCodeAs(UUID.hashCode()); } private static ComponentImpl.Builder buildSimpleComponent(Component.Type type, String dbKey) { diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ComponentTreeBuilderTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ComponentTreeBuilderTest.java index a5a0a810b24..34fe89feadd 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ComponentTreeBuilderTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ComponentTreeBuilderTest.java @@ -654,7 +654,7 @@ public class ComponentTreeBuilderTest { Component root = call(project); Component dir = root.getChildren().iterator().next(); Component file = dir.getChildren().iterator().next(); - assertThat(file.getFileAttributes().getLines()).isEqualTo(1); + assertThat(file.getFileAttributes().getLines()).isOne(); assertThat(file.getFileAttributes().getLanguageKey()).isNull(); assertThat(file.getFileAttributes().isUnitTest()).isFalse(); } @@ -698,7 +698,7 @@ public class ComponentTreeBuilderTest { Component root = call(project); Component dir = root.getChildren().iterator().next(); Component file = dir.getChildren().iterator().next(); - assertThat(file.getFileAttributes().getLines()).isEqualTo(1); + assertThat(file.getFileAttributes().getLines()).isOne(); assertThat(file.getFileAttributes().getLanguageKey()).isEqualTo("js"); assertThat(file.getFileAttributes().isUnitTest()).isTrue(); } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/FileAttributesTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/FileAttributesTest.java index 0425ae4f20b..0275211ed71 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/FileAttributesTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/FileAttributesTest.java @@ -70,7 +70,7 @@ public class FileAttributesTest { @Test public void test_toString() { - assertThat(new FileAttributes(true, "java", 10).toString()).isEqualTo("FileAttributes{languageKey='java', unitTest=true, lines=10}"); - assertThat(new FileAttributes(false, null, 1).toString()).isEqualTo("FileAttributes{languageKey='null', unitTest=false, lines=1}"); + assertThat(new FileAttributes(true, "java", 10)).hasToString("FileAttributes{languageKey='java', unitTest=true, lines=10}"); + assertThat(new FileAttributes(false, null, 1)).hasToString("FileAttributes{languageKey='null', unitTest=false, lines=1}"); } } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/container/ProjectAnalysisTaskContainerPopulatorTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/container/ProjectAnalysisTaskContainerPopulatorTest.java index 5c386c678ee..be880239e00 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/container/ProjectAnalysisTaskContainerPopulatorTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/container/ProjectAnalysisTaskContainerPopulatorTest.java @@ -20,7 +20,6 @@ package org.sonar.ce.task.projectanalysis.container; import com.google.common.base.Function; -import com.google.common.base.Predicate; import com.google.common.collect.ImmutableList; import java.lang.reflect.Modifier; import java.util.ArrayList; @@ -41,7 +40,6 @@ import org.sonar.ce.task.step.ComputationStep; import org.sonar.core.platform.ComponentContainer; import org.sonar.core.util.stream.MoreCollectors; -import static com.google.common.collect.FluentIterable.from; import static com.google.common.collect.Sets.difference; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -175,19 +173,10 @@ public class ProjectAnalysisTaskContainerPopulatorTest { @Override public <T> List<T> getComponentsByType(final Class<T> type) { - return from(added) - .filter(new Predicate<Object>() { - @Override - public boolean apply(@Nonnull Object input) { - return input.getClass().getSimpleName().contains(type.getSimpleName()); - } - }).transform(new Function<Object, T>() { - @Override - @Nonnull - public T apply(@Nonnull Object input) { - return (T) input; - } - }).toList(); + return added.stream() + .filter(input -> input.getClass().getSimpleName().contains(type.getSimpleName())) + .map(input -> (T) input) + .collect(Collectors.toList()); } } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/duplication/CrossProjectDuplicateTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/duplication/CrossProjectDuplicateTest.java index 938c97c9fe4..6d2867455a4 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/duplication/CrossProjectDuplicateTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/duplication/CrossProjectDuplicateTest.java @@ -67,7 +67,7 @@ public class CrossProjectDuplicateTest { @Test public void hashcode_depends_on_file_and_TextBlock() { TextBlock textBlock = new TextBlock(1, 2); - assertThat(new CrossProjectDuplicate(FILE_KEY_1, textBlock).hashCode()).isEqualTo(new CrossProjectDuplicate(FILE_KEY_1, textBlock).hashCode()); + assertThat(new CrossProjectDuplicate(FILE_KEY_1, textBlock)).hasSameHashCodeAs(new CrossProjectDuplicate(FILE_KEY_1, textBlock)); assertThat(new CrossProjectDuplicate(FILE_KEY_1, textBlock).hashCode()).isNotEqualTo(new CrossProjectDuplicate(FILE_KEY_2, textBlock).hashCode()); assertThat(new CrossProjectDuplicate(FILE_KEY_1, textBlock).hashCode()).isNotEqualTo(new CrossProjectDuplicate(FILE_KEY_2, new TextBlock(1, 1)).hashCode()); @@ -75,7 +75,7 @@ public class CrossProjectDuplicateTest { @Test public void verify_toString() { - assertThat(new CrossProjectDuplicate(FILE_KEY_1, new TextBlock(1, 2)).toString()).isEqualTo("CrossProjectDuplicate{fileKey='file key 1', textBlock=TextBlock{start=1, end=2}}"); + assertThat(new CrossProjectDuplicate(FILE_KEY_1, new TextBlock(1, 2))).hasToString("CrossProjectDuplicate{fileKey='file key 1', textBlock=TextBlock{start=1, end=2}}"); } } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/duplication/DuplicationRepositoryRule.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/duplication/DuplicationRepositoryRule.java index a5290b21624..cebfb389325 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/duplication/DuplicationRepositoryRule.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/duplication/DuplicationRepositoryRule.java @@ -19,13 +19,12 @@ */ package org.sonar.ce.task.projectanalysis.duplication; -import com.google.common.base.Function; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; import java.util.Arrays; import java.util.Collections; +import java.util.stream.Collectors; import javax.annotation.CheckForNull; -import javax.annotation.Nonnull; import org.junit.rules.ExternalResource; import org.sonar.ce.task.projectanalysis.component.Component; import org.sonar.ce.task.projectanalysis.component.ComponentProvider; @@ -34,7 +33,6 @@ import org.sonar.ce.task.projectanalysis.component.TreeRootHolderComponentProvid import org.sonar.ce.task.projectanalysis.component.TreeRootHolderRule; import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.collect.FluentIterable.from; import static java.util.Objects.requireNonNull; public class DuplicationRepositoryRule extends ExternalResource implements DuplicationRepository { @@ -101,7 +99,7 @@ public class DuplicationRepositoryRule extends ExternalResource implements Dupli component, new Duplication( original, - from(Arrays.asList(duplicates)).transform(TextBlockToInnerDuplicate.INSTANCE).toList())); + Arrays.stream(duplicates).map(InnerDuplicate::new).collect(Collectors.toList()))); return this; } @@ -169,14 +167,4 @@ public class DuplicationRepositoryRule extends ExternalResource implements Dupli requireNonNull(this.componentProvider, "Methods with component reference can not be used unless a TreeRootHolder has been provided when instantiating the rule"); this.componentProvider.ensureInitialized(); } - - private enum TextBlockToInnerDuplicate implements Function<TextBlock, Duplicate> { - INSTANCE; - - @Override - @Nonnull - public Duplicate apply(@Nonnull TextBlock input) { - return new InnerDuplicate(input); - } - } } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/duplication/DuplicationTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/duplication/DuplicationTest.java index d6bc28a9b32..9e70572c1dc 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/duplication/DuplicationTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/duplication/DuplicationTest.java @@ -154,7 +154,7 @@ public class DuplicationTest { public void hashcode_is_based_on_original_only() { Duplication duplication = new Duplication(SOME_ORIGINAL_TEXTBLOCK, Arrays.asList(new InnerDuplicate(TEXT_BLOCK_1))); - assertThat(duplication.hashCode()).isEqualTo(new Duplication(SOME_ORIGINAL_TEXTBLOCK, Arrays.asList(new InnerDuplicate(TEXT_BLOCK_1))).hashCode()); + assertThat(duplication).hasSameHashCodeAs(new Duplication(SOME_ORIGINAL_TEXTBLOCK, Arrays.asList(new InnerDuplicate(TEXT_BLOCK_1)))); assertThat(duplication.hashCode()).isNotEqualTo(new Duplication(SOME_ORIGINAL_TEXTBLOCK, Arrays.asList(new InnerDuplicate(TEXT_BLOCK_2))).hashCode()); assertThat(duplication.hashCode()).isNotEqualTo(new Duplication(TEXT_BLOCK_1, Arrays.asList(new InnerDuplicate(SOME_ORIGINAL_TEXTBLOCK))).hashCode()); } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/duplication/InProjectDuplicateTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/duplication/InProjectDuplicateTest.java index acde4f14a7f..9c420a56796 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/duplication/InProjectDuplicateTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/duplication/InProjectDuplicateTest.java @@ -77,7 +77,7 @@ public class InProjectDuplicateTest { @Test public void hashcode_depends_on_file_and_TextBlock() { TextBlock textBlock = new TextBlock(1, 2); - assertThat(new InProjectDuplicate(FILE_1, textBlock).hashCode()).isEqualTo(new InProjectDuplicate(FILE_1, textBlock).hashCode()); + assertThat(new InProjectDuplicate(FILE_1, textBlock)).hasSameHashCodeAs(new InProjectDuplicate(FILE_1, textBlock)); assertThat(new InProjectDuplicate(FILE_1, textBlock).hashCode()).isNotEqualTo(new InProjectDuplicate(FILE_2, textBlock).hashCode()); assertThat(new InProjectDuplicate(FILE_1, textBlock).hashCode()).isNotEqualTo(new InProjectDuplicate(FILE_2, new TextBlock(1, 1)).hashCode()); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/duplication/InnerDuplicateTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/duplication/InnerDuplicateTest.java index b62e3aea8fb..98801f99715 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/duplication/InnerDuplicateTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/duplication/InnerDuplicateTest.java @@ -48,11 +48,11 @@ public class InnerDuplicateTest { @Test public void hashcode_is_TextBlock_hashcode() { TextBlock textBlock = new TextBlock(1, 2); - assertThat(new InnerDuplicate(textBlock).hashCode()).isEqualTo(textBlock.hashCode()); + assertThat(new InnerDuplicate(textBlock)).hasSameHashCodeAs(textBlock); } @Test public void verify_toString() { - assertThat(new InnerDuplicate(new TextBlock(1, 2)).toString()).isEqualTo("InnerDuplicate{textBlock=TextBlock{start=1, end=2}}"); + assertThat(new InnerDuplicate(new TextBlock(1, 2))).hasToString("InnerDuplicate{textBlock=TextBlock{start=1, end=2}}"); } } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/duplication/TextBlockTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/duplication/TextBlockTest.java index 7b12ae7789d..e843e1d079d 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/duplication/TextBlockTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/duplication/TextBlockTest.java @@ -68,8 +68,8 @@ public class TextBlockTest { @Test public void hashcode_is_based__on_start_and_end() { - assertThat(new TextBlock(15, 15).hashCode()).isEqualTo(new TextBlock(15, 15).hashCode()); - assertThat(new TextBlock(15, 300).hashCode()).isEqualTo(new TextBlock(15, 300).hashCode()); + assertThat(new TextBlock(15, 15)).hasSameHashCodeAs(new TextBlock(15, 15)); + assertThat(new TextBlock(15, 300)).hasSameHashCodeAs(new TextBlock(15, 300)); assertThat(new TextBlock(15, 300).hashCode()).isNotEqualTo(new TextBlock(15, 15).hashCode()); } @@ -90,7 +90,7 @@ public class TextBlockTest { @Test public void verify_toString() { - assertThat(new TextBlock(13, 400).toString()).isEqualTo("TextBlock{start=13, end=400}"); + assertThat(new TextBlock(13, 400)).hasToString("TextBlock{start=13, end=400}"); } } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/event/EventTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/event/EventTest.java index d823db06c21..eb061526fd3 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/event/EventTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/event/EventTest.java @@ -63,8 +63,9 @@ public class EventTest { @Test public void same_name_and_category_make_equal_events() { Event source = Event.createAlert(SOME_NAME, null, null); - assertThat(source).isEqualTo(Event.createAlert(SOME_NAME, null, null)); - assertThat(source).isEqualTo(source); - assertThat(source).isNotEqualTo(null); + assertThat(source) + .isEqualTo(Event.createAlert(SOME_NAME, null, null)) + .isEqualTo(source) + .isNotNull(); } } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/filemove/FileMoveDetectionStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/filemove/FileMoveDetectionStepTest.java index 1e27dd9ecd6..1ea53020a4e 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/filemove/FileMoveDetectionStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/filemove/FileMoveDetectionStepTest.java @@ -348,7 +348,7 @@ public class FileMoveDetectionStepTest { assertThat(movedFilesRepository.getComponentsWithOriginal()).isEmpty(); assertThat(scoreMatrixDumper.scoreMatrix.getMaxScore()) - .isGreaterThan(0) + .isPositive() .isLessThan(MIN_REQUIRED_SCORE); assertThat(addedFileRepository.getComponents()).contains(file2); verifyStatistics(context, 1, 1, 1, 0); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/filemove/MatchTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/filemove/MatchTest.java index 31d85929675..c75c03069b0 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/filemove/MatchTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/filemove/MatchTest.java @@ -75,6 +75,6 @@ public class MatchTest { @Test public void toString_prints_both_properties() { - assertThat(underTest.toString()).isEqualTo("{key=>reportKey}"); + assertThat(underTest).hasToString("{key=>reportKey}"); } } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/counter/LongValueTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/counter/LongValueTest.java index 9b627307fbc..296e96bd4c7 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/counter/LongValueTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/counter/LongValueTest.java @@ -72,7 +72,7 @@ public class LongValueTest { private static void verifyUnsetVariationValue(LongValue variationValue) { assertThat(variationValue.isSet()).isFalse(); - assertThat(variationValue.getValue()).isEqualTo(0L); + assertThat(variationValue.getValue()).isZero(); } private static void verifySetVariationValue(LongValue variationValue, long expected) { diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/coverage/CoverageUtilsTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/coverage/CoverageUtilsTest.java index b03c77bc5e2..0437f97ad78 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/coverage/CoverageUtilsTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/formula/coverage/CoverageUtilsTest.java @@ -52,14 +52,14 @@ public class CoverageUtilsTest { @Test public void getLongMeasureValue_returns_0_if_measure_does_not_exist() { - assertThat(getLongMeasureValue(fileAggregateContext, SOME_METRIC_KEY)).isEqualTo(0L); + assertThat(getLongMeasureValue(fileAggregateContext, SOME_METRIC_KEY)).isZero(); } @Test public void getLongMeasureValue_returns_0_if_measure_is_NO_VALUE() { fileAggregateContext.put(SOME_METRIC_KEY, newMeasureBuilder().createNoValue()); - assertThat(getLongMeasureValue(fileAggregateContext, SOME_METRIC_KEY)).isEqualTo(0L); + assertThat(getLongMeasureValue(fileAggregateContext, SOME_METRIC_KEY)).isZero(); } @Test diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/DebtCalculatorTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/DebtCalculatorTest.java index 8d375515062..5ec7230bc63 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/DebtCalculatorTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/DebtCalculatorTest.java @@ -78,10 +78,10 @@ public class DebtCalculatorTest { public void copy_effort_for_external_issues() { issue.setGap(null); issue.setIsFromExternalRuleEngine(true); - issue.setEffort(Duration.create(20l)); + issue.setEffort(Duration.create(20L)); rule.setFunction(null); - assertThat(underTest.calculate(issue).toMinutes()).isEqualTo(20l); + assertThat(underTest.calculate(issue).toMinutes()).isEqualTo(20L); } @Test diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/NewAdHocRuleTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/NewAdHocRuleTest.java index 56adca43ae2..14e43a63dff 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/NewAdHocRuleTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/NewAdHocRuleTest.java @@ -40,13 +40,13 @@ public class NewAdHocRuleTest { NewAdHocRule adHocRule2 = new NewAdHocRule(ScannerReport.ExternalIssue.newBuilder().setEngineId("eslint").setRuleId("no-cond-assign").build()); NewAdHocRule anotherAdHocRule = new NewAdHocRule(ScannerReport.ExternalIssue.newBuilder().setEngineId("eslint").setRuleId("another").build()); - assertThat(adHocRule1).isEqualTo(adHocRule1); - assertThat(adHocRule1).isEqualTo(adHocRule2); - assertThat(adHocRule1).isNotEqualTo(null); - assertThat(adHocRule1).isNotEqualTo(anotherAdHocRule); - - assertThat(adHocRule1.hashCode()).isEqualTo(adHocRule1.hashCode()); - assertThat(adHocRule1.hashCode()).isEqualTo(adHocRule2.hashCode()); + assertThat(adHocRule1) + .isEqualTo(adHocRule1) + .isEqualTo(adHocRule2) + .isNotNull() + .isNotEqualTo(anotherAdHocRule) + .hasSameHashCodeAs(adHocRule1) + .hasSameHashCodeAs(adHocRule2); assertThat(adHocRule1.hashCode()).isNotEqualTo(anotherAdHocRule.hashCode()); } } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/TrackerRawInputFactoryTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/TrackerRawInputFactoryTest.java index 00b486bddb7..141d7ebfa62 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/TrackerRawInputFactoryTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/TrackerRawInputFactoryTest.java @@ -231,7 +231,7 @@ public class TrackerRawInputFactoryTest { .setEngineId("eslint") .setRuleId("S001") .setSeverity(Constants.Severity.BLOCKER) - .setEffort(20l) + .setEffort(20L) .setType(issueType) .build(); reportReader.putExternalIssues(FILE.getReportAttributes().getRef(), asList(reportIssue)); @@ -245,7 +245,7 @@ public class TrackerRawInputFactoryTest { assertThat(issue.ruleKey()).isEqualTo(RuleKey.of("external_eslint", "S001")); assertThat(issue.severity()).isEqualTo(Severity.BLOCKER); assertThat(issue.line()).isEqualTo(2); - assertThat(issue.effort()).isEqualTo(Duration.create(20l)); + assertThat(issue.effort()).isEqualTo(Duration.create(20L)); assertThat(issue.message()).isEqualTo("the message"); assertThat(issue.type()).isEqualTo(expectedRuleType); @@ -288,7 +288,7 @@ public class TrackerRawInputFactoryTest { assertThat(issue.ruleKey()).isEqualTo(RuleKey.of("external_eslint", "S001")); assertThat(issue.severity()).isEqualTo(Severity.BLOCKER); assertThat(issue.line()).isEqualTo(2); - assertThat(issue.effort()).isEqualTo(Duration.create(0l)); + assertThat(issue.effort()).isEqualTo(Duration.create(0L)); assertThat(issue.message()).isEqualTo("the message"); assertThat(issue.type()).isEqualTo(expectedRuleType); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/filter/IssuePatternTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/filter/IssuePatternTest.java index 814a9a99b83..1d7258f9c42 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/filter/IssuePatternTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/filter/IssuePatternTest.java @@ -61,7 +61,7 @@ public class IssuePatternTest { public void test_to_string() { IssuePattern pattern = new IssuePattern("*", "checkstyle:*"); - assertThat(pattern.toString()).isEqualTo( + assertThat(pattern).hasToString( "IssuePattern{componentPattern=*, rulePattern=checkstyle:*}"); } } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/language/HandleUnanalyzedLanguagesStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/language/HandleUnanalyzedLanguagesStepTest.java index 221345392d8..281709b3e98 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/language/HandleUnanalyzedLanguagesStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/language/HandleUnanalyzedLanguagesStepTest.java @@ -151,7 +151,7 @@ public class HandleUnanalyzedLanguagesStepTest { "1 unanalyzed C++ file was detected in this project during the last analysis. C++ cannot be analyzed with your current SonarQube edition. Please" + " consider <a target=\"_blank\" href=\"https://www.sonarqube.org/trial-request/developer-edition/?referrer=sonarqube-cpp\">upgrading to Developer" + " Edition</a> to find Bugs, Code Smells, Vulnerabilities and Security Hotspots in this file."); - assertThat(measureRepository.getAddedRawMeasure(PROJECT_REF, UNANALYZED_CPP_KEY).get().getIntValue()).isEqualTo(1); + assertThat(measureRepository.getAddedRawMeasure(PROJECT_REF, UNANALYZED_CPP_KEY).get().getIntValue()).isOne(); assertThat(measureRepository.getAddedRawMeasure(PROJECT_REF, UNANALYZED_C_KEY)).isEmpty(); } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/language/LanguageRepositoryImplTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/language/LanguageRepositoryImplTest.java index d98333f56e6..745a540ad49 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/language/LanguageRepositoryImplTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/language/LanguageRepositoryImplTest.java @@ -40,14 +40,14 @@ public class LanguageRepositoryImplTest { @Test public void find_on_empty_LanguageRepository_returns_absent() { - assertThat(new LanguageRepositoryImpl().find(ANY_KEY).isPresent()).isFalse(); + assertThat(new LanguageRepositoryImpl().find(ANY_KEY)).isEmpty(); } @Test public void find_by_key_returns_the_same_object() { LanguageRepositoryImpl languageRepository = new LanguageRepositoryImpl(SOME_LANGUAGE); Optional<Language> language = languageRepository.find(SOME_LANGUAGE_KEY); - assertThat(language.isPresent()).isTrue(); + assertThat(language).isPresent(); assertThat(language.get()).isSameAs(SOME_LANGUAGE); } @@ -55,7 +55,7 @@ public class LanguageRepositoryImplTest { public void find_by_other_key_returns_absent() { LanguageRepositoryImpl languageRepository = new LanguageRepositoryImpl(SOME_LANGUAGE); Optional<Language> language = languageRepository.find(ANY_KEY); - assertThat(language.isPresent()).isFalse(); + assertThat(language).isEmpty(); } private static Language createLanguage(final String key, final String nameSuffix) { diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/BatchMeasureToMeasureTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/BatchMeasureToMeasureTest.java index efe52ccdb96..55f9928f05d 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/BatchMeasureToMeasureTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/BatchMeasureToMeasureTest.java @@ -141,7 +141,7 @@ public class BatchMeasureToMeasureTest { public void toMeasure_returns_no_value_if_dto_has_no_value_for_Int_Metric() { Optional<Measure> measure = underTest.toMeasure(EMPTY_BATCH_MEASURE, SOME_INT_METRIC); - assertThat(measure.isPresent()).isTrue(); + assertThat(measure).isPresent(); assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.NO_VALUE); } @@ -153,7 +153,7 @@ public class BatchMeasureToMeasureTest { Optional<Measure> measure = underTest.toMeasure(batchMeasure, SOME_INT_METRIC); - assertThat(measure.isPresent()).isTrue(); + assertThat(measure).isPresent(); assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.INT); assertThat(measure.get().getIntValue()).isEqualTo(10); assertThat(measure.get().getData()).isEqualTo(SOME_DATA); @@ -163,15 +163,15 @@ public class BatchMeasureToMeasureTest { public void toMeasure_returns_no_value_if_dto_has_no_value_for_Long_Metric() { Optional<Measure> measure = underTest.toMeasure(EMPTY_BATCH_MEASURE, SOME_LONG_METRIC); - assertThat(measure.isPresent()).isTrue(); + assertThat(measure).isPresent(); assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.NO_VALUE); } @Test public void toMeasure_returns_long_part_of_value_in_dto_for_Long_Metric() { - Optional<Measure> measure = underTest.toMeasure(ScannerReport.Measure.newBuilder().setLongValue(LongValue.newBuilder().setValue(15l)).build(), SOME_LONG_METRIC); + Optional<Measure> measure = underTest.toMeasure(ScannerReport.Measure.newBuilder().setLongValue(LongValue.newBuilder().setValue(15L)).build(), SOME_LONG_METRIC); - assertThat(measure.isPresent()).isTrue(); + assertThat(measure).isPresent(); assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.LONG); assertThat(measure.get().getLongValue()).isEqualTo(15); } @@ -179,12 +179,12 @@ public class BatchMeasureToMeasureTest { @Test public void toMeasure_maps_data_and_alert_properties_in_dto_for_Long_Metric() { ScannerReport.Measure batchMeasure = ScannerReport.Measure.newBuilder() - .setLongValue(LongValue.newBuilder().setValue(10l).setData(SOME_DATA)) + .setLongValue(LongValue.newBuilder().setValue(10L).setData(SOME_DATA)) .build(); Optional<Measure> measure = underTest.toMeasure(batchMeasure, SOME_LONG_METRIC); - assertThat(measure.isPresent()).isTrue(); + assertThat(measure).isPresent(); assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.LONG); assertThat(measure.get().getLongValue()).isEqualTo(10); assertThat(measure.get().getData()).isEqualTo(SOME_DATA); @@ -194,7 +194,7 @@ public class BatchMeasureToMeasureTest { public void toMeasure_returns_no_value_if_dto_has_no_value_for_Double_Metric() { Optional<Measure> measure = underTest.toMeasure(EMPTY_BATCH_MEASURE, SOME_DOUBLE_METRIC); - assertThat(measure.isPresent()).isTrue(); + assertThat(measure).isPresent(); assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.NO_VALUE); } @@ -206,7 +206,7 @@ public class BatchMeasureToMeasureTest { Optional<Measure> measure = underTest.toMeasure(batchMeasure, SOME_DOUBLE_METRIC); - assertThat(measure.isPresent()).isTrue(); + assertThat(measure).isPresent(); assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.DOUBLE); assertThat(measure.get().getDoubleValue()).isEqualTo(10.6395d); assertThat(measure.get().getData()).isEqualTo(SOME_DATA); @@ -216,7 +216,7 @@ public class BatchMeasureToMeasureTest { public void toMeasure_returns_no_value_if_dto_has_no_value_for_Boolean_metric() { Optional<Measure> measure = underTest.toMeasure(EMPTY_BATCH_MEASURE, SOME_BOOLEAN_METRIC); - assertThat(measure.isPresent()).isTrue(); + assertThat(measure).isPresent(); assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.NO_VALUE); } @@ -229,7 +229,7 @@ public class BatchMeasureToMeasureTest { private void verify_toMeasure_returns_false_value_if_dto_has_invalid_value_for_Boolean_metric(boolean expected) { Optional<Measure> measure = underTest.toMeasure(ScannerReport.Measure.newBuilder().setBooleanValue(BoolValue.newBuilder().setValue(expected)).build(), SOME_BOOLEAN_METRIC); - assertThat(measure.isPresent()).isTrue(); + assertThat(measure).isPresent(); assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.BOOLEAN); assertThat(measure.get().getBooleanValue()).isEqualTo(expected); } @@ -241,7 +241,7 @@ public class BatchMeasureToMeasureTest { Optional<Measure> measure = underTest.toMeasure(batchMeasure, SOME_BOOLEAN_METRIC); - assertThat(measure.isPresent()).isTrue(); + assertThat(measure).isPresent(); assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.BOOLEAN); assertThat(measure.get().getBooleanValue()).isTrue(); assertThat(measure.get().getData()).isEqualTo(SOME_DATA); @@ -251,7 +251,7 @@ public class BatchMeasureToMeasureTest { public void toMeasure_returns_no_value_if_dto_has_no_value_for_String_Metric() { Optional<Measure> measure = underTest.toMeasure(EMPTY_BATCH_MEASURE, SOME_STRING_METRIC); - assertThat(measure.isPresent()).isTrue(); + assertThat(measure).isPresent(); assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.NO_VALUE); } @@ -263,7 +263,7 @@ public class BatchMeasureToMeasureTest { Optional<Measure> measure = underTest.toMeasure(batchMeasure, SOME_STRING_METRIC); - assertThat(measure.isPresent()).isTrue(); + assertThat(measure).isPresent(); assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.STRING); assertThat(measure.get().getStringValue()).isEqualTo(SOME_DATA); assertThat(measure.get().getData()).isEqualTo(SOME_DATA); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/LiveMeasureDtoToMeasureTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/LiveMeasureDtoToMeasureTest.java index 7677858d438..a5b7b3677ca 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/LiveMeasureDtoToMeasureTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/LiveMeasureDtoToMeasureTest.java @@ -127,7 +127,7 @@ public class LiveMeasureDtoToMeasureTest { public void toMeasure_returns_no_value_if_dto_has_no_value_for_Int_Metric() { Optional<Measure> measure = underTest.toMeasure(EMPTY_MEASURE_DTO, SOME_INT_METRIC); - assertThat(measure.isPresent()).isTrue(); + assertThat(measure).isPresent(); assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.NO_VALUE); } @@ -135,16 +135,16 @@ public class LiveMeasureDtoToMeasureTest { public void toMeasure_returns_int_part_of_value_in_dto_for_Int_Metric() { Optional<Measure> measure = underTest.toMeasure(new LiveMeasureDto().setValue(1.5d), SOME_INT_METRIC); - assertThat(measure.isPresent()).isTrue(); + assertThat(measure).isPresent(); assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.INT); - assertThat(measure.get().getIntValue()).isEqualTo(1); + assertThat(measure.get().getIntValue()).isOne(); } @Test public void toMeasure_returns_no_value_if_dto_has_no_value_for_Long_Metric() { Optional<Measure> measure = underTest.toMeasure(EMPTY_MEASURE_DTO, SOME_LONG_METRIC); - assertThat(measure.isPresent()).isTrue(); + assertThat(measure).isPresent(); assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.NO_VALUE); } @@ -152,16 +152,16 @@ public class LiveMeasureDtoToMeasureTest { public void toMeasure_returns_long_part_of_value_in_dto_for_Long_Metric() { Optional<Measure> measure = underTest.toMeasure(new LiveMeasureDto().setValue(1.5d), SOME_LONG_METRIC); - assertThat(measure.isPresent()).isTrue(); + assertThat(measure).isPresent(); assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.LONG); - assertThat(measure.get().getLongValue()).isEqualTo(1); + assertThat(measure.get().getLongValue()).isOne(); } @Test public void toMeasure_returns_no_value_if_dto_has_no_value_for_Double_Metric() { Optional<Measure> measure = underTest.toMeasure(EMPTY_MEASURE_DTO, SOME_DOUBLE_METRIC); - assertThat(measure.isPresent()).isTrue(); + assertThat(measure).isPresent(); assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.NO_VALUE); } @@ -169,7 +169,7 @@ public class LiveMeasureDtoToMeasureTest { public void toMeasure_returns_no_value_if_dto_has_no_value_for_Boolean_metric() { Optional<Measure> measure = underTest.toMeasure(EMPTY_MEASURE_DTO, SOME_BOOLEAN_METRIC); - assertThat(measure.isPresent()).isTrue(); + assertThat(measure).isPresent(); assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.NO_VALUE); } @@ -177,7 +177,7 @@ public class LiveMeasureDtoToMeasureTest { public void toMeasure_returns_false_value_if_dto_has_invalid_value_for_Boolean_metric() { Optional<Measure> measure = underTest.toMeasure(new LiveMeasureDto().setValue(1.987d), SOME_BOOLEAN_METRIC); - assertThat(measure.isPresent()).isTrue(); + assertThat(measure).isPresent(); assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.BOOLEAN); assertThat(measure.get().getBooleanValue()).isFalse(); } @@ -186,7 +186,7 @@ public class LiveMeasureDtoToMeasureTest { public void toMeasure_returns_no_value_if_dto_has_no_value_for_String_Metric() { Optional<Measure> measure = underTest.toMeasure(EMPTY_MEASURE_DTO, SOME_STRING_METRIC); - assertThat(measure.isPresent()).isTrue(); + assertThat(measure).isPresent(); assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.NO_VALUE); } @@ -211,7 +211,7 @@ public class LiveMeasureDtoToMeasureTest { @Test @UseDataProvider("all_types_LiveMeasureDtos") public void toMeasure_creates_MeasureVariation_and_maps_the_right_one(LiveMeasureDto builder, Metric metric) { - assertThat(underTest.toMeasure(builder.setVariation(1d), metric).get().getVariation()).isEqualTo(1); + assertThat(underTest.toMeasure(builder.setVariation(1d), metric).get().getVariation()).isOne(); } @Test diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MapBasedRawMeasureRepositoryTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MapBasedRawMeasureRepositoryTest.java index ea292c95d5d..c5a30c2d06b 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MapBasedRawMeasureRepositoryTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MapBasedRawMeasureRepositoryTest.java @@ -141,7 +141,7 @@ public class MapBasedRawMeasureRepositoryTest { private static final List<Measure> MEASURES = ImmutableList.of( Measure.newMeasureBuilder().create(1), - Measure.newMeasureBuilder().create(1l), + Measure.newMeasureBuilder().create(1L), Measure.newMeasureBuilder().create(1d, 1), Measure.newMeasureBuilder().create(true), Measure.newMeasureBuilder().create(false), diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureDtoToMeasureTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureDtoToMeasureTest.java index 16d4aeb6f74..52c23ab24d1 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureDtoToMeasureTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureDtoToMeasureTest.java @@ -152,7 +152,7 @@ public class MeasureDtoToMeasureTest { public void toMeasure_returns_no_value_if_dto_has_no_value_for_Int_Metric() { Optional<Measure> measure = underTest.toMeasure(EMPTY_MEASURE_DTO, SOME_INT_METRIC); - assertThat(measure.isPresent()).isTrue(); + assertThat(measure).isPresent(); assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.NO_VALUE); } @@ -160,9 +160,9 @@ public class MeasureDtoToMeasureTest { public void toMeasure_returns_int_part_of_value_in_dto_for_Int_Metric() { Optional<Measure> measure = underTest.toMeasure(new MeasureDto().setValue(1.5d), SOME_INT_METRIC); - assertThat(measure.isPresent()).isTrue(); + assertThat(measure).isPresent(); assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.INT); - assertThat(measure.get().getIntValue()).isEqualTo(1); + assertThat(measure.get().getIntValue()).isOne(); } @Test @@ -171,7 +171,7 @@ public class MeasureDtoToMeasureTest { Optional<Measure> measure = underTest.toMeasure(measureDto, SOME_INT_METRIC); - assertThat(measure.isPresent()).isTrue(); + assertThat(measure).isPresent(); assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.INT); assertThat(measure.get().getIntValue()).isEqualTo(10); assertThat(measure.get().getData()).isEqualTo(SOME_DATA); @@ -183,7 +183,7 @@ public class MeasureDtoToMeasureTest { public void toMeasure_returns_no_value_if_dto_has_no_value_for_Long_Metric() { Optional<Measure> measure = underTest.toMeasure(EMPTY_MEASURE_DTO, SOME_LONG_METRIC); - assertThat(measure.isPresent()).isTrue(); + assertThat(measure).isPresent(); assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.NO_VALUE); } @@ -191,9 +191,9 @@ public class MeasureDtoToMeasureTest { public void toMeasure_returns_long_part_of_value_in_dto_for_Long_Metric() { Optional<Measure> measure = underTest.toMeasure(new MeasureDto().setValue(1.5d), SOME_LONG_METRIC); - assertThat(measure.isPresent()).isTrue(); + assertThat(measure).isPresent(); assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.LONG); - assertThat(measure.get().getLongValue()).isEqualTo(1); + assertThat(measure.get().getLongValue()).isOne(); } @Test @@ -202,7 +202,7 @@ public class MeasureDtoToMeasureTest { Optional<Measure> measure = underTest.toMeasure(measureDto, SOME_LONG_METRIC); - assertThat(measure.isPresent()).isTrue(); + assertThat(measure).isPresent(); assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.LONG); assertThat(measure.get().getLongValue()).isEqualTo(10); assertThat(measure.get().getData()).isEqualTo(SOME_DATA); @@ -214,7 +214,7 @@ public class MeasureDtoToMeasureTest { public void toMeasure_returns_no_value_if_dto_has_no_value_for_Double_Metric() { Optional<Measure> measure = underTest.toMeasure(EMPTY_MEASURE_DTO, SOME_DOUBLE_METRIC); - assertThat(measure.isPresent()).isTrue(); + assertThat(measure).isPresent(); assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.NO_VALUE); } @@ -224,7 +224,7 @@ public class MeasureDtoToMeasureTest { Optional<Measure> measure = underTest.toMeasure(measureDto, SOME_DOUBLE_METRIC); - assertThat(measure.isPresent()).isTrue(); + assertThat(measure).isPresent(); assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.DOUBLE); assertThat(measure.get().getDoubleValue()).isEqualTo(10.6395d); assertThat(measure.get().getData()).isEqualTo(SOME_DATA); @@ -236,7 +236,7 @@ public class MeasureDtoToMeasureTest { public void toMeasure_returns_no_value_if_dto_has_no_value_for_Boolean_metric() { Optional<Measure> measure = underTest.toMeasure(EMPTY_MEASURE_DTO, SOME_BOOLEAN_METRIC); - assertThat(measure.isPresent()).isTrue(); + assertThat(measure).isPresent(); assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.NO_VALUE); } @@ -244,7 +244,7 @@ public class MeasureDtoToMeasureTest { public void toMeasure_returns_false_value_if_dto_has_invalid_value_for_Boolean_metric() { Optional<Measure> measure = underTest.toMeasure(new MeasureDto().setValue(1.987d), SOME_BOOLEAN_METRIC); - assertThat(measure.isPresent()).isTrue(); + assertThat(measure).isPresent(); assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.BOOLEAN); assertThat(measure.get().getBooleanValue()).isFalse(); } @@ -255,7 +255,7 @@ public class MeasureDtoToMeasureTest { Optional<Measure> measure = underTest.toMeasure(measureDto, SOME_BOOLEAN_METRIC); - assertThat(measure.isPresent()).isTrue(); + assertThat(measure).isPresent(); assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.BOOLEAN); assertThat(measure.get().getBooleanValue()).isTrue(); assertThat(measure.get().getData()).isEqualTo(SOME_DATA); @@ -267,7 +267,7 @@ public class MeasureDtoToMeasureTest { public void toMeasure_returns_no_value_if_dto_has_no_value_for_String_Metric() { Optional<Measure> measure = underTest.toMeasure(EMPTY_MEASURE_DTO, SOME_STRING_METRIC); - assertThat(measure.isPresent()).isTrue(); + assertThat(measure).isPresent(); assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.NO_VALUE); } @@ -277,7 +277,7 @@ public class MeasureDtoToMeasureTest { Optional<Measure> measure = underTest.toMeasure(measureDto, SOME_STRING_METRIC); - assertThat(measure.isPresent()).isTrue(); + assertThat(measure).isPresent(); assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.STRING); assertThat(measure.get().getStringValue()).isEqualTo(SOME_DATA); assertThat(measure.get().getData()).isEqualTo(SOME_DATA); @@ -306,7 +306,7 @@ public class MeasureDtoToMeasureTest { @Test @UseDataProvider("all_types_MeasureDtos") public void toMeasure_creates_MeasureVariation_and_maps_the_right_one(MeasureDto builder, Metric metric) { - assertThat(underTest.toMeasure(builder.setVariation(1d), metric).get().getVariation()).isEqualTo(1); + assertThat(underTest.toMeasure(builder.setVariation(1d), metric).get().getVariation()).isOne(); } @Test diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepositoryImplTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepositoryImplTest.java index aa3e4d6db16..c75f9cf908d 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepositoryImplTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepositoryImplTest.java @@ -215,7 +215,7 @@ public class MeasureRepositoryImplTest { private static final List<Measure> MEASURES = ImmutableList.of( Measure.newMeasureBuilder().create(1), - Measure.newMeasureBuilder().create(1l), + Measure.newMeasureBuilder().create(1L), Measure.newMeasureBuilder().create(1d, 1), Measure.newMeasureBuilder().create(true), Measure.newMeasureBuilder().create(false), @@ -272,7 +272,7 @@ public class MeasureRepositoryImplTest { } private Measure getSomeMeasureByValueType(final Metric.MetricType metricType) { - return from(MEASURES).filter(input -> input.getValueType() == metricType.getValueType()).first().get(); + return MEASURES.stream().filter(input -> input.getValueType() == metricType.getValueType()).findFirst().get(); } @Test diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureTest.java index 597e4ec6f34..7a554e68d4b 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureTest.java @@ -37,7 +37,7 @@ import static org.sonar.ce.task.projectanalysis.measure.Measure.newMeasureBuilde public class MeasureTest { private static final Measure INT_MEASURE = newMeasureBuilder().create(1); - private static final Measure LONG_MEASURE = newMeasureBuilder().create(1l); + private static final Measure LONG_MEASURE = newMeasureBuilder().create(1L); private static final Measure DOUBLE_MEASURE = newMeasureBuilder().create(1d, 1); private static final Measure STRING_MEASURE = newMeasureBuilder().create("some_sT ring"); private static final Measure TRUE_MEASURE = newMeasureBuilder().create(true); @@ -132,7 +132,7 @@ public class MeasureTest { @Test public void getIntValue_returns_value_for_INT_value_type() { - assertThat(INT_MEASURE.getIntValue()).isEqualTo(1); + assertThat(INT_MEASURE.getIntValue()).isOne(); } @Test @@ -144,7 +144,7 @@ public class MeasureTest { @Test public void getLongValue_returns_value_for_LONG_value_type() { - assertThat(LONG_MEASURE.getLongValue()).isEqualTo(1); + assertThat(LONG_MEASURE.getLongValue()).isOne(); } @Test diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/QualityGateStatusTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/QualityGateStatusTest.java index 45418c0228c..7530d4ae1d8 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/QualityGateStatusTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/QualityGateStatusTest.java @@ -71,12 +71,12 @@ public class QualityGateStatusTest { assertThat(status).isEqualTo(new QualityGateStatus(level, null)); assertThat(status).isNotEqualTo(new QualityGateStatus(level, "bar")); assertThat(status).isNotEqualTo(new QualityGateStatus(level, "")); - assertThat(status).isNotEqualTo(null); + assertThat(status).isNotNull(); } } @Test public void verify_toString() { - assertThat(new QualityGateStatus(Measure.Level.OK, "foo").toString()).isEqualTo("QualityGateStatus{status=OK, text=foo}"); + assertThat(new QualityGateStatus(Measure.Level.OK, "foo")).hasToString("QualityGateStatus{status=OK, text=foo}"); } } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/period/PeriodTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/period/PeriodTest.java index 4881ea3cfda..cf31b7c8be3 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/period/PeriodTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/period/PeriodTest.java @@ -49,13 +49,13 @@ public class PeriodTest { public void equals_is_done_on_all_fields() { Period period = new Period(NewCodePeriodType.NUMBER_OF_DAYS.name(), "2.3", 1420034400000L); - assertThat(period).isEqualTo(new Period(NewCodePeriodType.NUMBER_OF_DAYS.name(), "2.3", 1420034400000L)); - - assertThat(period).isNotEqualTo(null); - assertThat(period).isNotEqualTo("sdsd"); - assertThat(period).isNotEqualTo(new Period(NewCodePeriodType.PREVIOUS_VERSION.name(), "2.3", 1420034400000L)); - assertThat(period).isNotEqualTo(new Period(NewCodePeriodType.NUMBER_OF_DAYS.name(), "2.4", 1420034400000L)); - assertThat(period).isNotEqualTo(new Period(NewCodePeriodType.NUMBER_OF_DAYS.name(), "2.3", 1420034410000L)); + assertThat(period) + .isEqualTo(new Period(NewCodePeriodType.NUMBER_OF_DAYS.name(), "2.3", 1420034400000L)) + .isNotNull() + .isNotEqualTo("sdsd") + .isNotEqualTo(new Period(NewCodePeriodType.PREVIOUS_VERSION.name(), "2.3", 1420034400000L)) + .isNotEqualTo(new Period(NewCodePeriodType.NUMBER_OF_DAYS.name(), "2.4", 1420034400000L)) + .isNotEqualTo(new Period(NewCodePeriodType.NUMBER_OF_DAYS.name(), "2.3", 1420034410000L)); } } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/ConditionEvaluatorTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/ConditionEvaluatorTest.java index a52bbe14a4d..eb63b60b4c7 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/ConditionEvaluatorTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/ConditionEvaluatorTest.java @@ -109,7 +109,7 @@ public class ConditionEvaluatorTest { @Test public void getLevel_throws_IEA_if_error_threshold_is_not_parsable_long() { Metric metric = createMetric(WORK_DUR); - Measure measure = newMeasureBuilder().create(60l, null); + Measure measure = newMeasureBuilder().create(60L, null); assertThatThrownBy(() -> underTest.evaluate(createCondition(metric, LESS_THAN, "polop"), measure)) .isInstanceOf(IllegalArgumentException.class) diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/ConditionStatusTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/ConditionStatusTest.java index 15e9f629396..4ed62f5bc6a 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/ConditionStatusTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/ConditionStatusTest.java @@ -68,8 +68,8 @@ public class ConditionStatusTest { @Test public void verify_toString() { - assertThat(ConditionStatus.create(OK, SOME_VALUE).toString()).isEqualTo("ConditionStatus{status=OK, value='value'}"); - assertThat(ConditionStatus.NO_VALUE_STATUS.toString()).isEqualTo("ConditionStatus{status=NO_VALUE, value='null'}"); + assertThat(ConditionStatus.create(OK, SOME_VALUE)).hasToString("ConditionStatus{status=OK, value='value'}"); + assertThat(ConditionStatus.NO_VALUE_STATUS).hasToString("ConditionStatus{status=NO_VALUE, value='null'}"); } @Test diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitymodel/NewMaintainabilityMeasuresVisitorTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitymodel/NewMaintainabilityMeasuresVisitorTest.java index 4606dca4e31..0da3c3a858e 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitymodel/NewMaintainabilityMeasuresVisitorTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitymodel/NewMaintainabilityMeasuresVisitorTest.java @@ -69,7 +69,7 @@ public class NewMaintainabilityMeasuresVisitorTest { private static final double[] RATING_GRID = new double[] {0.1, 0.2, 0.5, 1}; private static final String LANGUAGE_1_KEY = "language 1 key"; - private static final long LANGUAGE_1_DEV_COST = 30l; + private static final long LANGUAGE_1_DEV_COST = 30L; private static final int ROOT_REF = 1; private static final int LANGUAGE_1_FILE_REF = 11111; private static final Offset<Double> VARIATION_COMPARISON_OFFSET = Offset.offset(0.01); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitymodel/NewReliabilityAndSecurityRatingMeasuresVisitorTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitymodel/NewReliabilityAndSecurityRatingMeasuresVisitorTest.java index ffdb2400e3e..dc715492f20 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitymodel/NewReliabilityAndSecurityRatingMeasuresVisitorTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitymodel/NewReliabilityAndSecurityRatingMeasuresVisitorTest.java @@ -72,8 +72,8 @@ import static org.sonar.server.measure.Rating.E; public class NewReliabilityAndSecurityRatingMeasuresVisitorTest { - private static final long LEAK_PERIOD_SNAPSHOT_IN_MILLISEC = 12323l; - private static final Date DEFAULT_ISSUE_CREATION_DATE = new Date(1000l); + private static final long LEAK_PERIOD_SNAPSHOT_IN_MILLISEC = 12323L; + private static final Date DEFAULT_ISSUE_CREATION_DATE = new Date(1000L); private static final Date BEFORE_LEAK_PERIOD_DATE = new Date(LEAK_PERIOD_SNAPSHOT_IN_MILLISEC - 5000L); private static final Date AFTER_LEAK_PERIOD_DATE = new Date(LEAK_PERIOD_SNAPSHOT_IN_MILLISEC + 5000L); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitymodel/NewSecurityReviewMeasuresVisitorTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitymodel/NewSecurityReviewMeasuresVisitorTest.java index 70e8c133d2e..7f873c6ebf8 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitymodel/NewSecurityReviewMeasuresVisitorTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitymodel/NewSecurityReviewMeasuresVisitorTest.java @@ -74,8 +74,8 @@ public class NewSecurityReviewMeasuresVisitorTest { private static final Offset<Double> VARIATION_COMPARISON_OFFSET = Offset.offset(0.01); - private static final long LEAK_PERIOD_SNAPSHOT_IN_MILLISEC = 12323l; - private static final Date DEFAULT_CREATION_DATE = new Date(1000l); + private static final long LEAK_PERIOD_SNAPSHOT_IN_MILLISEC = 12323L; + private static final Date DEFAULT_CREATION_DATE = new Date(1000L); private static final Date BEFORE_LEAK_PERIOD_DATE = new Date(LEAK_PERIOD_SNAPSHOT_IN_MILLISEC - 5000L); private static final Date AFTER_LEAK_PERIOD_DATE = new Date(LEAK_PERIOD_SNAPSHOT_IN_MILLISEC + 5000L); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitymodel/ReliabilityAndSecurityRatingMeasuresVisitorTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitymodel/ReliabilityAndSecurityRatingMeasuresVisitorTest.java index d2bc39e2ddb..6a089260fcb 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitymodel/ReliabilityAndSecurityRatingMeasuresVisitorTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitymodel/ReliabilityAndSecurityRatingMeasuresVisitorTest.java @@ -251,7 +251,7 @@ public class ReliabilityAndSecurityRatingMeasuresVisitorTest { .setKey(Uuids.create()) .setSeverity(severity) .setType(type) - .setCreationDate(new Date(1000l)); + .setCreationDate(new Date(1000L)); } } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualityprofile/ActiveRulesHolderImplTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualityprofile/ActiveRulesHolderImplTest.java index 6c54e24c888..3ed89d895c8 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualityprofile/ActiveRulesHolderImplTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualityprofile/ActiveRulesHolderImplTest.java @@ -45,7 +45,7 @@ public class ActiveRulesHolderImplTest { public void get_inactive_rule() { underTest.set(Collections.emptyList()); Optional<ActiveRule> activeRule = underTest.get(RULE_KEY); - assertThat(activeRule.isPresent()).isFalse(); + assertThat(activeRule).isEmpty(); } @Test @@ -53,7 +53,7 @@ public class ActiveRulesHolderImplTest { underTest.set(asList(new ActiveRule(RULE_KEY, Severity.BLOCKER, Collections.emptyMap(), SOME_DATE, PLUGIN_KEY, QP_KEY))); Optional<ActiveRule> activeRule = underTest.get(RULE_KEY); - assertThat(activeRule.isPresent()).isTrue(); + assertThat(activeRule).isPresent(); assertThat(activeRule.get().getRuleKey()).isEqualTo(RULE_KEY); assertThat(activeRule.get().getSeverity()).isEqualTo(Severity.BLOCKER); } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/scm/ChangesetTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/scm/ChangesetTest.java index 73b1c158b5c..536cafafc84 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/scm/ChangesetTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/scm/ChangesetTest.java @@ -26,7 +26,6 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; public class ChangesetTest { - @Test public void create_changeset() { Changeset underTest = Changeset.newChangesetBuilder() @@ -78,7 +77,7 @@ public class ChangesetTest { .setRevision("rev-1") .build(); - assertThat(underTest.toString()).isEqualTo("Changeset{revision='rev-1', author='john', date=123456789}"); + assertThat(underTest).hasToString("Changeset{revision='rev-1', author='john', date=123456789}"); } @Test @@ -103,14 +102,15 @@ public class ChangesetTest { .setRevision("rev-2") .build(); - assertThat(changeset).isEqualTo(changeset); - assertThat(changeset).isEqualTo(sameChangeset); - assertThat(changeset).isNotEqualTo(anotherChangesetWithSameRevision); - assertThat(changeset).isNotEqualTo(anotherChangeset); - - assertThat(changeset.hashCode()).isEqualTo(changeset.hashCode()); - assertThat(changeset.hashCode()).isEqualTo(sameChangeset.hashCode()); - assertThat(changeset.hashCode()).isNotEqualTo(anotherChangesetWithSameRevision.hashCode()); - assertThat(changeset.hashCode()).isNotEqualTo(anotherChangeset.hashCode()); + assertThat(changeset) + .isEqualTo(changeset) + .isEqualTo(sameChangeset) + .isNotEqualTo(anotherChangesetWithSameRevision) + .isNotEqualTo(anotherChangeset) + .hasSameHashCodeAs(changeset) + .hasSameHashCodeAs(sameChangeset); + assertThat(changeset.hashCode()) + .isNotEqualTo(anotherChangesetWithSameRevision.hashCode()) + .isNotEqualTo(anotherChangeset.hashCode()); } } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/scm/ScmInfoImplTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/scm/ScmInfoImplTest.java index 8c471771f98..f67d986227c 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/scm/ScmInfoImplTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/scm/ScmInfoImplTest.java @@ -102,7 +102,7 @@ public class ScmInfoImplTest { public void test_to_string() { ScmInfo scmInfo = createScmInfoWithTwoChangestOnFourLines(); - assertThat(scmInfo.toString()).isEqualTo("ScmInfoImpl{" + + assertThat(scmInfo).hasToString("ScmInfoImpl{" + "latestChangeset=Changeset{revision='rev-2', author='henry', date=1234567810}, " + "lineChangesets={" + "1=Changeset{revision='rev-1', author='john', date=123456789}, " + diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/source/LastCommitVisitorTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/source/LastCommitVisitorTest.java index e9722e8598e..89c779f098b 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/source/LastCommitVisitorTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/source/LastCommitVisitorTest.java @@ -218,12 +218,12 @@ public class LastCommitVisitorTest { underTest.visit(file); Optional<Measure> measure = measureRepository.getAddedRawMeasure(FILE_1_REF, LAST_COMMIT_DATE_KEY); - assertThat(measure.isPresent()).isFalse(); + assertThat(measure).isEmpty(); } private void assertDate(int componentRef, long expectedDate) { Optional<Measure> measure = measureRepository.getAddedRawMeasure(componentRef, LAST_COMMIT_DATE_KEY); - assertThat(measure.isPresent()).isTrue(); + assertThat(measure).isPresent(); assertThat(measure.get().getLongValue()).isEqualTo(expectedDate); } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/source/PersistFileSourcesStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/source/PersistFileSourcesStepTest.java index 5e03cfd893c..57bc65474b6 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/source/PersistFileSourcesStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/source/PersistFileSourcesStepTest.java @@ -104,7 +104,7 @@ public class PersistFileSourcesStepTest extends BaseStepTest { underTest.execute(new TestComputationStepContext()); - assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1); + assertThat(dbTester.countRowsOfTable("file_sources")).isOne(); FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectByFileUuid(session, FILE1_UUID); assertThat(fileSourceDto.getProjectUuid()).isEqualTo(PROJECT_UUID); assertThat(fileSourceDto.getFileUuid()).isEqualTo(FILE1_UUID); @@ -117,7 +117,7 @@ public class PersistFileSourcesStepTest extends BaseStepTest { DbFileSources.Data data = fileSourceDto.getSourceData(); assertThat(data.getLinesCount()).isEqualTo(2); - assertThat(data.getLines(0).getLine()).isEqualTo(1); + assertThat(data.getLines(0).getLine()).isOne(); assertThat(data.getLines(0).getSource()).isEqualTo("line1"); assertThat(data.getLines(1).getLine()).isEqualTo(2); assertThat(data.getLines(1).getSource()).isEqualTo("line2"); @@ -132,7 +132,7 @@ public class PersistFileSourcesStepTest extends BaseStepTest { underTest.execute(new TestComputationStepContext()); - assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1); + assertThat(dbTester.countRowsOfTable("file_sources")).isOne(); FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectByFileUuid(session, FILE1_UUID); assertThat(fileSourceDto.getLineHashes()).containsExactly("137f72c3708c6bd0de00a0e5a69c699b", "e6251bcf1a7dc3ba5e7933e325bbe605"); assertThat(fileSourceDto.getSrcHash()).isEqualTo("ee5a58024a155466b43bc559d953e018"); @@ -153,7 +153,7 @@ public class PersistFileSourcesStepTest extends BaseStepTest { underTest.execute(new TestComputationStepContext()); - assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1); + assertThat(dbTester.countRowsOfTable("file_sources")).isOne(); FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectByFileUuid(session, FILE1_UUID); assertThat(fileSourceDto.getSourceData()).isEqualTo(dbData); verify(fileSourceDataWarnings).commitWarnings(); @@ -176,7 +176,7 @@ public class PersistFileSourcesStepTest extends BaseStepTest { underTest.execute(new TestComputationStepContext()); - assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1); + assertThat(dbTester.countRowsOfTable("file_sources")).isOne(); FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectByFileUuid(session, FILE1_UUID); assertThat(fileSourceDto.getSourceData()).isEqualTo(dbData); assertThat(fileSourceDto.getRevision()).isNull(); @@ -201,7 +201,7 @@ public class PersistFileSourcesStepTest extends BaseStepTest { underTest.execute(new TestComputationStepContext()); - assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1); + assertThat(dbTester.countRowsOfTable("file_sources")).isOne(); FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectByFileUuid(session, FILE1_UUID); DbFileSources.Data data = fileSourceDto.getSourceData(); @@ -233,7 +233,7 @@ public class PersistFileSourcesStepTest extends BaseStepTest { underTest.execute(new TestComputationStepContext()); - assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1); + assertThat(dbTester.countRowsOfTable("file_sources")).isOne(); FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectByFileUuid(session, FILE1_UUID); DbFileSources.Data data = fileSourceDto.getSourceData(); assertThat(data).isEqualTo(dbData); @@ -257,7 +257,7 @@ public class PersistFileSourcesStepTest extends BaseStepTest { underTest.execute(new TestComputationStepContext()); - assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1); + assertThat(dbTester.countRowsOfTable("file_sources")).isOne(); FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectByFileUuid(session, FILE1_UUID); assertThat(fileSourceDto.getSourceData()).isEqualTo(dbData); verify(fileSourceDataWarnings).commitWarnings(); @@ -274,7 +274,7 @@ public class PersistFileSourcesStepTest extends BaseStepTest { underTest.execute(new TestComputationStepContext()); - assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1); + assertThat(dbTester.countRowsOfTable("file_sources")).isOne(); FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectByFileUuid(session, FILE1_UUID); assertThat(fileSourceDto.getSourceData()).isEqualTo(dbData); verify(fileSourceDataWarnings).commitWarnings(); @@ -313,7 +313,7 @@ public class PersistFileSourcesStepTest extends BaseStepTest { underTest.execute(new TestComputationStepContext()); - assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1); + assertThat(dbTester.countRowsOfTable("file_sources")).isOne(); FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectByFileUuid(session, FILE1_UUID); assertThat(fileSourceDto.getSrcHash()).isEqualTo("sourceHash"); assertThat(fileSourceDto.getLineHashes()).isEqualTo(Collections.singletonList("lineHash")); @@ -359,7 +359,7 @@ public class PersistFileSourcesStepTest extends BaseStepTest { underTest.execute(new TestComputationStepContext()); - assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1); + assertThat(dbTester.countRowsOfTable("file_sources")).isOne(); FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectByFileUuid(session, FILE1_UUID); assertThat(fileSourceDto.getCreatedAt()).isEqualTo(past); assertThat(fileSourceDto.getUpdatedAt()).isEqualTo(NOW); @@ -377,7 +377,7 @@ public class PersistFileSourcesStepTest extends BaseStepTest { underTest.execute(new TestComputationStepContext()); - assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1); + assertThat(dbTester.countRowsOfTable("file_sources")).isOne(); FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectByFileUuid(session, FILE1_UUID); assertThat(fileSourceDto.getCreatedAt()).isEqualTo(PAST); assertThat(fileSourceDto.getUpdatedAt()).isEqualTo(NOW); @@ -402,7 +402,7 @@ public class PersistFileSourcesStepTest extends BaseStepTest { underTest.execute(new TestComputationStepContext()); - assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1); + assertThat(dbTester.countRowsOfTable("file_sources")).isOne(); FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectByFileUuid(session, FILE1_UUID); assertThat(fileSourceDto.getCreatedAt()).isEqualTo(PAST); assertThat(fileSourceDto.getUpdatedAt()).isEqualTo(NOW); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/source/ReportIteratorTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/source/ReportIteratorTest.java index 9a251227ca0..0e456ac0246 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/source/ReportIteratorTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/source/ReportIteratorTest.java @@ -65,13 +65,13 @@ public class ReportIteratorTest { @Test public void read_report() { underTest = new ReportIterator<>(file, ScannerReport.LineCoverage.parser()); - assertThat(underTest.next().getLine()).isEqualTo(1); + assertThat(underTest.next().getLine()).isOne(); } @Test public void do_not_fail_when_calling_has_next_with_iterator_already_closed() { underTest = new ReportIterator<>(file, ScannerReport.LineCoverage.parser()); - assertThat(underTest.next().getLine()).isEqualTo(1); + assertThat(underTest.next().getLine()).isOne(); assertThat(underTest.hasNext()).isFalse(); underTest.close(); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/source/SignificantCodeRepositoryTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/source/SignificantCodeRepositoryTest.java index 7257dbc4103..d082626fc96 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/source/SignificantCodeRepositoryTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/source/SignificantCodeRepositoryTest.java @@ -81,7 +81,7 @@ public class SignificantCodeRepositoryTest { assertThat(underTest.getRangesPerLine(component)).isNotEmpty(); LineRange[] lines = underTest.getRangesPerLine(component).get(); assertThat(lines).hasSize(1); - assertThat(lines[0].startOffset()).isEqualTo(1); + assertThat(lines[0].startOffset()).isOne(); assertThat(lines[0].endOffset()).isEqualTo(2); } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/source/linereader/CoverageLineReaderTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/source/linereader/CoverageLineReaderTest.java index cbb22c20884..897b7b1bc8b 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/source/linereader/CoverageLineReaderTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/source/linereader/CoverageLineReaderTest.java @@ -41,7 +41,7 @@ public class CoverageLineReaderTest { DbFileSources.Line.Builder lineBuilder = DbFileSources.Data.newBuilder().addLinesBuilder().setLine(1); assertThat(computeCoverageLine.read(lineBuilder)).isEmpty(); - assertThat(lineBuilder.getLineHits()).isEqualTo(1); + assertThat(lineBuilder.getLineHits()).isOne(); assertThat(lineBuilder.getConditions()).isEqualTo(10); assertThat(lineBuilder.getCoveredConditions()).isEqualTo(2); } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ExecuteVisitorsStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ExecuteVisitorsStepTest.java index 17645e5ff51..3a245d693a8 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ExecuteVisitorsStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ExecuteVisitorsStepTest.java @@ -108,8 +108,8 @@ public class ExecuteVisitorsStepTest { underTest.execute(new TestComputationStepContext()); - assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, TEST_METRIC_KEY).get().getIntValue()).isEqualTo(1); - assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, TEST_METRIC_KEY).get().getIntValue()).isEqualTo(1); + assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, TEST_METRIC_KEY).get().getIntValue()).isOne(); + assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, TEST_METRIC_KEY).get().getIntValue()).isOne(); assertThat(measureRepository.getAddedRawMeasure(DIRECTORY_REF, TEST_METRIC_KEY).get().getIntValue()).isEqualTo(2); assertThat(measureRepository.getAddedRawMeasure(ROOT_REF, TEST_METRIC_KEY).get().getIntValue()).isEqualTo(2); } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStepTest.java index 816b8d9da9e..782a83ef415 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStepTest.java @@ -88,7 +88,7 @@ public class LoadReportAnalysisMetadataHolderStepTest { underTest.execute(new TestComputationStepContext()); - assertThat(analysisMetadataHolder.getRootComponentRef()).isEqualTo(1); + assertThat(analysisMetadataHolder.getRootComponentRef()).isOne(); } @Test @@ -140,7 +140,7 @@ public class LoadReportAnalysisMetadataHolderStepTest { underTest.execute(new TestComputationStepContext()); - assertThat(analysisMetadataHolder.isCrossProjectDuplicationEnabled()).isEqualTo(true); + assertThat(analysisMetadataHolder.isCrossProjectDuplicationEnabled()).isTrue(); } @Test @@ -152,7 +152,7 @@ public class LoadReportAnalysisMetadataHolderStepTest { underTest.execute(new TestComputationStepContext()); - assertThat(analysisMetadataHolder.isCrossProjectDuplicationEnabled()).isEqualTo(false); + assertThat(analysisMetadataHolder.isCrossProjectDuplicationEnabled()).isFalse(); } @Test @@ -163,7 +163,7 @@ public class LoadReportAnalysisMetadataHolderStepTest { underTest.execute(new TestComputationStepContext()); - assertThat(analysisMetadataHolder.isCrossProjectDuplicationEnabled()).isEqualTo(false); + assertThat(analysisMetadataHolder.isCrossProjectDuplicationEnabled()).isFalse(); } @Test diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistAdHocRulesStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistAdHocRulesStepTest.java index d0e1c0f8e72..9b0cb46c087 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistAdHocRulesStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistAdHocRulesStepTest.java @@ -90,7 +90,7 @@ public class PersistAdHocRulesStepTest extends BaseStepTest { assertThat(reloaded.getSeverity()).isNull(); assertThat(reloaded.getName()).isEqualTo("eslint:no-cond-assign"); - assertThat(es.countDocuments(RuleIndexDefinition.TYPE_RULE)).isEqualTo(1L); + assertThat(es.countDocuments(RuleIndexDefinition.TYPE_RULE)).isOne(); assertThat(es.getDocuments(RuleIndexDefinition.TYPE_RULE).iterator().next().getId()).isEqualTo(reloaded.getUuid()); } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistCrossProjectDuplicationIndexStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistCrossProjectDuplicationIndexStepTest.java index d6c0cfe610e..65b2539c083 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistCrossProjectDuplicationIndexStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistCrossProjectDuplicationIndexStepTest.java @@ -100,12 +100,13 @@ public class PersistCrossProjectDuplicationIndexStepTest { underTest.execute(context); Map<String, Object> dto = dbTester.selectFirst("select HASH, START_LINE, END_LINE, INDEX_IN_FILE, COMPONENT_UUID, ANALYSIS_UUID from duplications_index"); - assertThat(dto.get("HASH")).isEqualTo(CPD_TEXT_BLOCK.getHash()); - assertThat(dto.get("START_LINE")).isEqualTo(30L); - assertThat(dto.get("END_LINE")).isEqualTo(45L); - assertThat(dto.get("INDEX_IN_FILE")).isEqualTo(0L); - assertThat(dto.get("COMPONENT_UUID")).isEqualTo(FILE_1.getUuid()); - assertThat(dto.get("ANALYSIS_UUID")).isEqualTo(ANALYSIS_UUID); + assertThat(dto) + .containsEntry("HASH", CPD_TEXT_BLOCK.getHash()) + .containsEntry("START_LINE", 30L) + .containsEntry("END_LINE", 45L) + .containsEntry("INDEX_IN_FILE", 0L) + .containsEntry("COMPONENT_UUID", FILE_1.getUuid()) + .containsEntry("ANALYSIS_UUID", ANALYSIS_UUID); context.getStatistics().assertValue("inserts", 1); } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistEventsStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistEventsStepTest.java index 3e67048e03a..f71360533fc 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistEventsStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistEventsStepTest.java @@ -125,7 +125,7 @@ public class PersistEventsStepTest extends BaseStepTest { underTest.execute(new TestComputationStepContext()); - assertThat(dbTester.countRowsOfTable(dbTester.getSession(), "events")).isEqualTo(1); + assertThat(dbTester.countRowsOfTable(dbTester.getSession(), "events")).isOne(); List<EventDto> eventDtos = dbTester.getDbClient().eventDao().selectByComponentUuid(dbTester.getSession(), ROOT.getUuid()); assertThat(eventDtos).hasSize(1); EventDto eventDto = eventDtos.iterator().next(); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStepTest.java index 7089c5648a7..61e067b1721 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStepTest.java @@ -213,14 +213,14 @@ public class PersistLiveMeasuresStepTest extends BaseStepTest { Optional<LiveMeasureDto> persisted = dbClient.liveMeasureDao().selectMeasure(db.getSession(), template.getComponentUuid(), metricRepository.getByUuid(template.getMetricUuid()).getKey()); assertThat(persisted).isPresent(); - assertThat(persisted.get().getValue()).isEqualTo((double) expectedValue); + assertThat(persisted.get().getValue()).isEqualTo(expectedValue); } private void assertThatMeasureHasValue(String componentUuid, Metric metric, int expectedValue) { Optional<LiveMeasureDto> persisted = dbClient.liveMeasureDao().selectMeasure(db.getSession(), componentUuid, metric.getKey()); assertThat(persisted).isPresent(); - assertThat(persisted.get().getValue()).isEqualTo((double) expectedValue); + assertThat(persisted.get().getValue()).isEqualTo(expectedValue); } private void assertThatMeasureDoesNotExist(LiveMeasureDto template) { diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistMeasuresStepTest.java index e33322b17b5..5fb838b36bf 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistMeasuresStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistMeasuresStepTest.java @@ -113,7 +113,7 @@ public class PersistMeasuresStepTest extends BaseStepTest { TestComputationStepContext context = execute(); // project and dir measures are persisted, but not file measures - assertThat(db.countRowsOfTable("project_measures")).isEqualTo(1); + assertThat(db.countRowsOfTable("project_measures")).isOne(); assertThat(selectMeasure("project-uuid", STRING_METRIC).get().getData()).isEqualTo("project-value"); assertThatMeasuresAreNotPersisted("dir-uuid"); assertThatMeasuresAreNotPersisted("file-uuid"); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistProjectLinksStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistProjectLinksStepTest.java index 70ed0e7fa23..e22b5982b47 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistProjectLinksStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistProjectLinksStepTest.java @@ -230,7 +230,7 @@ public class PersistProjectLinksStepTest extends BaseStepTest { underTest.execute(new TestComputationStepContext()); - assertThat(db.countRowsOfTable("project_links")).isEqualTo(1); + assertThat(db.countRowsOfTable("project_links")).isOne(); } @Test diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistAnalysisStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistAnalysisStepTest.java index c1ea5bb3a14..81a73cebc00 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistAnalysisStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistAnalysisStepTest.java @@ -118,7 +118,7 @@ public class ReportPersistAnalysisStepTest extends BaseStepTest { underTest.execute(new TestComputationStepContext()); - assertThat(dbTester.countRowsOfTable("snapshots")).isEqualTo(1); + assertThat(dbTester.countRowsOfTable("snapshots")).isOne(); SnapshotDto projectSnapshot = getUnprocessedSnapshot(projectDto.uuid()); assertThat(projectSnapshot.getUuid()).isEqualTo(ANALYSIS_UUID); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistAnalysisStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistAnalysisStepTest.java index ec84841e0ec..cc65464e2a8 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistAnalysisStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistAnalysisStepTest.java @@ -102,7 +102,7 @@ public class ViewsPersistAnalysisStepTest extends BaseStepTest { underTest.execute(new TestComputationStepContext()); - assertThat(dbTester.countRowsOfTable("snapshots")).isEqualTo(1); + assertThat(dbTester.countRowsOfTable("snapshots")).isOne(); SnapshotDto viewSnapshot = getUnprocessedSnapshot(viewDto.uuid()); assertThat(viewSnapshot.getUuid()).isEqualTo(ANALYSIS_UUID); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/ProjectExportComputationStepsTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/ProjectExportComputationStepsTest.java index 06c7fb916a7..201bd7224cb 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/ProjectExportComputationStepsTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/ProjectExportComputationStepsTest.java @@ -39,7 +39,7 @@ public class ProjectExportComputationStepsTest { @Test public void count_step_classes() { - assertThat(copyOf(underTest.orderedStepClasses()).size()).isEqualTo(20); + assertThat(copyOf(underTest.orderedStepClasses())).hasSize(20); } @Test diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/analysis/ExportAnalysesStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/analysis/ExportAnalysesStepTest.java index 3325590918a..e4777f89999 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/analysis/ExportAnalysesStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/analysis/ExportAnalysesStepTest.java @@ -213,7 +213,7 @@ public class ExportAnalysesStepTest { private static void assertAnalysis(ProjectDump.Analysis analysis, ComponentDto component, SnapshotDto dto) { assertThat(analysis.getUuid()).isEqualTo(dto.getUuid()); - assertThat(analysis.getComponentRef()).isEqualTo(1); + assertThat(analysis.getComponentRef()).isOne(); assertThat(analysis.getDate()).isEqualTo(dto.getCreatedAt()); assertThat(analysis.getProjectVersion()).isEqualTo(defaultString(dto.getProjectVersion())); assertThat(analysis.getBuildString()).isEqualTo(defaultString(dto.getBuildString())); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportEventsStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportEventsStepTest.java index a0ebffa634e..a04bc51ee5d 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportEventsStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportEventsStepTest.java @@ -136,7 +136,7 @@ public class ExportEventsStepTest { assertThat(event.getDescription()).isEqualTo("desc"); assertThat(event.getDate()).isEqualTo(IN_THE_PAST); assertThat(event.getAnalysisUuid()).isEqualTo(snapshot.getUuid()); - assertThat(event.getComponentRef()).isEqualTo(1); + assertThat(event.getComponentRef()).isOne(); } @Test diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportMetricsStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportMetricsStepTest.java index 9b8aad95849..7551a8514d9 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportMetricsStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportMetricsStepTest.java @@ -19,9 +19,9 @@ */ package org.sonar.ce.task.projectexport.steps; -import com.google.common.base.Predicate; import com.sonarsource.governance.projectdump.protobuf.ProjectDump; import java.util.List; +import java.util.function.Predicate; import javax.annotation.Nonnull; import org.junit.Before; import org.junit.Rule; @@ -33,7 +33,6 @@ import org.sonar.ce.task.step.TestComputationStepContext; import org.sonar.db.DbTester; import org.sonar.db.metric.MetricDto; -import static com.google.common.collect.FluentIterable.from; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -84,13 +83,13 @@ public class ExportMetricsStepTest { assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("2 metrics exported"); List<ProjectDump.Metric> exportedMetrics = dumpWriter.getWrittenMessagesOf(DumpElement.METRICS); - ProjectDump.Metric ncloc = from(exportedMetrics).firstMatch(new HasMetricRefPredicate(0)).get(); + ProjectDump.Metric ncloc = exportedMetrics.stream().filter(input -> input.getRef() == 0).findAny().orElseThrow(); assertThat(ncloc.getRef()).isZero(); assertThat(ncloc.getKey()).isEqualTo("ncloc"); assertThat(ncloc.getName()).isEqualTo("Lines of code"); - ProjectDump.Metric coverage = from(exportedMetrics).firstMatch(new HasMetricRefPredicate(1)).get(); - assertThat(coverage.getRef()).isEqualTo(1); + ProjectDump.Metric coverage = exportedMetrics.stream().filter(input -> input.getRef() == 1).findAny().orElseThrow(); + assertThat(coverage.getRef()).isOne(); assertThat(coverage.getKey()).isEqualTo("coverage"); assertThat(coverage.getName()).isEqualTo("Coverage"); } @@ -109,17 +108,4 @@ public class ExportMetricsStepTest { public void test_getDescription() { assertThat(underTest.getDescription()).isEqualTo("Export metrics"); } - - private static class HasMetricRefPredicate implements Predicate<ProjectDump.Metric> { - private final int ref; - - HasMetricRefPredicate(int ref) { - this.ref = ref; - } - - @Override - public boolean apply(@Nonnull ProjectDump.Metric input) { - return input.getRef() == ref; - } - } } diff --git a/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/measure/MeasureAssert.java b/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/measure/MeasureAssert.java index 0e9be2d8dd6..c0036e431ab 100644 --- a/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/measure/MeasureAssert.java +++ b/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/measure/MeasureAssert.java @@ -41,16 +41,6 @@ public class MeasureAssert extends AbstractAssert<MeasureAssert, Measure> { return new MeasureAssert(actual == null ? null : actual.orElse(null)); } - public MeasureAssert hasValueType(Measure.ValueType expected) { - isNotNull(); - - if (actual.getValueType() != expected) { - failWithMessage("Expected ValueType of Measure to be <%s> but was <%s>", expected, actual.getValueType()); - } - - return this; - } - public MeasureAssert hasValue(int expected) { isNotNull(); diff --git a/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepositoryRule.java b/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepositoryRule.java index d57fcb1eb1a..cba4813f639 100644 --- a/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepositoryRule.java +++ b/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepositoryRule.java @@ -169,7 +169,7 @@ public class MeasureRepositoryRule extends ExternalResource implements MeasureRe @Override public Map<String, Measure> getRawMeasures(Component component) { return filterKeys(rawMeasures, hasComponentRef(component)).entrySet().stream() - .collect(Collectors.toMap(k -> k.getKey().getMetricKey(), e -> e.getValue())); + .collect(Collectors.toMap(k -> k.getKey().getMetricKey(), Map.Entry::getValue)); } private HasComponentRefPredicate hasComponentRef(Component component) { diff --git a/server/sonar-ce-task/src/test/java/org/sonar/ce/task/CeTaskComponentTest.java b/server/sonar-ce-task/src/test/java/org/sonar/ce/task/CeTaskComponentTest.java index 4389facfb02..01043cae25b 100644 --- a/server/sonar-ce-task/src/test/java/org/sonar/ce/task/CeTaskComponentTest.java +++ b/server/sonar-ce-task/src/test/java/org/sonar/ce/task/CeTaskComponentTest.java @@ -64,14 +64,15 @@ public class CeTaskComponentTest { String somethingElse = randomAlphabetic(5); CeTask.Component underTest = new CeTask.Component(uuid, key, name); - assertThat(underTest).isEqualTo(underTest); - assertThat(underTest).isEqualTo(new CeTask.Component(uuid, key, name)); - assertThat(underTest).isNotEqualTo(null); - assertThat(underTest).isNotEqualTo(new Object()); - assertThat(underTest).isNotEqualTo(new CeTask.Component(somethingElse, key, name)); - assertThat(underTest).isNotEqualTo(new CeTask.Component(uuid, somethingElse, name)); - assertThat(underTest).isNotEqualTo(new CeTask.Component(uuid, key, somethingElse)); - assertThat(underTest).isNotEqualTo(new CeTask.Component(uuid, key, null)); + assertThat(underTest) + .isEqualTo(underTest) + .isEqualTo(new CeTask.Component(uuid, key, name)) + .isNotNull() + .isNotEqualTo(new Object()) + .isNotEqualTo(new CeTask.Component(somethingElse, key, name)) + .isNotEqualTo(new CeTask.Component(uuid, somethingElse, name)) + .isNotEqualTo(new CeTask.Component(uuid, key, somethingElse)) + .isNotEqualTo(new CeTask.Component(uuid, key, null)); } @Test @@ -82,13 +83,15 @@ public class CeTaskComponentTest { String somethingElse = randomAlphabetic(5); CeTask.Component underTest = new CeTask.Component(uuid, key, name); - assertThat(underTest.hashCode()).isEqualTo(underTest.hashCode()); - assertThat(underTest.hashCode()).isEqualTo(new CeTask.Component(uuid, key, name).hashCode()); - assertThat(underTest.hashCode()).isNotEqualTo(new Object().hashCode()); - assertThat(underTest.hashCode()).isNotEqualTo(new CeTask.Component(somethingElse, key, name).hashCode()); - assertThat(underTest.hashCode()).isNotEqualTo(new CeTask.Component(uuid, somethingElse, name).hashCode()); - assertThat(underTest.hashCode()).isNotEqualTo(new CeTask.Component(uuid, key, somethingElse).hashCode()); - assertThat(underTest.hashCode()).isNotEqualTo(new CeTask.Component(uuid, key, null).hashCode()); + assertThat(underTest) + .hasSameHashCodeAs(underTest) + .hasSameHashCodeAs(new CeTask.Component(uuid, key, name)); + assertThat(underTest.hashCode()) + .isNotEqualTo(new Object().hashCode()) + .isNotEqualTo(new CeTask.Component(somethingElse, key, name).hashCode()) + .isNotEqualTo(new CeTask.Component(uuid, somethingElse, name).hashCode()) + .isNotEqualTo(new CeTask.Component(uuid, key, somethingElse).hashCode()) + .isNotEqualTo(new CeTask.Component(uuid, key, null).hashCode()); } @DataProvider diff --git a/server/sonar-ce-task/src/test/java/org/sonar/ce/task/CeTaskTest.java b/server/sonar-ce-task/src/test/java/org/sonar/ce/task/CeTaskTest.java index 08b12549b77..f2cb3601bdb 100644 --- a/server/sonar-ce-task/src/test/java/org/sonar/ce/task/CeTaskTest.java +++ b/server/sonar-ce-task/src/test/java/org/sonar/ce/task/CeTaskTest.java @@ -121,8 +121,9 @@ public class CeTaskTest { assertThat(task1.equals(task1)).isTrue(); assertThat(task1.equals(task1bis)).isTrue(); assertThat(task1.equals(task2)).isFalse(); - assertThat(task1.hashCode()).isEqualTo(task1.hashCode()); - assertThat(task1.hashCode()).isEqualTo(task1bis.hashCode()); + assertThat(task1) + .hasSameHashCodeAs(task1) + .hasSameHashCodeAs(task1bis); } @Test @@ -148,12 +149,13 @@ public class CeTaskTest { CeTask.User user2 = new CeTask.User("UUID_2", null); CeTask.User user1_diff_login = new CeTask.User("UUID_1", "LOGIN"); - assertThat(user1).isEqualTo(user1); - assertThat(user1).isEqualTo(user1bis); - assertThat(user1).isNotEqualTo(user2); assertThat(user1.equals(null)).isFalse(); - assertThat(user1.hashCode()).isEqualTo(user1.hashCode()); - assertThat(user1.hashCode()).isEqualTo(user1bis.hashCode()); - assertThat(user1.hashCode()).isEqualTo(user1_diff_login.hashCode()); + assertThat(user1) + .isEqualTo(user1) + .isEqualTo(user1bis) + .isNotEqualTo(user2) + .hasSameHashCodeAs(user1) + .hasSameHashCodeAs(user1bis) + .hasSameHashCodeAs(user1_diff_login); } } diff --git a/server/sonar-ce-task/src/test/java/org/sonar/ce/task/container/TaskContainerImplTest.java b/server/sonar-ce-task/src/test/java/org/sonar/ce/task/container/TaskContainerImplTest.java index a4c6834d9a3..f75b4f80424 100644 --- a/server/sonar-ce-task/src/test/java/org/sonar/ce/task/container/TaskContainerImplTest.java +++ b/server/sonar-ce-task/src/test/java/org/sonar/ce/task/container/TaskContainerImplTest.java @@ -72,7 +72,7 @@ public class TaskContainerImplTest { assertThat(defaultStartable.startCalls).isZero(); assertThat(defaultStartable.stopCalls).isZero(); - assertThat(eagerStartable.startCalls).isEqualTo(1); + assertThat(eagerStartable.startCalls).isOne(); assertThat(eagerStartable.stopCalls).isZero(); } @@ -90,8 +90,8 @@ public class TaskContainerImplTest { assertThat(defaultStartable.startCalls).isZero(); assertThat(defaultStartable.stopCalls).isZero(); - assertThat(eagerStartable.startCalls).isEqualTo(1); - assertThat(eagerStartable.stopCalls).isEqualTo(1); + assertThat(eagerStartable.startCalls).isOne(); + assertThat(eagerStartable.stopCalls).isOne(); } public static class DefaultStartable implements Startable { diff --git a/server/sonar-ce-task/src/test/java/org/sonar/ce/task/log/CeTaskMessagesMessageTest.java b/server/sonar-ce-task/src/test/java/org/sonar/ce/task/log/CeTaskMessagesMessageTest.java index 13190b4392f..66adb122df5 100644 --- a/server/sonar-ce-task/src/test/java/org/sonar/ce/task/log/CeTaskMessagesMessageTest.java +++ b/server/sonar-ce-task/src/test/java/org/sonar/ce/task/log/CeTaskMessagesMessageTest.java @@ -60,7 +60,7 @@ public class CeTaskMessagesMessageTest { .isEqualTo(new Message(text, timestamp)) .isNotEqualTo(new Message(text + "ç", timestamp)) .isNotEqualTo(new Message(text, timestamp + 10_999L)) - .isNotEqualTo(null) + .isNotNull() .isNotEqualTo(new Object()); } diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/cleaning/CeCleaningSchedulerImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/cleaning/CeCleaningSchedulerImplTest.java index c6e43313cb8..783866c7eb1 100644 --- a/server/sonar-ce/src/test/java/org/sonar/ce/cleaning/CeCleaningSchedulerImplTest.java +++ b/server/sonar-ce/src/test/java/org/sonar/ce/cleaning/CeCleaningSchedulerImplTest.java @@ -138,7 +138,7 @@ public class CeCleaningSchedulerImplTest { mockedInternalCeQueue, mockCeDistributedInformation(jobLock)); underTest.startScheduling(); - assertThat(executorService.schedulerCounter).isEqualTo(1); + assertThat(executorService.schedulerCounter).isOne(); } private CeConfiguration mockCeConfiguration(long cleanCeTasksInitialDelay, long cleanCeTasksDelay) { diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/configuration/CeConfigurationImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/configuration/CeConfigurationImplTest.java index a2d1f1690bd..a76d275c3e5 100644 --- a/server/sonar-ce/src/test/java/org/sonar/ce/configuration/CeConfigurationImplTest.java +++ b/server/sonar-ce/src/test/java/org/sonar/ce/configuration/CeConfigurationImplTest.java @@ -36,12 +36,12 @@ public class CeConfigurationImplTest { @Test public void getWorkerCount_returns_1_when_there_is_no_WorkerCountProvider() { - assertThat(new CeConfigurationImpl(EMPTY_CONFIGURATION).getWorkerCount()).isEqualTo(1); + assertThat(new CeConfigurationImpl(EMPTY_CONFIGURATION).getWorkerCount()).isOne(); } @Test public void getWorkerMaxCount_returns_1_when_there_is_no_WorkerCountProvider() { - assertThat(new CeConfigurationImpl(EMPTY_CONFIGURATION).getWorkerMaxCount()).isEqualTo(1); + assertThat(new CeConfigurationImpl(EMPTY_CONFIGURATION).getWorkerMaxCount()).isOne(); } @Test @@ -95,10 +95,10 @@ public class CeConfigurationImplTest { @Test public void getCleanCeTasksInitialDelay_returns_0() { assertThat(new CeConfigurationImpl(EMPTY_CONFIGURATION).getCleanTasksInitialDelay()) - .isEqualTo(0L); + .isZero(); workerCountProvider.set(1); assertThat(new CeConfigurationImpl(EMPTY_CONFIGURATION, workerCountProvider).getCleanTasksInitialDelay()) - .isEqualTo(0L); + .isZero(); } @Test diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/monitoring/CEQueueStatusImplConcurrentTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/monitoring/CEQueueStatusImplConcurrentTest.java index 12895e24d9d..e21e063cbda 100644 --- a/server/sonar-ce/src/test/java/org/sonar/ce/monitoring/CEQueueStatusImplConcurrentTest.java +++ b/server/sonar-ce/src/test/java/org/sonar/ce/monitoring/CEQueueStatusImplConcurrentTest.java @@ -58,7 +58,7 @@ public class CEQueueStatusImplConcurrentTest { executorService.awaitTermination(1, TimeUnit.SECONDS); - assertThat(underTest.getInProgressCount()).isEqualTo(1); + assertThat(underTest.getInProgressCount()).isOne(); assertThat(underTest.getErrorCount()).isEqualTo(17); assertThat(underTest.getSuccessCount()).isEqualTo(80); assertThat(underTest.getProcessingTime()).isEqualTo(177); diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/monitoring/CommonCEQueueStatusImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/monitoring/CommonCEQueueStatusImplTest.java index e8680d4bddf..1439a8e2982 100644 --- a/server/sonar-ce/src/test/java/org/sonar/ce/monitoring/CommonCEQueueStatusImplTest.java +++ b/server/sonar-ce/src/test/java/org/sonar/ce/monitoring/CommonCEQueueStatusImplTest.java @@ -58,7 +58,7 @@ public abstract class CommonCEQueueStatusImplTest { public void addInProgress_increases_InProgress() { getUnderTest().addInProgress(); - assertThat(getUnderTest().getInProgressCount()).isEqualTo(1); + assertThat(getUnderTest().getInProgressCount()).isOne(); assertThat(getUnderTest().getErrorCount()).isZero(); assertThat(getUnderTest().getSuccessCount()).isZero(); assertThat(getUnderTest().getProcessingTime()).isZero(); @@ -87,7 +87,7 @@ public abstract class CommonCEQueueStatusImplTest { getUnderTest().addError(SOME_PROCESSING_TIME); assertThat(getUnderTest().getInProgressCount()).isEqualTo(-1); - assertThat(getUnderTest().getErrorCount()).isEqualTo(1); + assertThat(getUnderTest().getErrorCount()).isOne(); assertThat(getUnderTest().getSuccessCount()).isZero(); assertThat(getUnderTest().getProcessingTime()).isEqualTo(SOME_PROCESSING_TIME); } @@ -117,7 +117,7 @@ public abstract class CommonCEQueueStatusImplTest { assertThat(getUnderTest().getInProgressCount()).isEqualTo(-1); assertThat(getUnderTest().getErrorCount()).isZero(); - assertThat(getUnderTest().getSuccessCount()).isEqualTo(1); + assertThat(getUnderTest().getSuccessCount()).isOne(); assertThat(getUnderTest().getProcessingTime()).isEqualTo(SOME_PROCESSING_TIME); } diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/queue/InternalCeQueueImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/queue/InternalCeQueueImplTest.java index 310533c50c4..517f38139ee 100644 --- a/server/sonar-ce/src/test/java/org/sonar/ce/queue/InternalCeQueueImplTest.java +++ b/server/sonar-ce/src/test/java/org/sonar/ce/queue/InternalCeQueueImplTest.java @@ -159,7 +159,7 @@ public class InternalCeQueueImplTest { // available in history Optional<CeActivityDto> history = db.getDbClient().ceActivityDao().selectByUuid(db.getSession(), task.getUuid()); - assertThat(history.isPresent()).isTrue(); + assertThat(history).isPresent(); assertThat(history.get().getStatus()).isEqualTo(CeActivityDto.Status.SUCCESS); assertThat(history.get().getIsLast()).isTrue(); assertThat(history.get().getAnalysisUuid()).isNull(); @@ -187,7 +187,7 @@ public class InternalCeQueueImplTest { // available in history Optional<CeActivityDto> history = db.getDbClient().ceActivityDao().selectByUuid(db.getSession(), task.getUuid()); - assertThat(history.isPresent()).isTrue(); + assertThat(history).isPresent(); assertThat(history.get().getAnalysisUuid()).isNull(); } @@ -200,7 +200,7 @@ public class InternalCeQueueImplTest { // available in history Optional<CeActivityDto> history = db.getDbClient().ceActivityDao().selectByUuid(db.getSession(), task.getUuid()); - assertThat(history.isPresent()).isTrue(); + assertThat(history).isPresent(); assertThat(history.get().getAnalysisUuid()).isEqualTo("U1"); } @@ -330,7 +330,7 @@ public class InternalCeQueueImplTest { CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1")); Optional<CeTask> peek = underTest.peek(WORKER_UUID_1, true); - assertThat(peek.isPresent()).isTrue(); + assertThat(peek).isPresent(); assertThat(peek.get().getUuid()).isEqualTo(task.getUuid()); assertThat(peek.get().getType()).isEqualTo(CeTaskTypes.REPORT); assertThat(peek.get().getComponent()).contains(new CeTask.Component("PROJECT_1", null, null)); @@ -338,7 +338,7 @@ public class InternalCeQueueImplTest { // no more pending tasks peek = underTest.peek(WORKER_UUID_2, true); - assertThat(peek.isPresent()).isFalse(); + assertThat(peek).isEmpty(); } @Test @@ -348,7 +348,7 @@ public class InternalCeQueueImplTest { CeTask task = submit(CeTaskTypes.REPORT, branch); Optional<CeTask> peek = underTest.peek(WORKER_UUID_1, true); - assertThat(peek.isPresent()).isTrue(); + assertThat(peek).isPresent(); assertThat(peek.get().getUuid()).isEqualTo(task.getUuid()); assertThat(peek.get().getType()).isEqualTo(CeTaskTypes.REPORT); assertThat(peek.get().getComponent()).contains(new CeTask.Component(branch.uuid(), branch.getDbKey(), branch.name())); @@ -356,7 +356,7 @@ public class InternalCeQueueImplTest { // no more pending tasks peek = underTest.peek(WORKER_UUID_2, true); - assertThat(peek.isPresent()).isFalse(); + assertThat(peek).isEmpty(); } @Test @@ -391,7 +391,7 @@ public class InternalCeQueueImplTest { when(computeEngineStatus.getStatus()).thenReturn(STOPPING); Optional<CeTask> peek = underTest.peek(WORKER_UUID_1, true); - assertThat(peek.isPresent()).isFalse(); + assertThat(peek).isEmpty(); } @Test @@ -476,7 +476,7 @@ public class InternalCeQueueImplTest { underTest.cancel(db.getSession(), queueDto); Optional<CeActivityDto> activity = db.getDbClient().ceActivityDao().selectByUuid(db.getSession(), task.getUuid()); - assertThat(activity.isPresent()).isTrue(); + assertThat(activity).isPresent(); assertThat(activity.get().getStatus()).isEqualTo(CeActivityDto.Status.CANCELED); } @@ -506,7 +506,7 @@ public class InternalCeQueueImplTest { history = db.getDbClient().ceActivityDao().selectByUuid(db.getSession(), pendingTask2.getUuid()); assertThat(history.get().getStatus()).isEqualTo(CeActivityDto.Status.CANCELED); history = db.getDbClient().ceActivityDao().selectByUuid(db.getSession(), inProgressTask.getUuid()); - assertThat(history.isPresent()).isFalse(); + assertThat(history).isEmpty(); } @Test @@ -628,7 +628,7 @@ public class InternalCeQueueImplTest { private void verifyCeQueueDtoForTaskSubmit(CeTaskSubmit taskSubmit) { Optional<CeQueueDto> queueDto = db.getDbClient().ceQueueDao().selectByUuid(db.getSession(), taskSubmit.getUuid()); - assertThat(queueDto.isPresent()).isTrue(); + assertThat(queueDto).isPresent(); CeQueueDto dto = queueDto.get(); assertThat(dto.getTaskType()).isEqualTo(taskSubmit.getType()); Optional<CeTaskSubmit.Component> component = taskSubmit.getComponent(); diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/taskprocessor/CeProcessingSchedulerImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/taskprocessor/CeProcessingSchedulerImplTest.java index 9354eb186cd..86fadf966c2 100644 --- a/server/sonar-ce/src/test/java/org/sonar/ce/taskprocessor/CeProcessingSchedulerImplTest.java +++ b/server/sonar-ce/src/test/java/org/sonar/ce/taskprocessor/CeProcessingSchedulerImplTest.java @@ -193,7 +193,7 @@ public class CeProcessingSchedulerImplTest { i++; } - assertThat(cancelledTaskFutureCount).isEqualTo(1); + assertThat(cancelledTaskFutureCount).isOne(); assertThat(processingExecutorService.getSchedulerCalls()).containsExactly( regularDelayedPoll, regularDelayedPoll, @@ -231,7 +231,7 @@ public class CeProcessingSchedulerImplTest { i++; } - assertThat(cancelledTaskFutureCount).isEqualTo(1); + assertThat(cancelledTaskFutureCount).isOne(); assertThat(processingExecutorService.getSchedulerCalls()).containsExactly( regularDelayedPoll, regularDelayedPoll, diff --git a/server/sonar-db-core/src/main/java/org/sonar/db/DatabaseUtils.java b/server/sonar-db-core/src/main/java/org/sonar/db/DatabaseUtils.java index 4a74e8771a3..0c70bb0b0c1 100644 --- a/server/sonar-db-core/src/main/java/org/sonar/db/DatabaseUtils.java +++ b/server/sonar-db-core/src/main/java/org/sonar/db/DatabaseUtils.java @@ -19,7 +19,6 @@ */ package org.sonar.db; -import com.google.common.base.Function; import com.google.common.base.Throwables; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; @@ -42,9 +41,9 @@ import java.util.Locale; import java.util.Optional; import java.util.Set; import java.util.function.Consumer; +import java.util.function.Function; import java.util.function.IntFunction; import java.util.function.IntSupplier; -import java.util.function.Supplier; import java.util.regex.Pattern; import javax.annotation.CheckForNull; import javax.annotation.Nonnull; @@ -54,7 +53,6 @@ import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.collect.Lists.newArrayList; import static java.lang.String.format; public class DatabaseUtils { @@ -216,7 +214,7 @@ public class DatabaseUtils { return; } - List<List<T>> partitions = Lists.partition(newArrayList(input), PARTITION_SIZE_FOR_ORACLE); + List<List<T>> partitions = Lists.partition(new ArrayList<>(input), PARTITION_SIZE_FOR_ORACLE); for (List<T> partition : partitions) { consumer.accept(partition); } diff --git a/server/sonar-db-core/src/main/java/org/sonar/db/version/SqTables.java b/server/sonar-db-core/src/main/java/org/sonar/db/version/SqTables.java index 33e58ca8716..ce341c7f897 100644 --- a/server/sonar-db-core/src/main/java/org/sonar/db/version/SqTables.java +++ b/server/sonar-db-core/src/main/java/org/sonar/db/version/SqTables.java @@ -19,12 +19,8 @@ */ package org.sonar.db.version; -import java.util.HashSet; import java.util.Set; -import static java.util.Arrays.asList; -import static java.util.Collections.unmodifiableSet; - public final class SqTables { /** @@ -32,7 +28,7 @@ public final class SqTables { * This list is hardcoded because we didn't succeed in using java.sql.DatabaseMetaData#getTables() in the same way * for all the supported databases, particularly due to Oracle results. */ - public static final Set<String> TABLES = unmodifiableSet(new HashSet<>(asList( + public static final Set<String> TABLES = Set.of( "active_rules", "active_rule_parameters", "alm_settings", @@ -107,7 +103,7 @@ public final class SqTables { "user_roles", "user_tokens", "webhooks", - "webhook_deliveries"))); + "webhook_deliveries"); private SqTables() { // prevents instantiation diff --git a/server/sonar-db-core/src/test/java/org/sonar/db/DatabaseUtilsTest.java b/server/sonar-db-core/src/test/java/org/sonar/db/DatabaseUtilsTest.java index 118518ab2e7..ba1515ff724 100644 --- a/server/sonar-db-core/src/test/java/org/sonar/db/DatabaseUtilsTest.java +++ b/server/sonar-db-core/src/test/java/org/sonar/db/DatabaseUtilsTest.java @@ -462,9 +462,7 @@ public class DatabaseUtilsTest { @Test public void executeLargeUpdates_on_empty_list() { - DatabaseUtils.executeLargeUpdates(Collections.<Integer>emptyList(), input -> { - fail("No partition should be made on empty list"); - }); + DatabaseUtils.executeLargeUpdates(Collections.<Integer>emptyList(), input -> fail("No partition should be made on empty list")); } @Test diff --git a/server/sonar-db-core/src/test/java/org/sonar/db/DefaultDatabaseTest.java b/server/sonar-db-core/src/test/java/org/sonar/db/DefaultDatabaseTest.java index e19b90ce649..da572c8b059 100644 --- a/server/sonar-db-core/src/test/java/org/sonar/db/DefaultDatabaseTest.java +++ b/server/sonar-db-core/src/test/java/org/sonar/db/DefaultDatabaseTest.java @@ -50,7 +50,7 @@ public class DefaultDatabaseTest { Properties props = db.getProperties(); assertThat(props.getProperty("sonar.jdbc.url")).isEqualTo("jdbc:h2:tcp://localhost/sonar"); assertThat(props.getProperty("sonar.jdbc.driverClassName")).isEqualTo("org.h2.Driver"); - assertThat(db.toString()).isEqualTo("Database[jdbc:h2:tcp://localhost/sonar]"); + assertThat(db).hasToString("Database[jdbc:h2:tcp://localhost/sonar]"); } @Test @@ -124,7 +124,7 @@ public class DefaultDatabaseTest { db.stop(); assertThat(db.getDialect().getId()).isEqualTo("h2"); - assertThat(((BasicDataSource) db.getDataSource()).getMaxTotal()).isEqualTo(1); + assertThat(((BasicDataSource) db.getDataSource()).getMaxTotal()).isOne(); } @Test diff --git a/server/sonar-db-core/src/test/java/org/sonar/db/dialect/H2Test.java b/server/sonar-db-core/src/test/java/org/sonar/db/dialect/H2Test.java index 7949ede9e48..558a8dd4e44 100644 --- a/server/sonar-db-core/src/test/java/org/sonar/db/dialect/H2Test.java +++ b/server/sonar-db-core/src/test/java/org/sonar/db/dialect/H2Test.java @@ -66,7 +66,7 @@ public class H2Test { @Test public void getSqlFromDual() { - assertThat(underTest.getSqlFromDual()).isEqualTo(""); + assertThat(underTest.getSqlFromDual()).isEmpty(); } @Test diff --git a/server/sonar-db-core/src/test/java/org/sonar/db/dialect/MsSqlTest.java b/server/sonar-db-core/src/test/java/org/sonar/db/dialect/MsSqlTest.java index b07dfd64c8e..f9bf6a4f070 100644 --- a/server/sonar-db-core/src/test/java/org/sonar/db/dialect/MsSqlTest.java +++ b/server/sonar-db-core/src/test/java/org/sonar/db/dialect/MsSqlTest.java @@ -68,7 +68,7 @@ public class MsSqlTest { @Test public void getSqlFromDual() { - assertThat(underTest.getSqlFromDual()).isEqualTo(""); + assertThat(underTest.getSqlFromDual()).isEmpty(); } @Test diff --git a/server/sonar-db-core/src/test/java/org/sonar/db/dialect/PostgreSqlTest.java b/server/sonar-db-core/src/test/java/org/sonar/db/dialect/PostgreSqlTest.java index cc76081db42..2b40b91cc57 100644 --- a/server/sonar-db-core/src/test/java/org/sonar/db/dialect/PostgreSqlTest.java +++ b/server/sonar-db-core/src/test/java/org/sonar/db/dialect/PostgreSqlTest.java @@ -76,7 +76,7 @@ public class PostgreSqlTest { @Test public void getSqlFromDual() { - assertThat(underTest.getSqlFromDual()).isEqualTo(""); + assertThat(underTest.getSqlFromDual()).isEmpty(); } @Test diff --git a/server/sonar-db-core/src/test/java/org/sonar/db/profiling/SqlLogFormatterTest.java b/server/sonar-db-core/src/test/java/org/sonar/db/profiling/SqlLogFormatterTest.java index 8866d1d3944..93d265dedaa 100644 --- a/server/sonar-db-core/src/test/java/org/sonar/db/profiling/SqlLogFormatterTest.java +++ b/server/sonar-db-core/src/test/java/org/sonar/db/profiling/SqlLogFormatterTest.java @@ -28,7 +28,7 @@ public class SqlLogFormatterTest { @Test public void reformatSql() { - assertThat(SqlLogFormatter.reformatSql("")).isEqualTo(""); + assertThat(SqlLogFormatter.reformatSql("")).isEmpty(); assertThat(SqlLogFormatter.reformatSql("select *")).isEqualTo("select *"); assertThat(SqlLogFormatter.reformatSql("select *\nfrom issues")).isEqualTo("select * from issues"); assertThat(SqlLogFormatter.reformatSql("select *\n from issues")).isEqualTo("select * from issues"); @@ -40,7 +40,7 @@ public class SqlLogFormatterTest { @Test public void reformatParam() { assertThat(SqlLogFormatter.reformatParam(null)).isEqualTo("[null]"); - assertThat(SqlLogFormatter.reformatParam("")).isEqualTo(""); + assertThat(SqlLogFormatter.reformatParam("")).isEmpty(); assertThat(SqlLogFormatter.reformatParam("foo")).isEqualTo("foo"); assertThat(SqlLogFormatter.reformatParam("foo bar ")).isEqualTo("foo bar "); } @@ -69,13 +69,13 @@ public class SqlLogFormatterTest { @Test public void reformatParams_returns_blank_if_zero_params() { String formattedParams = SqlLogFormatter.reformatParams(new Object[0]); - assertThat(formattedParams).isEqualTo(""); + assertThat(formattedParams).isEmpty(); } @Test public void countArguments() { assertThat(SqlLogFormatter.countArguments("select * from issues")).isZero(); - assertThat(SqlLogFormatter.countArguments("select * from issues where id=?")).isEqualTo(1); + assertThat(SqlLogFormatter.countArguments("select * from issues where id=?")).isOne(); assertThat(SqlLogFormatter.countArguments("select * from issues where id=? and kee=?")).isEqualTo(2); } } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java b/server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java index cc088c10d12..12f3ab67d48 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java @@ -19,8 +19,6 @@ */ package org.sonar.db; -import java.util.Arrays; -import java.util.Collections; import java.util.List; import org.sonar.core.platform.Module; import org.sonar.db.alm.pat.AlmPatDao; @@ -59,8 +57,8 @@ import org.sonar.db.permission.template.PermissionTemplateCharacteristicDao; import org.sonar.db.permission.template.PermissionTemplateDao; import org.sonar.db.plugin.PluginDao; import org.sonar.db.portfolio.PortfolioDao; -import org.sonar.db.project.ProjectDao; import org.sonar.db.project.ProjectBadgeTokenDao; +import org.sonar.db.project.ProjectDao; import org.sonar.db.property.InternalComponentPropertiesDao; import org.sonar.db.property.InternalPropertiesDao; import org.sonar.db.property.PropertiesDao; @@ -95,7 +93,7 @@ import org.sonar.db.webhook.WebhookDao; import org.sonar.db.webhook.WebhookDeliveryDao; public class DaoModule extends Module { - private static final List<Class<? extends Dao>> classes = Collections.unmodifiableList(Arrays.asList( + private static final List<Class<? extends Dao>> classes = List.of( // ===================================================================== // for readability and easier merge, keep list ordered alphabetically // ===================================================================== @@ -168,7 +166,7 @@ public class DaoModule extends Module { UserPropertiesDao.class, UserTokenDao.class, WebhookDao.class, - WebhookDeliveryDao.class)); + WebhookDeliveryDao.class); @Override protected void configureModule() { diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskCharacteristicDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskCharacteristicDto.java index acf7f6783ee..75928668ec8 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskCharacteristicDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskCharacteristicDto.java @@ -30,7 +30,7 @@ public class CeTaskCharacteristicDto { public static final String BRANCH_KEY = "branch"; public static final String BRANCH_TYPE_KEY = "branchType"; public static final String PULL_REQUEST = "pullRequest"; - public static final Set<String> SUPPORTED_KEYS = unmodifiableSet(new HashSet<>(asList(BRANCH_KEY, BRANCH_TYPE_KEY, PULL_REQUEST))); + public static final Set<String> SUPPORTED_KEYS = Set.of(BRANCH_KEY, BRANCH_TYPE_KEY, PULL_REQUEST); private String uuid; private String taskUuid; diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeProfiler.java b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeProfiler.java index 9d0a8250173..ec1e3ff7828 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeProfiler.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeProfiler.java @@ -55,12 +55,7 @@ public class PurgeProfiler { } void stop() { - final Long cumulatedDuration; - if (durations.containsKey(currentTable)) { - cumulatedDuration = durations.get(currentTable); - } else { - cumulatedDuration = 0L; - } + Long cumulatedDuration = durations.getOrDefault(currentTable, 0L); durations.put(currentTable, cumulatedDuration + (clock.now() - startTime)); } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/PaginationTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/PaginationTest.java index aaf90cbc676..e7b56559e4f 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/PaginationTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/PaginationTest.java @@ -31,7 +31,7 @@ public class PaginationTest { public void all_is_page_1_with_MAX_INTEGER_page_size() { Pagination pagination = Pagination.all(); - assertThat(pagination.getPage()).isEqualTo(1); + assertThat(pagination.getPage()).isOne(); assertThat(pagination.getPageSize()).isEqualTo(Integer.MAX_VALUE); } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/alm/setting/ProjectAlmSettingDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/alm/setting/ProjectAlmSettingDaoTest.java index c972d2d6ab6..5d987f1361d 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/alm/setting/ProjectAlmSettingDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/alm/setting/ProjectAlmSettingDaoTest.java @@ -183,7 +183,7 @@ public class ProjectAlmSettingDaoTest { underTest.deleteByAlmSetting(dbSession, githubAlmSetting); assertThat(underTest.countByAlmSetting(dbSession, githubAlmSetting)).isZero(); - assertThat(underTest.countByAlmSetting(dbSession, githubAlmSetting1)).isEqualTo(1); + assertThat(underTest.countByAlmSetting(dbSession, githubAlmSetting1)).isOne(); } } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/audit/AuditDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/audit/AuditDaoTest.java index 31c26933cf1..a36cb96ee9f 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/audit/AuditDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/audit/AuditDaoTest.java @@ -56,7 +56,7 @@ public class AuditDaoTest { List<AuditDto> auditDtos = testAuditDao.selectByPeriodPaginated(dbSession, 1, 20000, 2); - assertThat(auditDtos.size()).isEqualTo(1); + assertThat(auditDtos.size()).isOne(); } @Test @@ -64,7 +64,7 @@ public class AuditDaoTest { prepareRowsWithDeterministicCreatedAt(100_001); long purged = testAuditDao.deleteBefore(dbSession, 200_000); assertThat(purged).isEqualTo(100_000); - assertThat(db.countRowsOfTable(dbSession, "audits")).isEqualTo(1); + assertThat(db.countRowsOfTable(dbSession, "audits")).isOne(); assertThat(testAuditDao.selectOlderThan(dbSession, 100_002)) .extracting(AuditDto::getCreatedAt) .containsOnly(100_001L); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/audit/model/LicenseNewValueTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/audit/model/LicenseNewValueTest.java index eba459637a6..cfa7e1f4be5 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/audit/model/LicenseNewValueTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/audit/model/LicenseNewValueTest.java @@ -28,7 +28,7 @@ public class LicenseNewValueTest { @Test public void toStringIsEmptyForNullEdition(){ LicenseNewValue newValue = new LicenseNewValue(null); - assertThat(newValue.toString()).isEqualTo("{}"); + assertThat(newValue).hasToString("{}"); } @Test diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeActivityDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeActivityDaoTest.java index 870eacaea7b..cca5ec95293 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeActivityDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeActivityDaoTest.java @@ -130,7 +130,7 @@ public class CeActivityDaoTest { assertThat(underTest.selectByUuid(dbSession, tasks[0].getUuid()).get().getWarningCount()).isEqualTo(moreThan1); assertThat(underTest.selectByUuid(dbSession, tasks[1].getUuid()).get().getWarningCount()).isZero(); - assertThat(underTest.selectByUuid(dbSession, tasks[2].getUuid()).get().getWarningCount()).isEqualTo(1); + assertThat(underTest.selectByUuid(dbSession, tasks[2].getUuid()).get().getWarningCount()).isOne(); } private void insertWarnings(CeActivityDto task, int warningCount) { @@ -691,9 +691,9 @@ public class CeActivityDaoTest { insert("TASK_3", "REPORT", MAINCOMPONENT_1, SUCCESS); underTest.deleteByUuids(db.getSession(), ImmutableSet.of("TASK_1", "TASK_3")); - assertThat(underTest.selectByUuid(db.getSession(), "TASK_1").isPresent()).isFalse(); + assertThat(underTest.selectByUuid(db.getSession(), "TASK_1")).isEmpty(); assertThat(underTest.selectByUuid(db.getSession(), "TASK_2")).isPresent(); - assertThat(underTest.selectByUuid(db.getSession(), "TASK_3").isPresent()).isFalse(); + assertThat(underTest.selectByUuid(db.getSession(), "TASK_3")).isEmpty(); } @Test @@ -718,7 +718,7 @@ public class CeActivityDaoTest { insert("TASK_5", CeTaskTypes.REPORT, MAINCOMPONENT_1, SUCCESS); db.commit(); - assertThat(underTest.countLastByStatusAndMainComponentUuid(dbSession, SUCCESS, MAINCOMPONENT_1)).isEqualTo(1); + assertThat(underTest.countLastByStatusAndMainComponentUuid(dbSession, SUCCESS, MAINCOMPONENT_1)).isOne(); assertThat(underTest.countLastByStatusAndMainComponentUuid(dbSession, SUCCESS, null)).isEqualTo(2); } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeQueueDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeQueueDaoTest.java index 0f2935c8014..c685c1ded01 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeQueueDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeQueueDaoTest.java @@ -126,7 +126,7 @@ public class CeQueueDaoTest { public void test_selectByUuid() { CeQueueDto ceQueueDto = insertPending(TASK_UUID_1, MAIN_COMPONENT_UUID_1); - assertThat(underTest.selectByUuid(db.getSession(), "TASK_UNKNOWN").isPresent()).isFalse(); + assertThat(underTest.selectByUuid(db.getSession(), "TASK_UNKNOWN")).isEmpty(); CeQueueDto saved = underTest.selectByUuid(db.getSession(), TASK_UUID_1).get(); assertThat(saved.getUuid()).isEqualTo(TASK_UUID_1); assertThat(saved.getTaskType()).isEqualTo(CeTaskTypes.REPORT); @@ -250,11 +250,11 @@ public class CeQueueDaoTest { assertThat(underTest.selectByUuid(db.getSession(), TASK_UUID_1)).isPresent(); deletedCount = underTest.deleteByUuid(db.getSession(), TASK_UUID_1); - assertThat(deletedCount).isEqualTo(1); + assertThat(deletedCount).isOne(); assertThat(underTest.selectByUuid(db.getSession(), TASK_UUID_1)).isEmpty(); deletedCount = underTest.deleteByUuid(db.getSession(), TASK_UUID_2, null); - assertThat(deletedCount).isEqualTo(1); + assertThat(deletedCount).isOne(); assertThat(underTest.selectByUuid(db.getSession(), TASK_UUID_2)).isEmpty(); } @@ -276,11 +276,11 @@ public class CeQueueDaoTest { assertThat(underTest.selectByUuid(db.getSession(), TASK_UUID_2)).isPresent(); deletedCount = underTest.deleteByUuid(db.getSession(), TASK_UUID_1, new DeleteIf(PENDING)); - assertThat(deletedCount).isEqualTo(1); + assertThat(deletedCount).isOne(); assertThat(underTest.selectByUuid(db.getSession(), TASK_UUID_1)).isEmpty(); deletedCount = underTest.deleteByUuid(db.getSession(), TASK_UUID_2, new DeleteIf(IN_PROGRESS)); - assertThat(deletedCount).isEqualTo(1); + assertThat(deletedCount).isOne(); assertThat(underTest.selectByUuid(db.getSession(), TASK_UUID_2)).isEmpty(); } @@ -445,7 +445,7 @@ public class CeQueueDaoTest { // do not peek second task as long as the first one is in progress peek = underTest.peek(db.getSession(), WORKER_UUID_1, false, false); - assertThat(peek.isPresent()).isFalse(); + assertThat(peek).isEmpty(); // first one is finished underTest.deleteByUuid(db.getSession(), TASK_UUID_1); @@ -577,7 +577,7 @@ public class CeQueueDaoTest { .setTaskType(CeTaskTypes.REPORT) .setCreatedAt(100_000L)); - assertThat(underTest.countByStatusAndMainComponentUuid(db.getSession(), IN_PROGRESS, MAIN_COMPONENT_UUID_1)).isEqualTo(1); + assertThat(underTest.countByStatusAndMainComponentUuid(db.getSession(), IN_PROGRESS, MAIN_COMPONENT_UUID_1)).isOne(); assertThat(underTest.countByStatus(db.getSession(), IN_PROGRESS)).isEqualTo(2); } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeScannerContextDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeScannerContextDaoTest.java index c30fc96f0bd..cce756a0a04 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeScannerContextDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeScannerContextDaoTest.java @@ -83,7 +83,7 @@ public class CeScannerContextDaoTest { underTest.insert(dbSession, SOME_UUID, scannerContextInputStreamOf("bla")); dbSession.commit(); - assertThat(dbTester.countRowsOfTable(dbSession, TABLE_NAME)).isEqualTo(1); + assertThat(dbTester.countRowsOfTable(dbSession, TABLE_NAME)).isOne(); assertThatThrownBy(() -> underTest.insert(dbSession, SOME_UUID, scannerContextInputStreamOf("blo"))) .isInstanceOf(IllegalStateException.class) diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeTaskInputDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeTaskInputDaoTest.java index 6242cd1bf92..2f6385fbb77 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeTaskInputDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeTaskInputDaoTest.java @@ -96,7 +96,7 @@ public class CeTaskInputDaoTest { @Test public void deleteByUuids() { insertData(A_UUID); - assertThat(dbTester.countRowsOfTable(TABLE_NAME)).isEqualTo(1); + assertThat(dbTester.countRowsOfTable(TABLE_NAME)).isOne(); underTest.deleteByUuids(dbTester.getSession(), singleton(A_UUID)); dbTester.commit(); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/ce/LogsIteratorInputStreamTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/ce/LogsIteratorInputStreamTest.java index 85e7a8f1e5f..4fcab30f9c4 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/ce/LogsIteratorInputStreamTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/ce/LogsIteratorInputStreamTest.java @@ -43,7 +43,7 @@ public class LogsIteratorInputStreamTest { @Test public void read_from_ClosableIterator_with_single_empty_line() throws IOException { - assertThat(read(create(""))).isEqualTo(""); + assertThat(read(create(""))).isEmpty(); } @Test diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/AnalysisPropertiesDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/AnalysisPropertiesDaoTest.java index f4278817184..ccf2d576d1b 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/AnalysisPropertiesDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/AnalysisPropertiesDaoTest.java @@ -99,7 +99,7 @@ public class AnalysisPropertiesDaoTest { public void insert_as_empty() { AnalysisPropertyDto analysisPropertyDto = insertAnalysisPropertyDto(0); - assertThat(dbTester.countRowsOfTable(dbSession, "ANALYSIS_PROPERTIES")).isEqualTo(1); + assertThat(dbTester.countRowsOfTable(dbSession, "ANALYSIS_PROPERTIES")).isOne(); compareFirstValueWith(analysisPropertyDto); } @@ -107,7 +107,7 @@ public class AnalysisPropertiesDaoTest { public void insert_as_text() { AnalysisPropertyDto analysisPropertyDto = insertAnalysisPropertyDto(1 + random.nextInt(3999)); - assertThat(dbTester.countRowsOfTable(dbSession, "ANALYSIS_PROPERTIES")).isEqualTo(1); + assertThat(dbTester.countRowsOfTable(dbSession, "ANALYSIS_PROPERTIES")).isOne(); compareFirstValueWith(analysisPropertyDto); } @@ -115,7 +115,7 @@ public class AnalysisPropertiesDaoTest { public void insert_as_clob() { AnalysisPropertyDto analysisPropertyDto = insertAnalysisPropertyDto(4000 + random.nextInt(100)); - assertThat(dbTester.countRowsOfTable(dbSession, "ANALYSIS_PROPERTIES")).isEqualTo(1); + assertThat(dbTester.countRowsOfTable(dbSession, "ANALYSIS_PROPERTIES")).isOne(); compareFirstValueWith(analysisPropertyDto); } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/BranchDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/BranchDaoTest.java index fa598e92797..3e4e152ca12 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/BranchDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/BranchDaoTest.java @@ -605,8 +605,8 @@ public class BranchDaoTest { assertThat(underTest.countByTypeAndCreationDate(dbSession, BranchType.BRANCH, 0L)).isEqualTo(3); assertThat(underTest.countByTypeAndCreationDate(dbSession, BranchType.BRANCH, NOW)).isEqualTo(3); assertThat(underTest.countByTypeAndCreationDate(dbSession, BranchType.BRANCH, NOW + 100)).isZero(); - assertThat(underTest.countByTypeAndCreationDate(dbSession, BranchType.PULL_REQUEST, 0L)).isEqualTo(1); - assertThat(underTest.countByTypeAndCreationDate(dbSession, BranchType.PULL_REQUEST, NOW)).isEqualTo(1); + assertThat(underTest.countByTypeAndCreationDate(dbSession, BranchType.PULL_REQUEST, 0L)).isOne(); + assertThat(underTest.countByTypeAndCreationDate(dbSession, BranchType.PULL_REQUEST, NOW)).isOne(); assertThat(underTest.countByTypeAndCreationDate(dbSession, BranchType.PULL_REQUEST, NOW + 100)).isZero(); } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java index ccb93d46484..f440ca6af10 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java @@ -1123,9 +1123,9 @@ public class ComponentDaoTest { db.components().insertProjectAndSnapshot(ComponentTesting.newPortfolio()); Supplier<ComponentQuery.Builder> query = () -> ComponentQuery.builder().setOnProvisionedOnly(true); - assertThat(underTest.countByQuery(dbSession, query.get().setQualifiers(PROJECT).build())).isEqualTo(1); + assertThat(underTest.countByQuery(dbSession, query.get().setQualifiers(PROJECT).build())).isOne(); assertThat(underTest.countByQuery(dbSession, query.get().setQualifiers(Qualifiers.VIEW).build())).isZero(); - assertThat(underTest.countByQuery(dbSession, query.get().setQualifiers(PROJECT, Qualifiers.VIEW).build())).isEqualTo(1); + assertThat(underTest.countByQuery(dbSession, query.get().setQualifiers(PROJECT, Qualifiers.VIEW).build())).isOne(); } @Test @@ -1245,18 +1245,20 @@ public class ComponentDaoTest { Map<String, Object> row = selectBColumnsForUuid("U1"); assertThat(row.get("bChanged")).isIn(true, /* for Oracle */1L, 1); - assertThat(row.get("bKey")).isEqualTo("key"); - assertThat(row.get("bCopyComponentUuid")).isEqualTo("copy"); - assertThat(row.get("bDescription")).isEqualTo("desc"); + assertThat(row) + .containsEntry("bKey", "key") + .containsEntry("bCopyComponentUuid", "copy") + .containsEntry("bDescription", "desc"); assertThat(row.get("bEnabled")).isIn(true, /* for Oracle */1L, 1); - assertThat(row.get("bUuidPath")).isEqualTo("uuid_path"); - assertThat(row.get("bLanguage")).isEqualTo("lang"); - assertThat(row.get("bLongName")).isEqualTo("longName"); - assertThat(row.get("bModuleUuid")).isEqualTo("moduleUuid"); - assertThat(row.get("bModuleUuidPath")).isEqualTo("moduleUuidPath"); - assertThat(row.get("bName")).isEqualTo("name"); - assertThat(row.get("bPath")).isEqualTo("path"); - assertThat(row.get("bQualifier")).isEqualTo("qualifier"); + assertThat(row) + .containsEntry("bUuidPath", "uuid_path") + .containsEntry("bLanguage", "lang") + .containsEntry("bLongName", "longName") + .containsEntry("bModuleUuid", "moduleUuid") + .containsEntry("bModuleUuidPath", "moduleUuidPath") + .containsEntry("bName", "name") + .containsEntry("bPath", "path") + .containsEntry("bQualifier", "qualifier"); } @Test @@ -1271,33 +1273,37 @@ public class ComponentDaoTest { Map<String, Object> row1 = selectBColumnsForUuid("U1"); assertThat(row1.get("bChanged")).isIn(true, /* for Oracle */1L, 1); - assertThat(row1.get("bKey")).isEqualTo(dto1.getDbKey()); - assertThat(row1.get("bCopyComponentUuid")).isEqualTo(dto1.getCopyComponentUuid()); - assertThat(row1.get("bDescription")).isEqualTo(dto1.description()); + assertThat(row1) + .containsEntry("bKey", dto1.getDbKey()) + .containsEntry("bCopyComponentUuid", dto1.getCopyComponentUuid()) + .containsEntry("bDescription", dto1.description()); assertThat(row1.get("bEnabled")).isIn(false, /* for Oracle */0L, 0); - assertThat(row1.get("bUuidPath")).isEqualTo(dto1.getUuidPath()); - assertThat(row1.get("bLanguage")).isEqualTo(dto1.language()); - assertThat(row1.get("bLongName")).isEqualTo(dto1.longName()); - assertThat(row1.get("bModuleUuid")).isEqualTo(dto1.moduleUuid()); - assertThat(row1.get("bModuleUuidPath")).isEqualTo(dto1.moduleUuidPath()); - assertThat(row1.get("bName")).isEqualTo(dto1.name()); - assertThat(row1.get("bPath")).isEqualTo(dto1.path()); - assertThat(row1.get("bQualifier")).isEqualTo(dto1.qualifier()); + assertThat(row1) + .containsEntry("bUuidPath", dto1.getUuidPath()) + .containsEntry("bLanguage", dto1.language()) + .containsEntry("bLongName", dto1.longName()) + .containsEntry("bModuleUuid", dto1.moduleUuid()) + .containsEntry("bModuleUuidPath", dto1.moduleUuidPath()) + .containsEntry("bName", dto1.name()) + .containsEntry("bPath", dto1.path()) + .containsEntry("bQualifier", dto1.qualifier()); Map<String, Object> row2 = selectBColumnsForUuid("U2"); assertThat(row2.get("bChanged")).isIn(true, /* for Oracle */1L, 1); - assertThat(row2.get("bKey")).isEqualTo(dto2.getDbKey()); - assertThat(row2.get("bCopyComponentUuid")).isEqualTo(dto2.getCopyComponentUuid()); - assertThat(row2.get("bDescription")).isEqualTo(dto2.description()); + assertThat(row2) + .containsEntry("bKey", dto2.getDbKey()) + .containsEntry("bCopyComponentUuid", dto2.getCopyComponentUuid()) + .containsEntry("bDescription", dto2.description()); assertThat(row2.get("bEnabled")).isIn(false, /* for Oracle */0L, 0); - assertThat(row2.get("bUuidPath")).isEqualTo(dto2.getUuidPath()); - assertThat(row2.get("bLanguage")).isEqualTo(dto2.language()); - assertThat(row2.get("bLongName")).isEqualTo(dto2.longName()); - assertThat(row2.get("bModuleUuid")).isEqualTo(dto2.moduleUuid()); - assertThat(row2.get("bModuleUuidPath")).isEqualTo(dto2.moduleUuidPath()); - assertThat(row2.get("bName")).isEqualTo(dto2.name()); - assertThat(row2.get("bPath")).isEqualTo(dto2.path()); - assertThat(row2.get("bQualifier")).isEqualTo(dto2.qualifier()); + assertThat(row2) + .containsEntry("bUuidPath", dto2.getUuidPath()) + .containsEntry("bLanguage", dto2.language()) + .containsEntry("bLongName", dto2.longName()) + .containsEntry("bModuleUuid", dto2.moduleUuid()) + .containsEntry("bModuleUuidPath", dto2.moduleUuidPath()) + .containsEntry("bName", dto2.name()) + .containsEntry("bPath", dto2.path()) + .containsEntry("bQualifier", dto2.qualifier()); Map<String, Object> row3 = selectBColumnsForUuid("U3"); assertThat(row3.get("bChanged")).isIn(false, /* for Oracle */0L, 0); @@ -1370,7 +1376,7 @@ public class ComponentDaoTest { ComponentDto main = db.components().insertPublicProject(); ComponentDto branch = db.components().insertProjectBranch(main); - assertThat(underTest.countByQuery(dbSession, ALL_PROJECTS_COMPONENT_QUERY)).isEqualTo(1); + assertThat(underTest.countByQuery(dbSession, ALL_PROJECTS_COMPONENT_QUERY)).isOne(); } @Test diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDtoTest.java index 64974077864..ae332bab59f 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDtoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDtoTest.java @@ -61,12 +61,12 @@ public class ComponentDtoTest { ComponentDto dtoWithSameUuid = new ComponentDto().setUuid("u1"); ComponentDto dtoWithDifferentUuid = new ComponentDto().setUuid("u2"); - assertThat(dto).isEqualTo(dto); - assertThat(dto).isEqualTo(dtoWithSameUuid); - assertThat(dto).isNotEqualTo(dtoWithDifferentUuid); - - assertThat(dto.hashCode()).isEqualTo(dto.hashCode()); - assertThat(dto.hashCode()).isEqualTo(dtoWithSameUuid.hashCode()); + assertThat(dto) + .isEqualTo(dto) + .isEqualTo(dtoWithSameUuid) + .isNotEqualTo(dtoWithDifferentUuid) + .hasSameHashCodeAs(dto) + .hasSameHashCodeAs(dtoWithSameUuid); assertThat(dto.hashCode()).isNotEqualTo(dtoWithDifferentUuid.hashCode()); } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ScrapAnalysisPropertyDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ScrapAnalysisPropertyDtoTest.java index 5902c4b1b35..1d3effdb77f 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ScrapAnalysisPropertyDtoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ScrapAnalysisPropertyDtoTest.java @@ -34,7 +34,7 @@ public class ScrapAnalysisPropertyDtoTest { ScrapAnalysisPropertyDto underTest = new ScrapAnalysisPropertyDto(); underTest.setEmpty(true); - assertThat(underTest.getValue()).isEqualTo(""); + assertThat(underTest.getValue()).isEmpty(); } @Test diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotDaoTest.java index 7164082cff9..40ae2f1fc67 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotDaoTest.java @@ -321,7 +321,7 @@ public class SnapshotDaoTest { Optional<SnapshotDto> dto = underTest.selectOldestSnapshot(dbSession, project.uuid()); assertThat(dto).isNotEmpty(); - assertThat(dto.get().getCreatedAt()).isEqualTo(1L); + assertThat(dto.get().getCreatedAt()).isOne(); assertThat(underTest.selectOldestSnapshot(dbSession, "blabla")).isEmpty(); } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/duplication/DuplicationDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/duplication/DuplicationDaoTest.java index dba8d566232..d1bcc206be5 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/duplication/DuplicationDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/duplication/DuplicationDaoTest.java @@ -150,12 +150,13 @@ public class DuplicationDaoTest { Assertions.assertThat(rows).hasSize(1); Map<String, Object> row = rows.get(0); Assertions.assertThat(row.get("UUID")).isNotNull(); - Assertions.assertThat(row.get("ANALYSIS")).isEqualTo(analysis.getUuid()); - Assertions.assertThat(row.get("COMPONENT")).isEqualTo(project.uuid()); - Assertions.assertThat(row.get("HASH")).isEqualTo("bb"); - Assertions.assertThat(row.get("INDEX")).isEqualTo(0L); - Assertions.assertThat(row.get("START")).isEqualTo(1L); - Assertions.assertThat(row.get("END")).isEqualTo(2L); + Assertions.assertThat(row) + .containsEntry("ANALYSIS", analysis.getUuid()) + .containsEntry("COMPONENT", project.uuid()) + .containsEntry("HASH", "bb") + .containsEntry("INDEX", 0L) + .containsEntry("START", 1L) + .containsEntry("END", 2L); } public void insert(ComponentDto project, SnapshotDto analysis, String hash, int indexInFile, int startLine, int endLine) { diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueChangeDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueChangeDaoTest.java index 02d87460711..d73c927d90c 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueChangeDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueChangeDaoTest.java @@ -110,7 +110,7 @@ public class IssueChangeDaoTest { assertThat(underTest.delete(db.getSession(), issueChange1.getKey())).isTrue(); - assertThat(db.countRowsOfTable(db.getSession(), "issue_changes")).isEqualTo(1); + assertThat(db.countRowsOfTable(db.getSession(), "issue_changes")).isOne(); } @Test diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java index d3ba10a6349..13772704f58 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java @@ -326,14 +326,14 @@ public class IssueDaoTest { assertThat(result.stream().filter(g -> g.getRuleType() == RuleType.VULNERABILITY.getDbConstant()).mapToLong(IssueGroupDto::getCount).sum()).isZero(); assertThat(result.stream().filter(g -> g.getSeverity().equals("CRITICAL")).mapToLong(IssueGroupDto::getCount).sum()).isEqualTo(2); - assertThat(result.stream().filter(g -> g.getSeverity().equals("MAJOR")).mapToLong(IssueGroupDto::getCount).sum()).isEqualTo(1); + assertThat(result.stream().filter(g -> g.getSeverity().equals("MAJOR")).mapToLong(IssueGroupDto::getCount).sum()).isOne(); assertThat(result.stream().filter(g -> g.getSeverity().equals("MINOR")).mapToLong(IssueGroupDto::getCount).sum()).isZero(); assertThat(result.stream().filter(g -> g.getStatus().equals("OPEN")).mapToLong(IssueGroupDto::getCount).sum()).isEqualTo(2); - assertThat(result.stream().filter(g -> g.getStatus().equals("RESOLVED")).mapToLong(IssueGroupDto::getCount).sum()).isEqualTo(1); + assertThat(result.stream().filter(g -> g.getStatus().equals("RESOLVED")).mapToLong(IssueGroupDto::getCount).sum()).isOne(); assertThat(result.stream().filter(g -> g.getStatus().equals("CLOSED")).mapToLong(IssueGroupDto::getCount).sum()).isZero(); - assertThat(result.stream().filter(g -> "FALSE-POSITIVE".equals(g.getResolution())).mapToLong(IssueGroupDto::getCount).sum()).isEqualTo(1); + assertThat(result.stream().filter(g -> "FALSE-POSITIVE".equals(g.getResolution())).mapToLong(IssueGroupDto::getCount).sum()).isOne(); assertThat(result.stream().filter(g -> g.getResolution() == null).mapToLong(IssueGroupDto::getCount).sum()).isEqualTo(2); assertThat(result.stream().filter(g -> g.isInLeak()).mapToLong(IssueGroupDto::getCount).sum()).isEqualTo(3); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDtoTest.java index 644f33d74f7..8f1b5dabeb7 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDtoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDtoTest.java @@ -89,7 +89,7 @@ public class IssueDtoTest { DefaultIssue issue = dto.toDefaultIssue(); assertThat(issue.key()).isEqualTo("100"); assertThat(issue.type()).isEqualTo(RuleType.VULNERABILITY); - assertThat(issue.ruleKey().toString()).isEqualTo("squid:AvoidCycle"); + assertThat(issue.ruleKey()).hasToString("squid:AvoidCycle"); assertThat(issue.language()).isEqualTo("xoo"); assertThat(issue.componentUuid()).isEqualTo("CDEF"); assertThat(issue.projectUuid()).isEqualTo("GHIJ"); @@ -124,9 +124,9 @@ public class IssueDtoTest { assertThat(dto.getRuleUuid()).isEqualTo("uuid-1"); assertThat(dto.getRuleRepo()).isEqualTo("squid"); assertThat(dto.getRule()).isEqualTo("AvoidCycle"); - assertThat(dto.getRuleKey().toString()).isEqualTo("squid:AvoidCycle"); + assertThat(dto.getRuleKey()).hasToString("squid:AvoidCycle"); assertThat(dto.getLanguage()).isEqualTo("xoo"); - assertThat(dto.isExternal()).isEqualTo(true); + assertThat(dto.isExternal()).isTrue(); } @Test diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueMapperTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueMapperTest.java index fc40fcab457..2d3ab3091ed 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueMapperTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueMapperTest.java @@ -188,7 +188,7 @@ public class IssueMapperTest { dto.setSelectedAt(1500000000000L); int count = underTest.updateIfBeforeSelectedDate(dto); - assertThat(count).isEqualTo(1); + assertThat(count).isOne(); dbTester.getSession().commit(); IssueDto result = underTest.selectByKey("ABCDE"); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java index 76ebd5c01b4..734345fd31a 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java @@ -334,7 +334,7 @@ public class LiveMeasureDaoTest { .build(); long result = underTest.sumNclocOfBiggestBranch(db.getSession(), query); - assertThat(result).isEqualTo(0L); + assertThat(result).isZero(); } @Test @@ -457,7 +457,7 @@ public class LiveMeasureDaoTest { db.measures().insertLiveMeasure(project1, metric2); assertThat(underTest.countProjectsHavingMeasure(db.getSession(), metric1.getKey())).isEqualTo(2); - assertThat(underTest.countProjectsHavingMeasure(db.getSession(), metric2.getKey())).isEqualTo(1); + assertThat(underTest.countProjectsHavingMeasure(db.getSession(), metric2.getKey())).isOne(); assertThat(underTest.countProjectsHavingMeasure(db.getSession(), "unknown")).isZero(); } @@ -472,14 +472,14 @@ public class LiveMeasureDaoTest { int count = underTest.upsert(db.getSession(), dto); verifyPersisted(dto); verifyTableSize(1); - assertThat(count).isEqualTo(1); + assertThat(count).isOne(); // update dto.setValue(dto.getValue() + 1); dto.setVariation(dto.getVariation() + 10); dto.setData(dto.getDataAsString() + "_new"); count = underTest.upsert(db.getSession(), dto); - assertThat(count).isEqualTo(1); + assertThat(count).isOne(); verifyPersisted(dto); verifyTableSize(1); } @@ -512,7 +512,7 @@ public class LiveMeasureDaoTest { // update dto.setData(RandomStringUtils.random(dto.getDataAsString().length() + 10)); int count = underTest.upsert(db.getSession(), dto); - assertThat(count).isEqualTo(1); + assertThat(count).isOne(); verifyPersisted(dto); verifyTableSize(1); } @@ -544,7 +544,7 @@ public class LiveMeasureDaoTest { // update dto.setData((String) null); int count = underTest.upsert(db.getSession(), dto); - assertThat(count).isEqualTo(1); + assertThat(count).isOne(); verifyPersisted(dto); verifyTableSize(1); } @@ -560,7 +560,7 @@ public class LiveMeasureDaoTest { // update dto.setVariation(50.0); int count = underTest.upsert(db.getSession(), dto); - assertThat(count).isEqualTo(1); + assertThat(count).isOne(); verifyPersisted(dto); verifyTableSize(1); } @@ -576,7 +576,7 @@ public class LiveMeasureDaoTest { // update dto.setVariation(null); int count = underTest.upsert(db.getSession(), dto); - assertThat(count).isEqualTo(1); + assertThat(count).isOne(); verifyPersisted(dto); verifyTableSize(1); } @@ -592,7 +592,7 @@ public class LiveMeasureDaoTest { // update dto.setVariation(40.0); int count = underTest.upsert(db.getSession(), dto); - assertThat(count).isEqualTo(1); + assertThat(count).isOne(); verifyPersisted(dto); verifyTableSize(1); } @@ -608,7 +608,7 @@ public class LiveMeasureDaoTest { // update dto.setValue(50.0); int count = underTest.upsert(db.getSession(), dto); - assertThat(count).isEqualTo(1); + assertThat(count).isOne(); verifyPersisted(dto); verifyTableSize(1); } @@ -624,7 +624,7 @@ public class LiveMeasureDaoTest { // update dto.setValue(null); int count = underTest.upsert(db.getSession(), dto); - assertThat(count).isEqualTo(1); + assertThat(count).isOne(); verifyPersisted(dto); verifyTableSize(1); } @@ -640,7 +640,7 @@ public class LiveMeasureDaoTest { // update dto.setValue(40.0); int count = underTest.upsert(db.getSession(), dto); - assertThat(count).isEqualTo(1); + assertThat(count).isOne(); verifyPersisted(dto); verifyTableSize(1); } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/metric/MetricDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/metric/MetricDaoTest.java index 6297f2bfe84..56e4302086c 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/metric/MetricDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/metric/MetricDaoTest.java @@ -134,7 +134,7 @@ public class MetricDaoTest { assertThat(result.getDescription()).isEqualTo("Coverage by unit tests"); assertThat(result.getDomain()).isEqualTo("Tests"); assertThat(result.getValueType()).isEqualTo("PERCENT"); - assertThat(result.getDirection()).isEqualTo(1); + assertThat(result.getDirection()).isOne(); assertThat(result.isQualitative()).isTrue(); assertThat(result.getWorstValue()).isEqualTo(0d); assertThat(result.getBestValue()).isEqualTo(100d); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/metric/MetricDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/metric/MetricDtoTest.java index 0748e068b4e..495d15dba5e 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/metric/MetricDtoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/metric/MetricDtoTest.java @@ -57,7 +57,7 @@ public class MetricDtoTest { assertThat(metricDto.getWorstValue()).isEqualTo(0d); assertThat(metricDto.getBestValue()).isEqualTo(100d); assertThat(metricDto.isOptimizedBestValue()).isTrue(); - assertThat(metricDto.getDirection()).isEqualTo(1); + assertThat(metricDto.getDirection()).isOne(); assertThat(metricDto.isHidden()).isTrue(); assertThat(metricDto.isDeleteHistoricalData()).isTrue(); assertThat(metricDto.isEnabled()).isTrue(); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/notification/NotificationQueueDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/notification/NotificationQueueDaoTest.java index db21cc0ce02..a07409eef7c 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/notification/NotificationQueueDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/notification/NotificationQueueDaoTest.java @@ -51,7 +51,7 @@ public class NotificationQueueDaoTest { dao.insert(Arrays.asList(notificationQueueDto)); - assertThat(dao.count()).isEqualTo(1); + assertThat(dao.count()).isOne(); assertThat(dao.selectOldest(1).get(0).toNotification().getType()).isEqualTo("email"); } @@ -63,7 +63,7 @@ public class NotificationQueueDaoTest { dao.insert(Arrays.asList(notificationQueueDto)); - assertThat(dao.count()).isEqualTo(1); + assertThat(dao.count()).isOne(); } @Test diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/GroupPermissionDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/GroupPermissionDaoTest.java index 77aeec19786..aab2045957f 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/GroupPermissionDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/GroupPermissionDaoTest.java @@ -173,13 +173,13 @@ public class GroupPermissionDaoTest { assertThat(underTest.countGroupsByQuery(dbSession, newQuery().build())).isEqualTo(4); assertThat(underTest.countGroupsByQuery(dbSession, - newQuery().setPermission(PROVISION_PROJECTS.getKey()).build())).isEqualTo(1); + newQuery().setPermission(PROVISION_PROJECTS.getKey()).build())).isOne(); assertThat(underTest.countGroupsByQuery(dbSession, newQuery().withAtLeastOnePermission().build())).isEqualTo(2); assertThat(underTest.countGroupsByQuery(dbSession, newQuery().setSearchQuery("Group-").build())).isEqualTo(3); assertThat(underTest.countGroupsByQuery(dbSession, - newQuery().setSearchQuery("Any").build())).isEqualTo(1); + newQuery().setSearchQuery("Any").build())).isOne(); } @Test @@ -701,7 +701,7 @@ public class GroupPermissionDaoTest { int deletedCount = underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, null, project); - assertThat(deletedCount).isEqualTo(1); + assertThat(deletedCount).isOne(); assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, null, project.uuid())) .isEmpty(); assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, group.getUuid(), project.uuid())) @@ -739,7 +739,7 @@ public class GroupPermissionDaoTest { int deletedCount = underTest.deleteByRootComponentUuidAndGroupUuid(dbSession, group1.getUuid(), project); - assertThat(deletedCount).isEqualTo(1); + assertThat(deletedCount).isOne(); assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, null, project.uuid())) .containsOnly("p1"); assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, group1.getUuid(), project.uuid())) diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/template/GroupWithPermissionTemplateDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/template/GroupWithPermissionTemplateDaoTest.java index dcac233f428..98b419bcd29 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/template/GroupWithPermissionTemplateDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/template/GroupWithPermissionTemplateDaoTest.java @@ -103,9 +103,7 @@ public class GroupWithPermissionTemplateDaoTest { @Test public void selectGroupNamesByQueryAndTemplate_is_order_by_groups_with_permission_then_by_name_when_many_groups() { PermissionTemplateDto template = permissionTemplateDbTester.insertTemplate(); - IntStream.rangeClosed(1, DEFAULT_PAGE_SIZE + 1).forEach(i -> { - db.users().insertGroup("Group-" + i); - }); + IntStream.rangeClosed(1, DEFAULT_PAGE_SIZE + 1).forEach(i -> db.users().insertGroup("Group-" + i)); String lastGroupName = "Group-" + (DEFAULT_PAGE_SIZE + 1); permissionTemplateDbTester.addGroupToTemplate(template, db.users().selectGroup(lastGroupName).get(), UserRole.USER); @@ -177,15 +175,15 @@ public class GroupWithPermissionTemplateDaoTest { .isEqualTo(4); assertThat(countGroupNamesByQueryAndTemplate(builder().withAtLeastOnePermission(), template)) .isEqualTo(2); - assertThat(countGroupNamesByQueryAndTemplate(builder().setPermission(USER), template)).isEqualTo(1); + assertThat(countGroupNamesByQueryAndTemplate(builder().setPermission(USER), template)).isOne(); assertThat(countGroupNamesByQueryAndTemplate(builder().setPermission(USER), anotherTemplate)) - .isEqualTo(1); + .isOne(); assertThat(countGroupNamesByQueryAndTemplate(builder().setSearchQuery("groU"), template)) .isEqualTo(3); assertThat(countGroupNamesByQueryAndTemplate(builder().setSearchQuery("nYo"), template)) - .isEqualTo(1); + .isOne(); assertThat(countGroupNamesByQueryAndTemplate(builder().setSearchQuery("p-2"), template)) - .isEqualTo(1); + .isOne(); assertThat(countGroupNamesByQueryAndTemplate(builder().withAtLeastOnePermission().build(), "123")) .isZero(); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/property/InternalComponentPropertyDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/property/InternalComponentPropertyDtoTest.java index 1089188d382..799e56fcc17 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/property/InternalComponentPropertyDtoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/property/InternalComponentPropertyDtoTest.java @@ -93,6 +93,6 @@ public class InternalComponentPropertyDtoTest { .setCreatedAt(10L) .setUpdatedAt(15L); - assertThat(underTest.toString()).isEqualTo("InternalComponentPropertyDto{uuid=uuid1, key=key1, value=value1, componentUuid=component1, updatedAt=15, createdAt=10}"); + assertThat(underTest).hasToString("InternalComponentPropertyDto{uuid=uuid1, key=key1, value=value1, componentUuid=component1, updatedAt=15, createdAt=10}"); } } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertyDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertyDtoTest.java index 28372586bbb..5fd21c24f13 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertyDtoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertyDtoTest.java @@ -33,7 +33,7 @@ public class PropertyDtoTest { public void testEquals() { assertThat(new PropertyDto().setKey("123").setComponentUuid("uuid123")).isEqualTo(new PropertyDto().setKey("123").setComponentUuid("uuid123")); assertThat(new PropertyDto().setKey("1234").setComponentUuid("uuid123")).isNotEqualTo(new PropertyDto().setKey("123").setComponentUuid("uuid123")); - assertThat(new PropertyDto().setKey("1234").setComponentUuid("uuid123")).isNotEqualTo(null); + assertThat(new PropertyDto().setKey("1234").setComponentUuid("uuid123")).isNotNull(); assertThat(new PropertyDto().setKey("1234").setComponentUuid("uuid123")).isNotEqualTo(new Object()); } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java index f0851b0858c..a5c5ddf86bd 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java @@ -199,10 +199,10 @@ public class PurgeCommandsTest { underTest.deleteComponents(component.uuid()); assertThat(dbTester.countRowsOfTable("components")).isZero(); - assertThat(dbTester.countRowsOfTable("snapshots")).isEqualTo(1); - assertThat(dbTester.countRowsOfTable("events")).isEqualTo(1); - assertThat(dbTester.countRowsOfTable("issues")).isEqualTo(1); - assertThat(dbTester.countRowsOfTable("issue_changes")).isEqualTo(1); + assertThat(dbTester.countRowsOfTable("snapshots")).isOne(); + assertThat(dbTester.countRowsOfTable("events")).isOne(); + assertThat(dbTester.countRowsOfTable("issues")).isOne(); + assertThat(dbTester.countRowsOfTable("issue_changes")).isOne(); } @Test @@ -222,10 +222,10 @@ public class PurgeCommandsTest { assertThat(dbTester.countRowsOfTable("projects")).isZero(); assertThat(dbTester.countRowsOfTable("components")).isZero(); - assertThat(dbTester.countRowsOfTable("snapshots")).isEqualTo(1); - assertThat(dbTester.countRowsOfTable("events")).isEqualTo(1); - assertThat(dbTester.countRowsOfTable("issues")).isEqualTo(1); - assertThat(dbTester.countRowsOfTable("issue_changes")).isEqualTo(1); + assertThat(dbTester.countRowsOfTable("snapshots")).isOne(); + assertThat(dbTester.countRowsOfTable("events")).isOne(); + assertThat(dbTester.countRowsOfTable("issues")).isOne(); + assertThat(dbTester.countRowsOfTable("issue_changes")).isOne(); } @Test @@ -359,14 +359,14 @@ public class PurgeCommandsTest { underTest.deleteAbortedAnalyses(projectOrView.uuid()); - assertThat(countAnalysesOfRoot(projectOrView, STATUS_UNPROCESSED, true)).isEqualTo(1); + assertThat(countAnalysesOfRoot(projectOrView, STATUS_UNPROCESSED, true)).isOne(); assertThat(countAnalysesOfRoot(projectOrView, STATUS_UNPROCESSED, false)).isZero(); - assertThat(countAnalysesOfRoot(projectOrView, STATUS_PROCESSED, true)).isEqualTo(1); - assertThat(countAnalysesOfRoot(projectOrView, STATUS_PROCESSED, false)).isEqualTo(1); - assertThat(countAnalysesOfRoot(otherProject, STATUS_UNPROCESSED, true)).isEqualTo(1); - assertThat(countAnalysesOfRoot(otherProject, STATUS_UNPROCESSED, false)).isEqualTo(1); - assertThat(countAnalysesOfRoot(otherProject, STATUS_PROCESSED, true)).isEqualTo(1); - assertThat(countAnalysesOfRoot(otherProject, STATUS_PROCESSED, false)).isEqualTo(1); + assertThat(countAnalysesOfRoot(projectOrView, STATUS_PROCESSED, true)).isOne(); + assertThat(countAnalysesOfRoot(projectOrView, STATUS_PROCESSED, false)).isOne(); + assertThat(countAnalysesOfRoot(otherProject, STATUS_UNPROCESSED, true)).isOne(); + assertThat(countAnalysesOfRoot(otherProject, STATUS_UNPROCESSED, false)).isOne(); + assertThat(countAnalysesOfRoot(otherProject, STATUS_PROCESSED, true)).isOne(); + assertThat(countAnalysesOfRoot(otherProject, STATUS_PROCESSED, false)).isOne(); } @Test @@ -543,7 +543,7 @@ public class PurgeCommandsTest { purgeCommands.deletePermissions(project.uuid()); assertThat(dbTester.countRowsOfTable("group_roles")).isEqualTo(2); - assertThat(dbTester.countRowsOfTable("user_roles")).isEqualTo(1); + assertThat(dbTester.countRowsOfTable("user_roles")).isOne(); } @Test @@ -554,8 +554,8 @@ public class PurgeCommandsTest { PurgeCommands purgeCommands = new PurgeCommands(dbTester.getSession(), profiler, system2); purgeCommands.deletePermissions(project.uuid()); - assertThat(dbTester.countRowsOfTable("group_roles")).isEqualTo(1); - assertThat(dbTester.countRowsOfTable("user_roles")).isEqualTo(1); + assertThat(dbTester.countRowsOfTable("group_roles")).isOne(); + assertThat(dbTester.countRowsOfTable("user_roles")).isOne(); } @Test @@ -567,7 +567,7 @@ public class PurgeCommandsTest { purgeCommands.deletePermissions(project.uuid()); assertThat(dbTester.countRowsOfTable("group_roles")).isEqualTo(2); - assertThat(dbTester.countRowsOfTable("user_roles")).isEqualTo(1); + assertThat(dbTester.countRowsOfTable("user_roles")).isOne(); } @Test @@ -611,7 +611,7 @@ public class PurgeCommandsTest { purgeCommands.deleteNewCodePeriods(project.uuid()); // should delete branch and project settings only - assertThat(dbTester.countRowsOfTable("new_code_periods")).isEqualTo(1); + assertThat(dbTester.countRowsOfTable("new_code_periods")).isOne(); } @Test @@ -649,7 +649,7 @@ public class PurgeCommandsTest { purgeCommands.deleteUserDismissedMessages(project.getUuid()); - assertThat(dbTester.countRowsOfTable("user_dismissed_messages")).isEqualTo(1); + assertThat(dbTester.countRowsOfTable("user_dismissed_messages")).isOne(); } @Test diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java index f2566237fe2..80238ce0ae5 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java @@ -285,7 +285,7 @@ public class PurgeDaoTest { verify(purgeListener).onComponentsDisabling(project.uuid(), ImmutableSet.of(dir.uuid())); // set purge_status=1 for non-last snapshot - assertThat(db.countSql("select count(*) from snapshots where purge_status = 1")).isEqualTo(1); + assertThat(db.countSql("select count(*) from snapshots where purge_status = 1")).isOne(); // close open issues of selected assertThat(db.countSql("select count(*) from issues where status = 'CLOSED'")).isEqualTo(4); @@ -301,7 +301,7 @@ public class PurgeDaoTest { } // delete file sources of selected - assertThat(db.countRowsOfTable("file_sources")).isEqualTo(1); + assertThat(db.countRowsOfTable("file_sources")).isOne(); assertThat(db.getDbClient().fileSourceDao().selectByFileUuid(dbSession, nonSelectedFileSource.getFileUuid())).isNotNull(); // deletes live measure of selected @@ -369,7 +369,7 @@ public class PurgeDaoTest { assertThat(uuidsIn("event_component_changes", "event_analysis_uuid")) .containsOnly(projectAnalysis2.getUuid()); assertThat(db.countRowsOfTable("event_component_changes")) - .isEqualTo(1); + .isOne(); assertThat(uuidsIn("events")) .containsOnly(projectEvent2.getUuid(), projectEvent3.getUuid()); @@ -377,7 +377,7 @@ public class PurgeDaoTest { assertThat(uuidsIn("event_component_changes", "event_analysis_uuid")) .containsOnly(projectAnalysis2.getUuid()); assertThat(db.countRowsOfTable("event_component_changes")) - .isEqualTo(1); + .isOne(); assertThat(uuidsIn("events")) .containsOnly(projectEvent2.getUuid(), projectEvent3.getUuid()); @@ -385,7 +385,7 @@ public class PurgeDaoTest { assertThat(uuidsIn("event_component_changes", "event_analysis_uuid")) .containsOnly(projectAnalysis2.getUuid()); assertThat(db.countRowsOfTable("event_component_changes")) - .isEqualTo(1); + .isOne(); assertThat(uuidsIn("events")) .containsOnly(projectEvent2.getUuid()); @@ -833,7 +833,7 @@ public class PurgeDaoTest { underTest.deleteProject(dbSession, projectToBeDeleted.uuid(), projectToBeDeleted.qualifier(), projectToBeDeleted.name(), projectToBeDeleted.getKey()); dbSession.commit(); - assertThat(db.countRowsOfTable("ce_queue")).isEqualTo(1); + assertThat(db.countRowsOfTable("ce_queue")).isOne(); assertThat(db.countSql("select count(*) from ce_queue where main_component_uuid='" + projectToBeDeleted.uuid() + "'")).isZero(); } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeableAnalysisDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeableAnalysisDtoTest.java index 4905705ce2c..37e360e8747 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeableAnalysisDtoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeableAnalysisDtoTest.java @@ -41,7 +41,6 @@ public class PurgeableAnalysisDtoTest { @Test public void testHasCode() { PurgeableAnalysisDto dto = new PurgeableAnalysisDto().setAnalysisUuid("u3"); - assertThat(dto.hashCode()).isEqualTo(dto.hashCode()); // no uuid => NPE dto = new PurgeableAnalysisDto(); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/period/IntervalTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/period/IntervalTest.java index 2b314333bf6..ab9acbc02e8 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/period/IntervalTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/period/IntervalTest.java @@ -59,7 +59,7 @@ public class IntervalTest { List<Interval> intervals = Interval.group(snapshots, DateUtils.parseDate("2010-01-01"), DateUtils.parseDate("2011-12-31"), Calendar.MONTH); assertThat(intervals.size()).isEqualTo(3); - assertThat(intervals.get(0).count()).isEqualTo(1); + assertThat(intervals.get(0).count()).isOne(); assertThat(calendarField(intervals.get(0), Calendar.MONTH)).isEqualTo((Calendar.APRIL)); assertThat(intervals.get(1).count()).isEqualTo(2); @@ -80,11 +80,11 @@ public class IntervalTest { DateUtils.parseDateTime("2010-01-01T00:00:00+0100"), DateUtils.parseDateTime("2011-12-31T00:00:00+0100"), Calendar.MONTH); assertThat(intervals.size()).isEqualTo(2); - assertThat(intervals.get(0).count()).isEqualTo(1); + assertThat(intervals.get(0).count()).isOne(); assertThat(calendarField(intervals.get(0), Calendar.MONTH)).isEqualTo((Calendar.APRIL)); assertThat(calendarField(intervals.get(0), Calendar.YEAR)).isEqualTo((2010)); - assertThat(intervals.get(1).count()).isEqualTo(1); + assertThat(intervals.get(1).count()).isOne(); assertThat(calendarField(intervals.get(1), Calendar.MONTH)).isEqualTo((Calendar.APRIL)); assertThat(calendarField(intervals.get(1), Calendar.YEAR)).isEqualTo((2011)); } @@ -100,8 +100,8 @@ public class IntervalTest { List<Interval> intervals = Interval.group(snapshots, DateUtils.parseDateTime("2011-05-25T00:00:00+0100"), DateUtils.parseDateTime("2012-01-26T00:00:00+0100"), Calendar.MONTH); - assertThat(intervals.size()).isEqualTo(1); - assertThat(intervals.get(0).count()).isEqualTo(1); + assertThat(intervals.size()).isOne(); + assertThat(intervals.get(0).count()).isOne(); assertThat(intervals.get(0).get().get(0).getAnalysisUuid()).isEqualTo(("u2")); } } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/period/KeepOneFilterTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/period/KeepOneFilterTest.java index ef2dfd7329a..645ef2246a7 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/period/KeepOneFilterTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/period/KeepOneFilterTest.java @@ -33,7 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat; public class KeepOneFilterTest { private static List<String> analysisUuids(List<PurgeableAnalysisDto> snapshotDtos) { - return snapshotDtos.stream().map(input -> input.getAnalysisUuid()).collect(Collectors.toList()); + return snapshotDtos.stream().map(PurgeableAnalysisDto::getAnalysisUuid).collect(Collectors.toList()); } @Test diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/ProjectQgateAssociationDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/ProjectQgateAssociationDaoTest.java index 594f3ec87df..bf807721f8f 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/ProjectQgateAssociationDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/ProjectQgateAssociationDaoTest.java @@ -151,7 +151,7 @@ public class ProjectQgateAssociationDaoTest { Optional<String> result = underTest.selectQGateUuidByProjectUuid(dbSession, project.uuid()); - assertThat(result.isPresent()).isFalse(); + assertThat(result).isEmpty(); } @Test diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/QualityGateGroupPermissionsDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/QualityGateGroupPermissionsDaoTest.java index d76815dc5a9..b07083fa5ce 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/QualityGateGroupPermissionsDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/QualityGateGroupPermissionsDaoTest.java @@ -121,7 +121,7 @@ public class QualityGateGroupPermissionsDaoTest { assertThat(underTest.countByQuery(dbSession, builder() .setQualityGate(qualityGateDto) .setMembership(OUT).build())) - .isEqualTo(1); + .isOne(); } @Test diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/QualityGateUserPermissionsDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/QualityGateUserPermissionsDaoTest.java index 8cf82da9ef1..327f87cab84 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/QualityGateUserPermissionsDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/QualityGateUserPermissionsDaoTest.java @@ -120,7 +120,7 @@ public class QualityGateUserPermissionsDaoTest { assertThat(underTest.countByQuery(db.getSession(), builder() .setQualityGate(qualityGate) .setMembership(OUT).build())) - .isEqualTo(1); + .isOne(); } @Test diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java index 5126294af22..9c74633b3bd 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java @@ -374,7 +374,7 @@ public class ActiveRuleDaoTest { underTest.deleteByRuleProfileUuids(dbSession, singletonList(profile1.getRulesProfileUuid())); - assertThat(db.countRowsOfTable(dbSession, "active_rules")).isEqualTo(1); + assertThat(db.countRowsOfTable(dbSession, "active_rules")).isOne(); assertThat(underTest.selectByKey(dbSession, ActiveRuleKey.of(profile2, rule1.getKey()))).isPresent(); } @@ -384,7 +384,7 @@ public class ActiveRuleDaoTest { underTest.deleteByRuleProfileUuids(dbSession, singletonList("does_not_exist")); - assertThat(db.countRowsOfTable(dbSession, "active_rules")).isEqualTo(1); + assertThat(db.countRowsOfTable(dbSession, "active_rules")).isOne(); } @Test @@ -395,7 +395,7 @@ public class ActiveRuleDaoTest { underTest.deleteByUuids(dbSession, asList(ar1.getUuid(), ar3.getUuid())); - assertThat(db.countRowsOfTable(dbSession, "active_rules")).isEqualTo(1); + assertThat(db.countRowsOfTable(dbSession, "active_rules")).isOne(); assertThat(underTest.selectByProfile(dbSession, profile1)) .extracting(ActiveRuleDto::getUuid) .containsExactly(ar2.getUuid()); @@ -407,7 +407,7 @@ public class ActiveRuleDaoTest { underTest.deleteByUuids(dbSession, emptyList()); - assertThat(db.countRowsOfTable(dbSession, "active_rules")).isEqualTo(1); + assertThat(db.countRowsOfTable(dbSession, "active_rules")).isOne(); } private static ActiveRuleDto newRow(QProfileDto profile, RuleDefinitionDto rule) { diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleKeyTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleKeyTest.java index 42ed856bc4f..256f1aa5434 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleKeyTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleKeyTest.java @@ -79,6 +79,6 @@ public class ActiveRuleKeyTest { assertThat(key1.equals(key2)).isFalse(); assertThat(key1.equals(key3)).isFalse(); - assertThat(key1.hashCode()).isEqualTo(key1.hashCode()); + assertThat(key1).hasSameHashCodeAs(key1); } } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleParamDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleParamDtoTest.java index 0c2b13ab3bd..9706d29792e 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleParamDtoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleParamDtoTest.java @@ -37,6 +37,6 @@ public class ActiveRuleParamDtoTest { new ActiveRuleParamDto().setKey("foo"), new ActiveRuleParamDto().setKey("bar") ); Map<String, ActiveRuleParamDto> group = ActiveRuleParamDto.groupByKey(dtos); - assertThat(group.keySet()).containsOnly("foo", "bar"); + assertThat(group).containsOnlyKeys("foo", "bar"); } } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/DefaultQProfileDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/DefaultQProfileDaoTest.java index 81bbf2912e5..2c763ec85b9 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/DefaultQProfileDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/DefaultQProfileDaoTest.java @@ -48,7 +48,7 @@ public class DefaultQProfileDaoTest { underTest.insertOrUpdate(dbSession, dto); dbSession.commit(); - assertThat(countRows()).isEqualTo(1); + assertThat(countRows()).isOne(); assertThatIsDefault(profile); } @@ -66,7 +66,7 @@ public class DefaultQProfileDaoTest { underTest.insertOrUpdate(dbSession, dto); dbSession.commit(); - assertThat(countRows()).isEqualTo(1); + assertThat(countRows()).isOne(); assertThat(selectUuidOfDefaultProfile(dto.getLanguage())).hasValue(newQProfileUuid); } @@ -78,7 +78,7 @@ public class DefaultQProfileDaoTest { .setQProfileUuid(previousQProfileUuid); underTest.insert(dbSession, dto); dbSession.commit(); - assertThat(countRows()).isEqualTo(1); + assertThat(countRows()).isOne(); assertThat(selectUuidOfDefaultProfile(dto.getLanguage())).hasValue(dto.getQProfileUuid()); } @@ -90,7 +90,7 @@ public class DefaultQProfileDaoTest { underTest.deleteByQProfileUuids(dbSession, asList("u1", "u3")); dbSession.commit(); - assertThat(countRows()).isEqualTo(1); + assertThat(countRows()).isOne(); assertThat(selectUuidOfDefaultProfile("java")).isEmpty(); assertThat(selectUuidOfDefaultProfile("js")).hasValue("u2"); } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QProfileChangeDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QProfileChangeDaoTest.java index cd49fca93ca..b725275fedb 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QProfileChangeDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QProfileChangeDaoTest.java @@ -194,7 +194,7 @@ public class QProfileChangeDaoTest { long end = system2.now(); assertThat(underTest.countByQuery(dbSession, new QProfileChangeQuery(profile1.getKee()))).isEqualTo(2); - assertThat(underTest.countByQuery(dbSession, new QProfileChangeQuery(profile2.getKee()))).isEqualTo(1); + assertThat(underTest.countByQuery(dbSession, new QProfileChangeQuery(profile2.getKee()))).isOne(); assertThat(underTest.countByQuery(dbSession, new QProfileChangeQuery("does_not_exist"))).isZero(); QProfileChangeQuery query = new QProfileChangeQuery(profile1.getKee()); @@ -217,7 +217,7 @@ public class QProfileChangeDaoTest { underTest.deleteByRulesProfileUuids(dbSession, asList(profile1.getRulesProfileUuid())); assertThat(underTest.countByQuery(dbSession, new QProfileChangeQuery(profile1.getKee()))).isZero(); - assertThat(underTest.countByQuery(dbSession, new QProfileChangeQuery(profile2.getKee()))).isEqualTo(1); + assertThat(underTest.countByQuery(dbSession, new QProfileChangeQuery(profile2.getKee()))).isOne(); } @Test @@ -227,7 +227,7 @@ public class QProfileChangeDaoTest { underTest.deleteByRulesProfileUuids(dbSession, asList("does not exist")); - assertThat(underTest.countByQuery(dbSession, new QProfileChangeQuery(profile1.getKee()))).isEqualTo(1); + assertThat(underTest.countByQuery(dbSession, new QProfileChangeQuery(profile1.getKee()))).isOne(); } private QProfileChangeDto insertChange(QProfileDto profile, String type, @Nullable String login, @Nullable String data) { diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QProfileEditGroupsDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QProfileEditGroupsDaoTest.java index 919f596e8fd..724b0a66a82 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QProfileEditGroupsDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QProfileEditGroupsDaoTest.java @@ -100,7 +100,7 @@ public class QProfileEditGroupsDaoTest { assertThat(underTest.countByQuery(db.getSession(), builder() .setProfile(profile) .setMembership(OUT).build())) - .isEqualTo(1); + .isOne(); } @Test diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QProfileEditUsersDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QProfileEditUsersDaoTest.java index 05df576f38b..4b9ec4e3ecb 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QProfileEditUsersDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QProfileEditUsersDaoTest.java @@ -105,7 +105,7 @@ public class QProfileEditUsersDaoTest { assertThat(underTest.countByQuery(db.getSession(), builder() .setProfile(profile) .setMembership(OUT).build())) - .isEqualTo(1); + .isOne(); } @Test diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java index 0f0abc2178c..d3c4c9d2a08 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java @@ -146,7 +146,7 @@ public class QualityProfileDaoTest { int count = underTest.updateLastUsedDate(dbSession, initial, 15_000L); - assertThat(count).isEqualTo(1); + assertThat(count).isOne(); QProfileDto reloaded = underTest.selectByUuid(dbSession, initial.getKee()); assertThat(reloaded).isNotNull(); assertThat(reloaded.getLastUsed()).isEqualTo(15_000L); @@ -160,7 +160,7 @@ public class QualityProfileDaoTest { int count = underTest.updateLastUsedDate(dbSession, initial, 15_000L); - assertThat(count).isEqualTo(1); + assertThat(count).isOne(); QProfileDto reloaded = underTest.selectByUuid(dbSession, initial.getKee()); assertThat(reloaded).isNotNull(); assertThat(reloaded.getLastUsed()).isEqualTo(15_000L); @@ -206,7 +206,7 @@ public class QualityProfileDaoTest { underTest.deleteRulesProfilesByUuids(dbSession, emptyList()); - assertThat(db.countRowsOfTable(dbSession, "rules_profiles")).isEqualTo(1); + assertThat(db.countRowsOfTable(dbSession, "rules_profiles")).isOne(); } @Test @@ -215,7 +215,7 @@ public class QualityProfileDaoTest { underTest.deleteRulesProfilesByUuids(dbSession, singletonList("does_not_exist")); - assertThat(db.countRowsOfTable(dbSession, "rules_profiles")).isEqualTo(1); + assertThat(db.countRowsOfTable(dbSession, "rules_profiles")).isOne(); } private RulesProfileDto insertRulesProfile() { @@ -258,7 +258,7 @@ public class QualityProfileDaoTest { underTest.deleteProjectAssociationsByProfileUuids(dbSession, Collections.emptyList()); - assertThat(db.countRowsOfTable(dbSession, "project_qprofiles")).isEqualTo(1); + assertThat(db.countRowsOfTable(dbSession, "project_qprofiles")).isOne(); } @Test diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDaoTest.java index 0aa60519e8b..288a8c07d6f 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDaoTest.java @@ -97,7 +97,7 @@ public class RuleDaoTest { public void selectDefinitionByKey() { RuleDefinitionDto rule = db.rules().insert(); - assertThat(underTest.selectDefinitionByKey(db.getSession(), RuleKey.of("NOT", "FOUND")).isPresent()).isFalse(); + assertThat(underTest.selectDefinitionByKey(db.getSession(), RuleKey.of("NOT", "FOUND"))).isEmpty(); Optional<RuleDefinitionDto> reloaded = underTest.selectDefinitionByKey(db.getSession(), rule.getKey()); assertThat(reloaded).isPresent(); @@ -298,7 +298,7 @@ public class RuleDaoTest { ResultHandler<RuleDefinitionDto> resultHandler = resultContext -> rules.add(resultContext.getResultObject()); underTest.selectEnabled(db.getSession(), resultHandler); - assertThat(rules.size()).isEqualTo(1); + assertThat(rules.size()).isOne(); RuleDefinitionDto ruleDto = rules.get(0); assertThat(ruleDto.getUuid()).isEqualTo(rule.getUuid()); } @@ -610,7 +610,7 @@ public class RuleDaoTest { underTest.insertOrUpdate(db.getSession(), metadataV1); db.commit(); - assertThat(db.countRowsOfTable("RULES_METADATA")).isEqualTo(1); + assertThat(db.countRowsOfTable("RULES_METADATA")).isOne(); RuleDto ruleDto = underTest.selectOrFailByKey(db.getSession(), rule.getKey()); assertThat(ruleDto.getNoteData()).isNull(); assertThat(ruleDto.getNoteUserUuid()).isNull(); @@ -676,7 +676,7 @@ public class RuleDaoTest { List<RuleParamDto> ruleDtos = underTest.selectRuleParamsByRuleKey(db.getSession(), rule.getKey()); - assertThat(ruleDtos.size()).isEqualTo(1); + assertThat(ruleDtos.size()).isOne(); RuleParamDto ruleDto = ruleDtos.get(0); assertThat(ruleDto.getUuid()).isEqualTo(ruleParam.getUuid()); assertThat(ruleDto.getName()).isEqualTo(ruleParam.getName()); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDefinitionDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDefinitionDtoTest.java index 1080e43b22e..cb27398ea37 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDefinitionDtoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDefinitionDtoTest.java @@ -32,13 +32,14 @@ public class RuleDefinitionDtoTest { String uuid = Uuids.createFast(); RuleDefinitionDto dto = newRule().setUuid(uuid); - assertThat(dto).isEqualTo(dto); - assertThat(dto).isEqualTo(newRule().setUuid(uuid)); - assertThat(dto).isEqualTo(newRule().setRuleKey(dto.getRuleKey()).setUuid(uuid)); - assertThat(dto).isNotEqualTo(null); - assertThat(dto).isNotEqualTo(new Object()); - assertThat(dto).isNotEqualTo(newRule().setRuleKey(dto.getRuleKey()).setUuid(Uuids.createFast())); - assertThat(dto).isNotEqualTo(newRule().setUuid(Uuids.createFast())); + assertThat(dto) + .isEqualTo(dto) + .isEqualTo(newRule().setUuid(uuid)) + .isEqualTo(newRule().setRuleKey(dto.getRuleKey()).setUuid(uuid)) + .isNotNull() + .isNotEqualTo(new Object()) + .isNotEqualTo(newRule().setRuleKey(dto.getRuleKey()).setUuid(Uuids.createFast())) + .isNotEqualTo(newRule().setUuid(Uuids.createFast())); } @Test @@ -46,12 +47,13 @@ public class RuleDefinitionDtoTest { String uuid = Uuids.createFast(); RuleDefinitionDto dto = newRule().setUuid(uuid); - assertThat(dto.hashCode()).isEqualTo(dto.hashCode()); - assertThat(dto.hashCode()).isEqualTo(newRule().setUuid(uuid).hashCode()); - assertThat(dto.hashCode()).isEqualTo(newRule().setRuleKey(dto.getRuleKey()).setUuid(uuid).hashCode()); - assertThat(dto.hashCode()).isNotEqualTo(null); - assertThat(dto.hashCode()).isNotEqualTo(new Object().hashCode()); - assertThat(dto.hashCode()).isNotEqualTo(newRule().setRuleKey(dto.getRuleKey()).setUuid(Uuids.createFast()).hashCode()); - assertThat(dto.hashCode()).isNotEqualTo(newRule().setUuid(Uuids.createFast()).hashCode()); + assertThat(dto) + .hasSameHashCodeAs(dto) + .hasSameHashCodeAs(newRule().setUuid(uuid)) + .hasSameHashCodeAs(newRule().setRuleKey(dto.getRuleKey()).setUuid(uuid)); + assertThat(dto.hashCode()) + .isNotEqualTo(new Object().hashCode()) + .isNotEqualTo(newRule().setRuleKey(dto.getRuleKey()).setUuid(Uuids.createFast()).hashCode()) + .isNotEqualTo(newRule().setUuid(Uuids.createFast()).hashCode()); } } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/source/FileSourceDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/source/FileSourceDaoTest.java index ddd107ce125..b60ae0ecf58 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/source/FileSourceDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/source/FileSourceDaoTest.java @@ -304,7 +304,7 @@ public class FileSourceDaoTest { assertThat(fileSourceDto.getDataHash()).isEqualTo("NEW_DATA_HASH"); assertThat(fileSourceDto.getRawLineHashes()).isEqualTo("NEW_LINE_HASHES"); assertThat(fileSourceDto.getLineHashes()).isEqualTo(singletonList("NEW_LINE_HASHES")); - assertThat(fileSourceDto.getLineCount()).isEqualTo(1); + assertThat(fileSourceDto.getLineCount()).isOne(); assertThat(fileSourceDto.getSrcHash()).isEqualTo("NEW_FILE_HASH"); assertThat(fileSourceDto.getCreatedAt()).isEqualTo(expected.getCreatedAt()); assertThat(fileSourceDto.getUpdatedAt()).isEqualTo(1500000000002L); @@ -335,6 +335,6 @@ public class FileSourceDaoTest { FileSourceDto res = underTest.selectByFileUuid(dbSession, fileSourceDto.getFileUuid()); assertThat(res.getLineHashes()).isEmpty(); - assertThat(res.getLineCount()).isEqualTo(1); + assertThat(res.getLineCount()).isOne(); } } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/source/FileSourceDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/source/FileSourceDtoTest.java index ae89e31d7bc..6c0f8f8c1bb 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/source/FileSourceDtoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/source/FileSourceDtoTest.java @@ -100,7 +100,7 @@ public class FileSourceDtoTest { FileSourceDto underTest = new FileSourceDto(); underTest.setLineHashes(Collections.emptyList()); - assertThat(underTest.getLineCount()).isEqualTo(1); + assertThat(underTest.getLineCount()).isOne(); assertThat(underTest.getLineHashes()).isEmpty(); assertThat(underTest.getRawLineHashes()).isNull(); } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/user/GroupDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/user/GroupDaoTest.java index a7602c17fa3..45301c533a7 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/user/GroupDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/user/GroupDaoTest.java @@ -189,7 +189,7 @@ public class GroupDaoTest { assertThat(result).hasSize(1); assertThat(result.get(0).getName()).isEqualTo(groupNameWithSpecialCharacters); - assertThat(resultCount).isEqualTo(1); + assertThat(resultCount).isOne(); } @Test diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/user/GroupMembershipDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/user/GroupMembershipDaoTest.java index d8c9c95b43a..f882c972241 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/user/GroupMembershipDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/user/GroupMembershipDaoTest.java @@ -69,7 +69,7 @@ public class GroupMembershipDaoTest { assertThat(underTest.countGroups(db.getSession(), builder().membership(IN).build(), user1.getUuid())).isEqualTo(3); assertThat(underTest.countGroups(db.getSession(), builder().membership(OUT).build(), user1.getUuid())).isZero(); // user2 is member of 1 group on 3 - assertThat(underTest.countGroups(db.getSession(), builder().membership(IN).build(), user2.getUuid())).isEqualTo(1); + assertThat(underTest.countGroups(db.getSession(), builder().membership(IN).build(), user2.getUuid())).isOne(); assertThat(underTest.countGroups(db.getSession(), builder().membership(OUT).build(), user2.getUuid())).isEqualTo(2); // user3 is member of 0 group assertThat(underTest.countGroups(db.getSession(), builder().membership(IN).build(), user3.getUuid())).isZero(); @@ -137,14 +137,14 @@ public class GroupMembershipDaoTest { db.users().insertMember(group2, user2); // 100 has 1 member and 1 non member - assertThat(underTest.countMembers(db.getSession(), newQuery().groupUuid(group1.getUuid()).membership(UserMembershipQuery.IN).build())).isEqualTo(1); - assertThat(underTest.countMembers(db.getSession(), newQuery().groupUuid(group1.getUuid()).membership(UserMembershipQuery.OUT).build())).isEqualTo(1); + assertThat(underTest.countMembers(db.getSession(), newQuery().groupUuid(group1.getUuid()).membership(UserMembershipQuery.IN).build())).isOne(); + assertThat(underTest.countMembers(db.getSession(), newQuery().groupUuid(group1.getUuid()).membership(UserMembershipQuery.OUT).build())).isOne(); // 101 has 2 members assertThat(underTest.countMembers(db.getSession(), newQuery().groupUuid(group2.getUuid()).membership(UserMembershipQuery.IN).build())).isEqualTo(2); assertThat(underTest.countMembers(db.getSession(), newQuery().groupUuid(group2.getUuid()).membership(UserMembershipQuery.OUT).build())).isZero(); // 102 has 1 member and 1 non member - assertThat(underTest.countMembers(db.getSession(), newQuery().groupUuid(group3.getUuid()).membership(UserMembershipQuery.IN).build())).isEqualTo(1); - assertThat(underTest.countMembers(db.getSession(), newQuery().groupUuid(group3.getUuid()).membership(UserMembershipQuery.OUT).build())).isEqualTo(1); + assertThat(underTest.countMembers(db.getSession(), newQuery().groupUuid(group3.getUuid()).membership(UserMembershipQuery.IN).build())).isOne(); + assertThat(underTest.countMembers(db.getSession(), newQuery().groupUuid(group3.getUuid()).membership(UserMembershipQuery.OUT).build())).isOne(); // 103 has no member assertThat(underTest.countMembers(db.getSession(), newQuery().groupUuid(emptyGroup.getUuid()).membership(UserMembershipQuery.IN).build())).isZero(); assertThat(underTest.countMembers(db.getSession(), newQuery().groupUuid(emptyGroup.getUuid()).membership(UserMembershipQuery.OUT).build())).isEqualTo(2); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDaoTest.java index d727f9a3973..f4733395994 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDaoTest.java @@ -684,8 +684,8 @@ public class UserDaoTest { public void setRoot_set_root_flag_of_specified_user_to_specified_value_and_updates_udpateAt() { String login = insertActiveUser().getLogin(); UserDto otherUser = insertActiveUser(); - assertThat(underTest.selectByLogin(session, login).isRoot()).isEqualTo(false); - assertThat(underTest.selectByLogin(session, otherUser.getLogin()).isRoot()).isEqualTo(false); + assertThat(underTest.selectByLogin(session, login).isRoot()).isFalse(); + assertThat(underTest.selectByLogin(session, otherUser.getLogin()).isRoot()).isFalse(); // does not fail when changing to same value system2.setNow(15_000L); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/webhook/WebhookDeliveryDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/webhook/WebhookDeliveryDaoTest.java index fb2b70c8a7b..9daad8073c6 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/webhook/WebhookDeliveryDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/webhook/WebhookDeliveryDaoTest.java @@ -202,7 +202,7 @@ public class WebhookDeliveryDaoTest { underTest.deleteByWebhook(dbSession, webhookDto); - assertThat(dbTester.countRowsOfTable(dbSession, "webhook_deliveries")).isEqualTo(1); + assertThat(dbTester.countRowsOfTable(dbSession, "webhook_deliveries")).isOne(); } @Test @@ -231,7 +231,7 @@ public class WebhookDeliveryDaoTest { underTest.deleteComponentBeforeDate(dbSession, "COMPONENT_2", 1_500_000L); - assertThat(dbTester.countRowsOfTable(dbSession, "webhook_deliveries")).isEqualTo(1); + assertThat(dbTester.countRowsOfTable(dbSession, "webhook_deliveries")).isOne(); } private void verifyMandatoryFields(WebhookDeliveryDto expected, WebhookDeliveryDto actual) { diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/TestDbImpl.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/TestDbImpl.java index da1e98bf22d..42c1aaab549 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/TestDbImpl.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/TestDbImpl.java @@ -21,7 +21,6 @@ package org.sonar.db; import java.util.Arrays; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Set; import java.util.function.BiConsumer; @@ -57,9 +56,7 @@ class TestDbImpl extends CoreTestDb { } private void init(@Nullable String schemaPath, MyBatisConfExtension[] confExtensions) { - Consumer<Settings> loadOrchestratorSettings = settings -> { - OrchestratorSettingsUtils.loadOrchestratorSettings(settings); - }; + Consumer<Settings> loadOrchestratorSettings = OrchestratorSettingsUtils::loadOrchestratorSettings; Function<Settings, Database> databaseCreator = settings -> { String dialect = settings.getString("sonar.jdbc.dialect"); if (dialect != null && !"h2".equals(dialect)) { diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/ce/CeQueueTesting.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/ce/CeQueueTesting.java index f306496d419..1ced696c144 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/ce/CeQueueTesting.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/ce/CeQueueTesting.java @@ -52,7 +52,7 @@ public class CeQueueTesting { int touchedRows = mapper.updateIf(ceQueueDto.getUuid(), new UpdateIf.NewProperties(IN_PROGRESS, workerUuid, now, now), new UpdateIf.OldProperties(PENDING)); - assertThat(touchedRows).isEqualTo(1); + assertThat(touchedRows).isOne(); }); } @@ -65,7 +65,7 @@ public class CeQueueTesting { int touchedRows = mapper.updateIf(ceQueueDto.getUuid(), new UpdateIf.NewProperties(PENDING, ceQueueDto.getUuid(), now, now), new UpdateIf.OldProperties(IN_PROGRESS)); - assertThat(touchedRows).isEqualTo(1); + assertThat(touchedRows).isOne(); }); } } diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/rule/RuleTesting.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/rule/RuleTesting.java index 85c552ab5b6..8c405f25c88 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/rule/RuleTesting.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/rule/RuleTesting.java @@ -165,7 +165,8 @@ public class RuleTesting { */ @Deprecated public static RuleDto newDto(RuleKey ruleKey) { - RuleDto res = new RuleDto() + + return new RuleDto() .setUuid("uuid_" + Uuids.createFast()) .setRuleKey(ruleKey.rule()) .setRepositoryKey(ruleKey.repository()) @@ -189,8 +190,6 @@ public class RuleTesting { .setTags(ImmutableSet.of("tag1", "tag2")) .setRemediationFunction("LINEAR") .setRemediationGapMultiplier("1h"); - - return res; } /** diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserTesting.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserTesting.java index c1ca8bcef15..93db0abe0fd 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserTesting.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserTesting.java @@ -25,7 +25,6 @@ import org.sonar.core.util.Uuids; import static java.util.Collections.singletonList; import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; import static org.apache.commons.lang.math.RandomUtils.nextBoolean; -import static org.apache.commons.lang.math.RandomUtils.nextInt; import static org.apache.commons.lang.math.RandomUtils.nextLong; public class UserTesting { diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/CreateTableBuilder.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/CreateTableBuilder.java index 752bde2ca81..e0b11211a5c 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/CreateTableBuilder.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/CreateTableBuilder.java @@ -101,7 +101,7 @@ public class CreateTableBuilder { "Auto increment column must either be BigInteger or Integer"); checkArgument(!columnDef.isNullable(), "Auto increment column can't be nullable"); - checkState(pkColumnDefs.stream().filter(this::isAutoIncrement).count() == 0, + checkState(pkColumnDefs.stream().noneMatch(this::isAutoIncrement), "There can't be more than one auto increment column"); } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/charset/SqlExecutorTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/charset/SqlExecutorTest.java index 5d9724021df..ca785ed18c0 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/charset/SqlExecutorTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/charset/SqlExecutorTest.java @@ -64,8 +64,9 @@ public class SqlExecutorTest { underTest.executeDdl(connection, "update users set " + NAME_DB_COLUMN + "='new name' where " + LOGIN_DB_COLUMN + "='the_login'"); } Map<String, Object> row = dbTester.selectFirst("select " + NAME_DB_COLUMN + " from users where " + LOGIN_DB_COLUMN + "='the_login'"); - assertThat(row).isNotEmpty(); - assertThat(row.get("NAME")).isEqualTo("new name"); + assertThat(row) + .isNotEmpty() + .containsEntry("NAME", "new name"); } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/engine/MigrationContainerImplTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/engine/MigrationContainerImplTest.java index 6999698b56e..67ac64eede9 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/engine/MigrationContainerImplTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/engine/MigrationContainerImplTest.java @@ -53,7 +53,7 @@ public class MigrationContainerImplTest { StartCallCounter startCallCounter = underTest.getComponentByType(StartCallCounter.class); assertThat(startCallCounter).isNotNull(); - assertThat(StartCallCounter.startCalls).isEqualTo(1); + assertThat(StartCallCounter.startCalls).isOne(); } @Test diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/CreateTableBuilderDbTesterTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/CreateTableBuilderDbTesterTest.java index 94833cc6ec6..1196fc3d520 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/CreateTableBuilderDbTesterTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/CreateTableBuilderDbTesterTest.java @@ -119,7 +119,7 @@ public class CreateTableBuilderDbTesterTest { Map<String, Object> row = dbTester.selectFirst("select id as \"id\", val as \"val\" from " + tableName); assertThat(row.get("id")).isNotNull(); - assertThat(row.get("val")).isEqualTo("toto"); + assertThat(row).containsEntry("val", "toto"); } private CreateTableBuilder newCreateTableBuilder() { diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/step/DataChangeTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/step/DataChangeTest.java index dc4b92bb1b9..33bd51d868d 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/step/DataChangeTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/step/DataChangeTest.java @@ -523,11 +523,11 @@ public class DataChangeTest { .select("select id as \"ID\", login as \"LOGIN\", age as \"AGE\", enabled as \"ENABLED\", coeff as \"COEFF\", updated_at as \"UPDATED\" from persons where id=" + id); assertThat(rows).describedAs("id=" + id).hasSize(1); Map<String, Object> row = rows.get(0); - assertThat(row.get("ID")).isEqualTo(id); - assertThat(row.get("LOGIN")).isEqualTo(login); - assertThat(row.get("AGE")).isEqualTo(age); - assertThat(row.get("ENABLED")).isEqualTo(enabled); - assertThat(row.get("UPDATED")).isEqualTo(updatedAt == null ? null : dateFormat.parse(updatedAt)); - assertThat(row.get("COEFF")).isEqualTo(coeff); + assertThat(row).containsEntry("ID", id); + assertThat(row).containsEntry("LOGIN", login); + assertThat(row).containsEntry("AGE", age); + assertThat(row).containsEntry("ENABLED", enabled); + assertThat(row).containsEntry("UPDATED", updatedAt == null ? null : dateFormat.parse(updatedAt)); + assertThat(row).containsEntry("COEFF", coeff); } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/step/MigrationStepsImplTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/step/MigrationStepsImplTest.java index f330fc601e0..5d0e98c6824 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/step/MigrationStepsImplTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/step/MigrationStepsImplTest.java @@ -67,7 +67,7 @@ public class MigrationStepsImplTest { @Test public void getMaxMigrationNumber_returns_migration_of_last_step_in_constructor_list_argument() { assertThat(underTest.getMaxMigrationNumber()).isEqualTo(8L); - assertThat(unorderedSteps.getMaxMigrationNumber()).isEqualTo(1L); + assertThat(unorderedSteps.getMaxMigrationNumber()).isOne(); } @Test diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v00/PopulateInitialSchemaTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v00/PopulateInitialSchemaTest.java index e949422d748..16e7aea07b4 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v00/PopulateInitialSchemaTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v00/PopulateInitialSchemaTest.java @@ -127,8 +127,8 @@ public class PopulateInitialSchemaTest { assertThat(rows).hasSize(1); Map<String, Object> row = rows.get(0); - assertThat(row.get("name")).isEqualTo(expectedName); - assertThat(row.get("description")).isEqualTo(expectedDescription); + assertThat(row).containsEntry("name", expectedName); + assertThat(row).containsEntry("description", expectedDescription); assertThat(((Date) row.get("CREATED_AT")).getTime()).isEqualTo(NOW); assertThat(((Date) row.get("UPDATED_AT")).getTime()).isEqualTo(NOW); @@ -145,8 +145,8 @@ public class PopulateInitialSchemaTest { assertThat(rows).hasSize(1); Map<String, Object> row = rows.get(0); - assertThat(row.get("NAME")).isEqualTo("Sonar way"); - assertThat(row.get("BUILTIN")).isEqualTo(true); + assertThat(row).containsEntry("NAME", "Sonar way"); + assertThat(row).containsEntry("BUILTIN", true); assertThat(((Date) row.get("CREATED_AT")).getTime()).isEqualTo(NOW); assertThat(((Date) row.get("UPDATED_AT")).getTime()).isEqualTo(NOW); return (String) row.get("UUID"); diff --git a/server/sonar-main/src/test/java/org/sonar/application/AppLoggingTest.java b/server/sonar-main/src/test/java/org/sonar/application/AppLoggingTest.java index 1e153ea4be0..bdfdf94ec60 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/AppLoggingTest.java +++ b/server/sonar-main/src/test/java/org/sonar/application/AppLoggingTest.java @@ -250,7 +250,7 @@ public class AppLoggingTest { underTest.configure(); assertThat( - LoggerFactory.getLogger("com.hazelcast").isInfoEnabled()).isEqualTo(false); + LoggerFactory.getLogger("com.hazelcast").isInfoEnabled()).isFalse(); } @Test diff --git a/server/sonar-main/src/test/java/org/sonar/application/cluster/ClusterProcessTest.java b/server/sonar-main/src/test/java/org/sonar/application/cluster/ClusterProcessTest.java index 38d5a862161..46c79c40a37 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/cluster/ClusterProcessTest.java +++ b/server/sonar-main/src/test/java/org/sonar/application/cluster/ClusterProcessTest.java @@ -32,7 +32,7 @@ public class ClusterProcessTest { ClusterProcess clusterProcess = new ClusterProcess(nodeUuid, ProcessId.WEB_SERVER); assertThat(clusterProcess) - .isNotEqualTo(null) + .isNotNull() .isEqualTo(clusterProcess) .isNotEqualTo(new ClusterProcess(UUID.randomUUID(), ProcessId.WEB_SERVER)) .isNotEqualTo(new ClusterProcess(nodeUuid, ProcessId.ELASTICSEARCH)) diff --git a/server/sonar-main/src/test/java/org/sonar/application/command/JavaCommandTest.java b/server/sonar-main/src/test/java/org/sonar/application/command/JavaCommandTest.java index 8be42c22a96..777610474ff 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/command/JavaCommandTest.java +++ b/server/sonar-main/src/test/java/org/sonar/application/command/JavaCommandTest.java @@ -47,7 +47,7 @@ public class JavaCommandTest { command.setEnvVariable("JAVA_COMMAND_TEST", "1000"); command.addClasspath("lib/*.jar"); command.addClasspath("conf/*.xml"); - JvmOptions<JvmOptions> jvmOptions = new JvmOptions<JvmOptions>() {}; + JvmOptions<JvmOptions> jvmOptions = new JvmOptions<>() {}; command.setJvmOptions(jvmOptions); assertThat(command.toString()).isNotNull(); @@ -57,8 +57,8 @@ public class JavaCommandTest { assertThat(command.getClassName()).isEqualTo("org.sonar.ElasticSearch"); // copy current env variables - assertThat(command.getEnvVariables().get("JAVA_COMMAND_TEST")).isEqualTo("1000"); - assertThat(command.getEnvVariables().size()).isEqualTo(System.getenv().size() + 1); + assertThat(command.getEnvVariables()).containsEntry("JAVA_COMMAND_TEST", "1000"); + assertThat(command.getEnvVariables()).hasSize(System.getenv().size() + 1); } } diff --git a/server/sonar-main/src/test/java/org/sonar/application/es/EsLoggingTest.java b/server/sonar-main/src/test/java/org/sonar/application/es/EsLoggingTest.java index 7c4380e2468..faa2a5752b9 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/es/EsLoggingTest.java +++ b/server/sonar-main/src/test/java/org/sonar/application/es/EsLoggingTest.java @@ -146,7 +146,7 @@ public class EsLoggingTest { assertThat(properties.get(key)).describedAs("Unexpected value for property " + key).isEqualTo(value); keys.add(key); } - assertThat(properties.keySet()).containsOnly(keys.toArray()); + assertThat(properties).containsOnlyKeys(keys.toArray()); } } } diff --git a/server/sonar-process/src/test/java/org/sonar/process/LifecycleTest.java b/server/sonar-process/src/test/java/org/sonar/process/LifecycleTest.java index 37162c8c807..dd99d8bf068 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/LifecycleTest.java +++ b/server/sonar-process/src/test/java/org/sonar/process/LifecycleTest.java @@ -42,7 +42,7 @@ public class LifecycleTest { assertThat(init.equals(new Lifecycle())).isTrue(); assertThat(init.equals("INIT")).isFalse(); assertThat(init.equals(null)).isFalse(); - assertThat(init.hashCode()).isEqualTo(new Lifecycle().hashCode()); + assertThat(init).hasSameHashCodeAs(new Lifecycle()); // different state Lifecycle stopping = new Lifecycle(); diff --git a/server/sonar-process/src/test/java/org/sonar/process/ProcessEntryPointTest.java b/server/sonar-process/src/test/java/org/sonar/process/ProcessEntryPointTest.java index 372c229dda6..92dc3d6cd90 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/ProcessEntryPointTest.java +++ b/server/sonar-process/src/test/java/org/sonar/process/ProcessEntryPointTest.java @@ -111,8 +111,8 @@ public class ProcessEntryPointTest { entryPoint.stop(); assertThat(process.getState()).isEqualTo(State.STOPPED); - assertThat(process.wasStopped()).isEqualTo(true); - assertThat(process.wasHardStopped()).isEqualTo(false); + assertThat(process.wasStopped()).isTrue(); + assertThat(process.wasHardStopped()).isFalse(); } @Test @@ -131,7 +131,7 @@ public class ProcessEntryPointTest { entryPoint.hardStop(); assertThat(process.getState()).isEqualTo(State.STOPPED); - assertThat(process.wasHardStopped()).isEqualTo(true); + assertThat(process.wasHardStopped()).isTrue(); } @Test diff --git a/server/sonar-process/src/test/java/org/sonar/process/PropsTest.java b/server/sonar-process/src/test/java/org/sonar/process/PropsTest.java index ebbb0e557ab..04aff7ca9dd 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/PropsTest.java +++ b/server/sonar-process/src/test/java/org/sonar/process/PropsTest.java @@ -184,8 +184,8 @@ public class PropsTest { assertThat(props.rawProperties()).hasSize(2); // do not decrypt - assertThat(props.rawProperties().get("encrypted_prop")).isEqualTo("{aes}abcde"); - assertThat(props.rawProperties().get("clear_prop")).isEqualTo("foo"); + assertThat(props.rawProperties()).containsEntry("encrypted_prop", "{aes}abcde"); + assertThat(props.rawProperties()).containsEntry("clear_prop", "foo"); } @Test diff --git a/server/sonar-process/src/test/java/org/sonar/process/SystemExitTest.java b/server/sonar-process/src/test/java/org/sonar/process/SystemExitTest.java index d97a98808a3..3e18fe7f764 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/SystemExitTest.java +++ b/server/sonar-process/src/test/java/org/sonar/process/SystemExitTest.java @@ -50,6 +50,6 @@ public class SystemExitTest { assertThat(systemExit.isInShutdownHook()).isFalse(); systemExit.exit(1); - assertThat(got.get()).isEqualTo(1); + assertThat(got.get()).isOne(); } } diff --git a/server/sonar-process/src/test/java/org/sonar/process/cluster/health/NodeDetailsTest.java b/server/sonar-process/src/test/java/org/sonar/process/cluster/health/NodeDetailsTest.java index ab4ebedf871..d0866c3376c 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/cluster/health/NodeDetailsTest.java +++ b/server/sonar-process/src/test/java/org/sonar/process/cluster/health/NodeDetailsTest.java @@ -163,8 +163,9 @@ public class NodeDetailsTest { assertThat(builder.build()) .isEqualTo(underTest) .isNotSameAs(underTest); - assertThat(underTest).isNotEqualTo(null); - assertThat(underTest).isNotEqualTo(new Object()); + assertThat(underTest) + .isNotNull() + .isNotEqualTo(new Object()); } @Test diff --git a/server/sonar-process/src/test/java/org/sonar/process/cluster/health/NodeHealthTest.java b/server/sonar-process/src/test/java/org/sonar/process/cluster/health/NodeHealthTest.java index d69d6a5c1b2..42ec3fce4cc 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/cluster/health/NodeHealthTest.java +++ b/server/sonar-process/src/test/java/org/sonar/process/cluster/health/NodeHealthTest.java @@ -117,8 +117,9 @@ public class NodeHealthTest { assertThat(builder.build()) .isEqualTo(underTest) .isNotSameAs(underTest); - assertThat(underTest).isNotEqualTo(null); - assertThat(underTest).isNotEqualTo(new Object()); + assertThat(underTest) + .isNotNull() + .isNotEqualTo(new Object()); } @Test diff --git a/server/sonar-process/src/test/java/org/sonar/process/logging/Log4JPropertiesBuilderTest.java b/server/sonar-process/src/test/java/org/sonar/process/logging/Log4JPropertiesBuilderTest.java index bd0ceae2e9d..10ea096d4ac 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/logging/Log4JPropertiesBuilderTest.java +++ b/server/sonar-process/src/test/java/org/sonar/process/logging/Log4JPropertiesBuilderTest.java @@ -748,9 +748,9 @@ public class Log4JPropertiesBuilderTest { } private void verifyProperties(Properties properties, String... expectedPropertyKeysAndValuesOrdered) { - assertThat(properties.get("status")).isEqualTo("ERROR"); + assertThat(properties).containsEntry("status", "ERROR"); if (expectedPropertyKeysAndValuesOrdered.length == 0) { - assertThat(properties.size()).isEqualTo(1); + assertThat(properties.size()).isOne(); } else { assertThat(expectedPropertyKeysAndValuesOrdered.length % 2).describedAs("Number of parameters must be even").isZero(); Set<String> keys = new HashSet<>(expectedPropertyKeysAndValuesOrdered.length / 2 + 1); @@ -761,7 +761,7 @@ public class Log4JPropertiesBuilderTest { assertThat(properties.get(key)).describedAs("Unexpected value for property " + key).isEqualTo(value); keys.add(key); } - assertThat(properties.keySet()).containsOnly(keys.toArray()); + assertThat(properties).containsOnlyKeys(keys.toArray()); } } @@ -770,8 +770,8 @@ public class Log4JPropertiesBuilderTest { } private void verifyLoggerProperties(Properties properties, String loggerName, Level expectedLevel) { - assertThat(properties.get("logger." + loggerName + ".name")).isEqualTo(loggerName); - assertThat(properties.get("logger." + loggerName + ".level")).isEqualTo(expectedLevel.toString()); + assertThat(properties).containsEntry("logger." + loggerName + ".name", loggerName); + assertThat(properties).containsEntry("logger." + loggerName + ".level", expectedLevel.toString()); } private void verifyNoLoggerProperties(Properties properties, String loggerName) { @@ -780,7 +780,7 @@ public class Log4JPropertiesBuilderTest { } private void verifyRootLoggerLevel(Log4JPropertiesBuilder underTest, Level expectedLevel) { - assertThat(underTest.build().get("rootLogger.level")).isEqualTo(expectedLevel.toString()); + assertThat(underTest.build()).containsEntry("rootLogger.level", expectedLevel.toString()); } @DataProvider diff --git a/server/sonar-process/src/test/java/org/sonar/process/logging/LogLevelConfigTest.java b/server/sonar-process/src/test/java/org/sonar/process/logging/LogLevelConfigTest.java index a9cf5d6ae5f..b7bee280369 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/logging/LogLevelConfigTest.java +++ b/server/sonar-process/src/test/java/org/sonar/process/logging/LogLevelConfigTest.java @@ -161,7 +161,7 @@ public class LogLevelConfigTest { assertThat(config.getConfiguredByProperties()).isEmpty(); assertThat(config.getConfiguredByHardcodedLevel()).hasSize(1); - assertThat(config.getConfiguredByHardcodedLevel().get("bar")).isEqualTo(Level.INFO); + assertThat(config.getConfiguredByHardcodedLevel()).containsEntry("bar", Level.INFO); } @Test diff --git a/server/sonar-process/src/test/java/org/sonar/process/logging/LogbackHelperTest.java b/server/sonar-process/src/test/java/org/sonar/process/logging/LogbackHelperTest.java index bddd62d0406..4175a427309 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/logging/LogbackHelperTest.java +++ b/server/sonar-process/src/test/java/org/sonar/process/logging/LogbackHelperTest.java @@ -146,7 +146,7 @@ public class LogbackHelperTest { int countListeners = ctx.getCopyOfListenerList().size(); LoggerContextListener propagator = underTest.enableJulChangePropagation(ctx); - assertThat(ctx.getCopyOfListenerList().size()).isEqualTo(countListeners + 1); + assertThat(ctx.getCopyOfListenerList()).hasSize(countListeners + 1); ctx.removeListener(propagator); } diff --git a/server/sonar-process/src/test/java/org/sonar/process/sharedmemoryfile/AllProcessesCommandsTest.java b/server/sonar-process/src/test/java/org/sonar/process/sharedmemoryfile/AllProcessesCommandsTest.java index 5821162fd59..4f776d4fd21 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/sharedmemoryfile/AllProcessesCommandsTest.java +++ b/server/sonar-process/src/test/java/org/sonar/process/sharedmemoryfile/AllProcessesCommandsTest.java @@ -90,7 +90,7 @@ public class AllProcessesCommandsTest { try (AllProcessesCommands commands = new AllProcessesCommands(temp.newFolder())) { int offset = 5; - assertThat(readLong(commands, offset)).isEqualTo(0L); + assertThat(readLong(commands, offset)).isZero(); long currentTime = System.currentTimeMillis(); commands.ping(PROCESS_NUMBER); diff --git a/server/sonar-process/src/test/java/org/sonar/process/systeminfo/JvmStateSectionTest.java b/server/sonar-process/src/test/java/org/sonar/process/systeminfo/JvmStateSectionTest.java index 87df778a013..a994116a028 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/systeminfo/JvmStateSectionTest.java +++ b/server/sonar-process/src/test/java/org/sonar/process/systeminfo/JvmStateSectionTest.java @@ -38,7 +38,7 @@ public class JvmStateSectionTest { ProtobufSystemInfo.Section section = underTest.toProtobuf(); assertThat(section.getName()).isEqualTo(PROCESS_NAME); - assertThat(section.getAttributesCount()).isGreaterThan(0); + assertThat(section.getAttributesCount()).isPositive(); assertThat(section.getAttributesList()).extracting("key") .contains( "Max Memory (MB)", "Free Memory (MB)", diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/metric/MetricFinder.java b/server/sonar-server-common/src/main/java/org/sonar/server/metric/MetricFinder.java index e592a7ba361..0c7169dc337 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/metric/MetricFinder.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/metric/MetricFinder.java @@ -19,19 +19,18 @@ */ package org.sonar.server.metric; -import com.google.common.base.Function; -import com.google.common.base.Predicate; import java.io.Serializable; import java.util.Collection; import java.util.List; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.stream.Collectors; import javax.annotation.Nonnull; import org.sonar.api.measures.Metric; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.metric.MetricDto; -import static com.google.common.collect.FluentIterable.from; - public class MetricFinder { private final DbClient dbClient; @@ -63,21 +62,21 @@ public class MetricFinder { public Collection<Metric> findAll(List<String> metricKeys) { try (DbSession session = dbClient.openSession(false)) { List<MetricDto> dtos = dbClient.metricDao().selectByKeys(session, metricKeys); - return from(dtos).filter(IsEnabled.INSTANCE).transform(ToMetric.INSTANCE).toList(); + return dtos.stream().filter(IsEnabled.INSTANCE).map(ToMetric.INSTANCE).collect(Collectors.toList()); } } public Collection<Metric> findAll() { try (DbSession session = dbClient.openSession(false)) { List<MetricDto> dtos = dbClient.metricDao().selectEnabled(session); - return from(dtos).transform(ToMetric.INSTANCE).toList(); + return dtos.stream().map(ToMetric.INSTANCE).collect(Collectors.toList()); } } private enum IsEnabled implements Predicate<MetricDto> { INSTANCE; @Override - public boolean apply(@Nonnull MetricDto dto) { + public boolean test(@Nonnull MetricDto dto) { return dto.isEnabled(); } } diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleDoc.java b/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleDoc.java index 76458e6c63a..13c83172e45 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleDoc.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleDoc.java @@ -257,7 +257,7 @@ public class RuleDoc extends BaseDoc { } public long createdAt() { - return (Long) getField(RuleIndexDefinition.FIELD_RULE_CREATED_AT); + return getField(RuleIndexDefinition.FIELD_RULE_CREATED_AT); } public RuleDoc setCreatedAt(@Nullable Long l) { @@ -266,7 +266,7 @@ public class RuleDoc extends BaseDoc { } public long updatedAt() { - return (Long) getField(RuleIndexDefinition.FIELD_RULE_UPDATED_AT); + return getField(RuleIndexDefinition.FIELD_RULE_UPDATED_AT); } public RuleDoc setUpdatedAt(@Nullable Long l) { diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleIndexer.java b/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleIndexer.java index 0181da84f0e..8a39746ae86 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleIndexer.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleIndexer.java @@ -188,7 +188,6 @@ public class RuleIndexer implements ResilientIndexer { } private static EsQueueDto createQueueDtoForRule(String ruleUuid) { - String docId = ruleUuid; - return EsQueueDto.create(TYPE_RULE.format(), docId, null, docId); + return EsQueueDto.create(TYPE_RULE.format(), ruleUuid, null, ruleUuid); } } diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/security/SecurityStandards.java b/server/sonar-server-common/src/main/java/org/sonar/server/security/SecurityStandards.java index 124eaf0853f..e30b2a0846e 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/security/SecurityStandards.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/security/SecurityStandards.java @@ -23,7 +23,6 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.Ordering; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -70,22 +69,16 @@ public final class SecurityStandards { SANS_TOP_25_POROUS_DEFENSES, POROUS_CWE); // https://cwe.mitre.org/top25/archive/2019/2019_cwe_top25.html - public static final List<String> CWE_TOP25_2019 = - Collections.unmodifiableList(asList("119", "79", "20", "200", "125", "89", "416", "190", "352", - "22", "78", "787", "287", "476", "732", "434", "611", "94", - "798", "400", "772", "426", "502", "269", "295")); + public static final List<String> CWE_TOP25_2019 = List.of("119", "79", "20", "200", "125", "89", "416", "190", "352", "22", "78", "787", "287", "476", + "732", "434", "611", "94", "798", "400", "772", "426", "502", "269", "295"); // https://cwe.mitre.org/top25/archive/2020/2020_cwe_top25.html - public static final List<String> CWE_TOP25_2020 = - Collections.unmodifiableList(asList("79", "787", "20", "125", "119", "89", "200", "416", "352", - "78", "190", "22", "476", "287", "434", "732", "94", "522", - "611", "798", "502", "269", "400", "306", "862")); + public static final List<String> CWE_TOP25_2020 = List.of("79", "787", "20", "125", "119", "89", "200", "416", "352", "78", "190", "22", "476", "287", + "434", "732", "94", "522", "611", "798", "502", "269", "400", "306", "862"); // https://cwe.mitre.org/top25/archive/2021/2021_cwe_top25.html - public static final List<String> CWE_TOP25_2021 = - Collections.unmodifiableList(asList("787", "79", "125", "20", "78", "89", "416", "22", "352", - "434", "306", "190", "502", "287", "476", "798", "119", "862", - "276", "200", "522", "732", "611", "918", "77")); + public static final List<String> CWE_TOP25_2021 = List.of("787", "79", "125", "20", "78", "89", "416", "22", "352", "434", "306", "190", "502", "287", "476", + "798", "119", "862", "276", "200", "522", "732", "611", "918", "77"); public static final Map<String, List<String>> CWES_BY_CWE_TOP_25 = Map.of( "2019", CWE_TOP25_2019, diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/user/index/UserDoc.java b/server/sonar-server-common/src/main/java/org/sonar/server/user/index/UserDoc.java index 2db7be9fd34..ecab0905175 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/user/index/UserDoc.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/user/index/UserDoc.java @@ -60,7 +60,7 @@ public class UserDoc extends BaseDoc { } public boolean active() { - return (Boolean) getField(UserIndexDefinition.FIELD_ACTIVE); + return getField(UserIndexDefinition.FIELD_ACTIVE); } public List<String> scmAccounts() { diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/component/index/ComponentIndexerTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/component/index/ComponentIndexerTest.java index 7eb09b5023f..c58e6c05a8d 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/component/index/ComponentIndexerTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/component/index/ComponentIndexerTest.java @@ -187,8 +187,8 @@ public class ComponentIndexerTest { IndexingResult result = indexProject(project, PROJECT_CREATION); assertThatIndexContainsOnly(project); - assertThat(result.getTotal()).isEqualTo(1L); - assertThat(result.getSuccess()).isEqualTo(1L); + assertThat(result.getTotal()).isOne(); + assertThat(result.getSuccess()).isOne(); } @Test @@ -219,20 +219,20 @@ public class ComponentIndexerTest { es.lockWrites(TYPE_COMPONENT); IndexingResult result = indexProject(project1, PROJECT_CREATION); - assertThat(result.getTotal()).isEqualTo(1L); - assertThat(result.getFailures()).isEqualTo(1L); + assertThat(result.getTotal()).isOne(); + assertThat(result.getFailures()).isOne(); // index is still read-only, fail to recover result = recover(); - assertThat(result.getTotal()).isEqualTo(1L); - assertThat(result.getFailures()).isEqualTo(1L); + assertThat(result.getTotal()).isOne(); + assertThat(result.getFailures()).isOne(); assertThat(es.countDocuments(TYPE_COMPONENT)).isZero(); es.unlockWrites(TYPE_COMPONENT); result = recover(); - assertThat(result.getTotal()).isEqualTo(1L); - assertThat(result.getFailures()).isEqualTo(0L); + assertThat(result.getTotal()).isOne(); + assertThat(result.getFailures()).isZero(); assertThatIndexContainsOnly(project1); } diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/component/index/SuggestionQueryTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/component/index/SuggestionQueryTest.java index afd691c0dd7..c556b3f9cbc 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/component/index/SuggestionQueryTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/component/index/SuggestionQueryTest.java @@ -71,6 +71,6 @@ public class SuggestionQueryTest { SuggestionQuery query = SuggestionQuery.builder().setQuery("ab") .setLimit(1).build(); - assertThat(query.getLimit()).isEqualTo(1); + assertThat(query.getLimit()).isOne(); } } diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/es/BulkIndexerTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/es/BulkIndexerTest.java index 7384326ca85..3d8c3ec345b 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/es/BulkIndexerTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/es/BulkIndexerTest.java @@ -83,7 +83,7 @@ public class BulkIndexerTest { @Test public void large_indexing() { // index has one replica - assertThat(replicas()).isEqualTo(1); + assertThat(replicas()).isOne(); BulkIndexer indexer = new BulkIndexer(es.client(), TYPE_FAKE, Size.LARGE); indexer.start(); @@ -102,7 +102,7 @@ public class BulkIndexerTest { assertThat(result.getTotal()).isEqualTo(10); assertThat(count()).isEqualTo(10); // replicas are re-enabled - assertThat(replicas()).isEqualTo(1); + assertThat(replicas()).isOne(); } @Test @@ -132,8 +132,8 @@ public class BulkIndexerTest { indexer.stop(); assertThat(listener.calledDocIds) .containsExactlyInAnyOrder(newDocId(TYPE_FAKE, "foo")); - assertThat(listener.calledResult.getSuccess()).isEqualTo(1); - assertThat(listener.calledResult.getTotal()).isEqualTo(1); + assertThat(listener.calledResult.getSuccess()).isOne(); + assertThat(listener.calledResult.getTotal()).isOne(); } @Test @@ -159,7 +159,7 @@ public class BulkIndexerTest { indexer.add(new IndexRequest("index_does_not_exist", "index_does_not_exist", "bar").source(emptyMap())); indexer.stop(); assertThat(listener.calledDocIds).containsExactly(newDocId(TYPE_FAKE, "foo")); - assertThat(listener.calledResult.getSuccess()).isEqualTo(1); + assertThat(listener.calledResult.getSuccess()).isOne(); assertThat(listener.calledResult.getTotal()).isEqualTo(2); } diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/es/EsUtilsTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/es/EsUtilsTest.java index ecb59d04fe7..524aa85a7fc 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/es/EsUtilsTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/es/EsUtilsTest.java @@ -63,7 +63,7 @@ public class EsUtilsTest { @Test public void test_escapeSpecialRegexChars() { - assertThat(escapeSpecialRegexChars("")).isEqualTo(""); + assertThat(escapeSpecialRegexChars("")).isEmpty(); assertThat(escapeSpecialRegexChars("foo")).isEqualTo("foo"); assertThat(escapeSpecialRegexChars("FOO")).isEqualTo("FOO"); assertThat(escapeSpecialRegexChars("foo++")).isEqualTo("foo\\+\\+"); diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/es/IndexTypeTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/es/IndexTypeTest.java index 510d9574c23..d9dbd697363 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/es/IndexTypeTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/es/IndexTypeTest.java @@ -34,7 +34,6 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; @RunWith(DataProviderRunner.class) public class IndexTypeTest { - @Test public void parseMainType_from_main_type_without_relations() { IndexMainType type1 = IndexType.main(Index.simple("foo"), "bar"); @@ -116,10 +115,9 @@ public class IndexTypeTest { .isEqualTo(type1) .isEqualTo(type1b) .isNotEqualTo(type1c) - .isNotEqualTo(type2); - - assertThat(type1.hashCode()).isEqualTo(type1.hashCode()); - assertThat(type1.hashCode()).isEqualTo(type1b.hashCode()); + .isNotEqualTo(type2) + .hasSameHashCodeAs(type1) + .hasSameHashCodeAs(type1b); assertThat(type1.hashCode()).isNotEqualTo(type1c.hashCode()); assertThat(type2.hashCode()).isNotEqualTo(type1.hashCode()); } @@ -137,10 +135,9 @@ public class IndexTypeTest { .isEqualTo(type1) .isEqualTo(type1b) .isNotEqualTo(type2) - .isNotEqualTo(type3); - - assertThat(type1.hashCode()).isEqualTo(type1.hashCode()); - assertThat(type1.hashCode()).isEqualTo(type1b.hashCode()); + .isNotEqualTo(type3) + .hasSameHashCodeAs(type1) + .hasSameHashCodeAs(type1b); assertThat(type2.hashCode()).isNotEqualTo(type1.hashCode()); assertThat(type3.hashCode()) .isNotEqualTo(type2.hashCode()) diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/es/IndexingResultTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/es/IndexingResultTest.java index 8a5606fa6e5..37aae602efd 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/es/IndexingResultTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/es/IndexingResultTest.java @@ -74,7 +74,7 @@ public class IndexingResultTest { underTest.incrementSuccess(); assertThat(underTest.getFailures()).isEqualTo(3); - assertThat(underTest.getSuccess()).isEqualTo(1); + assertThat(underTest.getSuccess()).isOne(); assertThat(underTest.getTotal()).isEqualTo(4); assertThat(underTest.getSuccessRatio()).isEqualTo(0.25, DOUBLE_OFFSET); assertThat(underTest.isSuccess()).isFalse(); diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/es/NewIndexSettingsConfigurationTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/es/NewIndexSettingsConfigurationTest.java index 51b5d7e69ba..657440478f2 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/es/NewIndexSettingsConfigurationTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/es/NewIndexSettingsConfigurationTest.java @@ -62,7 +62,7 @@ public class NewIndexSettingsConfigurationTest { public void setDefaultNbOfShards_accepts_1() { SettingsConfiguration.Builder underTest = newBuilder(mockConfiguration); - assertThat(underTest.setDefaultNbOfShards(1).build().getDefaultNbOfShards()).isEqualTo(1); + assertThat(underTest.setDefaultNbOfShards(1).build().getDefaultNbOfShards()).isOne(); } @Test @@ -76,7 +76,7 @@ public class NewIndexSettingsConfigurationTest { @Test public void getDefaultNbOfShards_returns_1_when_not_explicitly_set() { - assertThat(newBuilder(mockConfiguration).build().getDefaultNbOfShards()).isEqualTo(1); + assertThat(newBuilder(mockConfiguration).build().getDefaultNbOfShards()).isOne(); } @Test diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/es/SearchOptionsTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/es/SearchOptionsTest.java index b8989416330..a6a0c6ffbca 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/es/SearchOptionsTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/es/SearchOptionsTest.java @@ -40,7 +40,7 @@ public class SearchOptionsTest { assertThat(options.getFields()).isEmpty(); assertThat(options.getOffset()).isZero(); assertThat(options.getLimit()).isEqualTo(10); - assertThat(options.getPage()).isEqualTo(1); + assertThat(options.getPage()).isOne(); } @Test @@ -56,7 +56,7 @@ public class SearchOptionsTest { SearchOptions options = new SearchOptions().setPage(1, 10); assertThat(options.getLimit()).isEqualTo(10); assertThat(options.getOffset()).isZero(); - assertThat(options.getPage()).isEqualTo(1); + assertThat(options.getPage()).isOne(); } @Test 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 3fb3ef6b174..6da8d61d902 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 @@ -143,29 +143,31 @@ public class NewIndexTest { .build(); Map<String, Object> props = (Map) newIndex.getProperty("basic_field"); - assertThat(props.get("type")).isEqualTo("keyword"); - assertThat(props.get("index")).isEqualTo("true"); + assertThat(props).containsEntry("type", "keyword") + .containsEntry("index", "true"); assertThat(props.get("fields")).isNull(); props = (Map) newIndex.getProperty("not_searchable_field"); - assertThat(props.get("type")).isEqualTo("keyword"); - assertThat(props.get("index")).isEqualTo("false"); - assertThat(props.get("norms")).isEqualTo("true"); - assertThat(props.get("store")).isEqualTo("false"); - assertThat(props.get("doc_values")).isEqualTo("true"); + assertThat(props) + .containsEntry("type", "keyword") + .containsEntry("index", "false") + .containsEntry("norms", "true") + .containsEntry("store", "false") + .containsEntry("doc_values", "true"); assertThat(props.get("fields")).isNull(); props = (Map) newIndex.getProperty("all_capabilities_field"); - assertThat(props.get("type")).isEqualTo("keyword"); + assertThat(props).containsEntry("type", "keyword"); // no need to test values, it's not the scope of this test assertThat((Map) props.get("fields")).isNotEmpty(); props = (Map) newIndex.getProperty("dumb_text_storage"); - assertThat(props.get("type")).isEqualTo("keyword"); - assertThat(props.get("index")).isEqualTo("false"); - assertThat(props.get("norms")).isEqualTo("false"); - assertThat(props.get("store")).isEqualTo("false"); - assertThat(props.get("doc_values")).isEqualTo("false"); + assertThat(props) + .containsEntry("type", "keyword") + .containsEntry("index", "false") + .containsEntry("norms", "false") + .containsEntry("store", "false") + .containsEntry("doc_values", "false"); assertThat(props.get("fields")).isNull(); } @@ -178,10 +180,10 @@ public class NewIndexTest { .build(); Map<String, Object> result = (Map) newIndex.getProperty("measures"); - assertThat(result.get("type")).isEqualTo("nested"); + assertThat(result).containsEntry("type", "nested"); Map<String, Map<String, Object>> subProperties = (Map) result.get("properties"); - assertThat(subProperties.get("key").get("type")).isEqualTo("keyword"); - assertThat(subProperties.get("value").get("type")).isEqualTo("double"); + assertThat(subProperties.get("key")).containsEntry("type", "keyword"); + assertThat(subProperties.get("value")).containsEntry("type", "double"); } @Test @@ -200,8 +202,9 @@ public class NewIndexTest { typeMapping.keywordFieldBuilder("the_doc_value").build(); Map<String, Object> props = (Map) newIndex.getProperty("the_doc_value"); - assertThat(props.get("type")).isEqualTo("keyword"); - assertThat(props.get("doc_values")).isEqualTo("true"); + assertThat(props) + .containsEntry("type", "keyword") + .containsEntry("doc_values", "true"); } @DataProvider diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/es/response/NodeStatsResponseTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/es/response/NodeStatsResponseTest.java index 17ace95ead6..0b234fea25a 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/es/response/NodeStatsResponseTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/es/response/NodeStatsResponseTest.java @@ -109,7 +109,7 @@ public class NodeStatsResponseTest { assertThat(nodeStats.getFieldDataCircuitBreakerLimit()).isEqualTo(207591833); assertThat(nodeStats.getFieldDataCircuitBreakerEstimation()).isEqualTo(4880); assertThat(nodeStats.getRequestCircuitBreakerLimit()).isEqualTo(311387750L); - assertThat(nodeStats.getRequestCircuitBreakerEstimation()).isEqualTo(1); + assertThat(nodeStats.getRequestCircuitBreakerEstimation()).isOne(); JvmStats jvmStats = nodeStats.getJvmStats(); assertThat(jvmStats).isNotNull(); diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/es/searchrequest/NestedFieldFilterScopeTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/es/searchrequest/NestedFieldFilterScopeTest.java index 0c2ceadfc38..be55e52c655 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/es/searchrequest/NestedFieldFilterScopeTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/es/searchrequest/NestedFieldFilterScopeTest.java @@ -84,7 +84,7 @@ public class NestedFieldFilterScopeTest { assertThat(underTest) .isEqualTo(underTest) .isEqualTo(new NestedFieldFilterScope<>(fieldName, nestedFieldName, value)) - .isNotEqualTo(null) + .isNotNull() .isNotEqualTo(new Object()) .isNotEqualTo(new NestedFieldFilterScope<>(fieldName2, nestedFieldName, value)) .isNotEqualTo(new NestedFieldFilterScope<>(fieldName, nestedFieldName2, value)) @@ -111,7 +111,6 @@ public class NestedFieldFilterScopeTest { .isEqualTo(underTest.hashCode()) .isEqualTo(new NestedFieldFilterScope<>(fieldName, nestedFieldName, value).hashCode()); assertThat(underTest.hashCode()) - .isNotEqualTo(null) .isNotEqualTo(new Object().hashCode()) .isNotEqualTo(new NestedFieldFilterScope<>(fieldName2, nestedFieldName, value).hashCode()) .isNotEqualTo(new NestedFieldFilterScope<>(fieldName, nestedFieldName2, value).hashCode()) diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/es/searchrequest/SimpleFieldFilterScopeTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/es/searchrequest/SimpleFieldFilterScopeTest.java index 0f8810ae1e1..37b32e54daf 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/es/searchrequest/SimpleFieldFilterScopeTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/es/searchrequest/SimpleFieldFilterScopeTest.java @@ -52,7 +52,7 @@ public class SimpleFieldFilterScopeTest { assertThat(underTest) .isEqualTo(underTest) .isEqualTo(new SimpleFieldFilterScope(fieldName1)) - .isNotEqualTo(null) + .isNotNull() .isNotEqualTo(new Object()) .isNotEqualTo(new SimpleFieldFilterScope(fieldName2)) .isNotEqualTo(new NestedFieldFilterScope<>(fieldName1, "foo", "bar")) diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/es/searchrequest/SubAggregationHelperTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/es/searchrequest/SubAggregationHelperTest.java index c9a3dc93e12..9cf81a34f60 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/es/searchrequest/SubAggregationHelperTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/es/searchrequest/SubAggregationHelperTest.java @@ -56,7 +56,7 @@ public class SubAggregationHelperTest { assertThat(agg.getName()).isEqualTo(aggName); assertThat(agg.field()).isEqualTo(topAggregation.getFilterScope().getFieldName()); assertThat(agg.size()).isEqualTo(DEFAULT_BUCKET_SIZE); - assertThat(agg.minDocCount()).isEqualTo(1); + assertThat(agg.minDocCount()).isOne(); assertThat(agg.order()).isEqualTo(BucketOrder.compound(SQ_DEFAULT_BUCKET_ORDER, ES_BUILTIN_TIE_BREAKER)); }); } diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/issue/index/IssueIndexerTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/issue/index/IssueIndexerTest.java index 490f3373e3f..5be0556e278 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/issue/index/IssueIndexerTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/issue/index/IssueIndexerTest.java @@ -227,7 +227,7 @@ public class IssueIndexerTest { IssueDto issue = db.issues().insert(); IndexingResult result = indexProject(issue.getProjectUuid(), ProjectIndexer.Cause.PROJECT_CREATION); - assertThat(result.getTotal()).isEqualTo(0L); + assertThat(result.getTotal()).isZero(); assertThatIndexHasSize(0); } @@ -237,7 +237,7 @@ public class IssueIndexerTest { IssueDto issue = db.issues().insert(); IndexingResult result = indexProject(issue.getProjectUuid(), ProjectIndexer.Cause.PROJECT_KEY_UPDATE); - assertThat(result.getTotal()).isEqualTo(0L); + assertThat(result.getTotal()).isZero(); assertThatIndexHasSize(0); } @@ -247,7 +247,7 @@ public class IssueIndexerTest { IssueDto issue = db.issues().insert(); IndexingResult result = indexProject(issue.getProjectUuid(), ProjectIndexer.Cause.PROJECT_TAGS_UPDATE); - assertThat(result.getTotal()).isEqualTo(0L); + assertThat(result.getTotal()).isZero(); assertThatIndexHasSize(0); } @@ -258,8 +258,8 @@ public class IssueIndexerTest { IndexingResult result = indexProject("P1", ProjectIndexer.Cause.PROJECT_DELETION); - assertThat(result.getTotal()).isEqualTo(1L); - assertThat(result.getSuccess()).isEqualTo(1L); + assertThat(result.getTotal()).isOne(); + assertThat(result.getSuccess()).isOne(); assertThatIndexHasSize(0); } @@ -270,20 +270,20 @@ public class IssueIndexerTest { es.lockWrites(TYPE_ISSUE); IndexingResult result = indexProject("P1", ProjectIndexer.Cause.PROJECT_DELETION); - assertThat(result.getTotal()).isEqualTo(1L); - assertThat(result.getFailures()).isEqualTo(1L); + assertThat(result.getTotal()).isOne(); + assertThat(result.getFailures()).isOne(); // index is still read-only, fail to recover result = recover(); - assertThat(result.getTotal()).isEqualTo(1L); - assertThat(result.getFailures()).isEqualTo(1L); + assertThat(result.getTotal()).isOne(); + assertThat(result.getFailures()).isOne(); assertThatIndexHasSize(1); es.unlockWrites(TYPE_ISSUE); result = recover(); - assertThat(result.getTotal()).isEqualTo(1L); - assertThat(result.getFailures()).isEqualTo(0L); + assertThat(result.getTotal()).isOne(); + assertThat(result.getFailures()).isZero(); assertThatIndexHasSize(0); } @@ -412,7 +412,7 @@ public class IssueIndexerTest { result = recover(); assertThat(result.getTotal()).isEqualTo(2L); - assertThat(result.getFailures()).isEqualTo(0L); + assertThat(result.getFailures()).isZero(); assertThatIndexHasSize(2); assertThatEsQueueTableHasSize(0); } @@ -475,7 +475,7 @@ public class IssueIndexerTest { new IssueIndexer(es.client(), db.getDbClient(), new IssueIteratorFactory(db.getDbClient()), null) .index(singletonList(issueDoc).iterator()); - assertThat(es.countDocuments(TYPE_ISSUE)).isEqualTo(1L); + assertThat(es.countDocuments(TYPE_ISSUE)).isOne(); } @Test diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/issue/index/IssueIteratorFactoryTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/issue/index/IssueIteratorFactoryTest.java index 82647a6ec02..512c0db0cd4 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/issue/index/IssueIteratorFactoryTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/issue/index/IssueIteratorFactoryTest.java @@ -19,11 +19,11 @@ */ package org.sonar.server.issue.index; -import com.google.common.base.Function; -import com.google.common.collect.ImmutableList; import com.google.common.collect.Maps; import java.util.Date; +import java.util.List; import java.util.Map; +import java.util.function.Function; import java.util.stream.Stream; import org.junit.Rule; import org.junit.Test; @@ -63,7 +63,7 @@ public class IssueIteratorFactoryTest { .setLine(444) .setRuleUuid(rule.getUuid()) .setIssueAttributes("JIRA=http://jira.com") - .setTags(ImmutableList.of("tag1", "tag2", "tag3")) + .setTags(List.of("tag1", "tag2", "tag3")) .setCreatedAt(1400000000000L) .setUpdatedAt(1400000000000L) .setIssueCreationDate(new Date(1115848800000L)) @@ -121,8 +121,9 @@ public class IssueIteratorFactoryTest { Map<String, IssueDoc> issuesByKey = issuesByKey(); - assertThat(issuesByKey).hasSize(4); - assertThat(issuesByKey.keySet()).containsOnly(fileIssue.getKey(), moduleIssue.getKey(), dirIssue.getKey(), projectIssue.getKey()); + assertThat(issuesByKey) + .hasSize(4) + .containsOnlyKeys(fileIssue.getKey(), moduleIssue.getKey(), dirIssue.getKey(), projectIssue.getKey()); } @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 c8785026554..879e308ed7b 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 @@ -53,7 +53,7 @@ public class ChangesOnMyIssuesNotificationTest { assertThat(underTest) .isEqualTo(new ChangesOnMyIssuesNotification(analysisChange, ImmutableSet.of(changedIssue))) .isNotEqualTo(mock(Notification.class)) - .isNotEqualTo(null) + .isNotNull() .isNotEqualTo(new ChangesOnMyIssuesNotification(new AnalysisChange(analysisChange.getDate() + 10), ImmutableSet.of(changedIssue))) .isNotEqualTo(new ChangesOnMyIssuesNotification(analysisChange, ImmutableSet.of())); } @@ -68,7 +68,6 @@ public class ChangesOnMyIssuesNotificationTest { assertThat(underTest.hashCode()) .isEqualTo(new ChangesOnMyIssuesNotification(analysisChange, ImmutableSet.of(changedIssue)).hashCode()) .isNotEqualTo(mock(Notification.class).hashCode()) - .isNotEqualTo(null) .isNotEqualTo(new ChangesOnMyIssuesNotification(new AnalysisChange(analysisChange.getDate() + 10), ImmutableSet.of(changedIssue)).hashCode()) .isNotEqualTo(new ChangesOnMyIssuesNotification(analysisChange, ImmutableSet.of())).hashCode(); } diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/FPOrWontFixNotificationTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/FPOrWontFixNotificationTest.java index c3b105ea331..00daece0ee9 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/FPOrWontFixNotificationTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/FPOrWontFixNotificationTest.java @@ -57,7 +57,7 @@ public class FPOrWontFixNotificationTest { .isEqualTo(new FPOrWontFixNotification(change, changedIssues, WONT_FIX)) .isEqualTo(new FPOrWontFixNotification(change, ImmutableSet.copyOf(changedIssues), WONT_FIX)) .isNotEqualTo(new Object()) - .isNotEqualTo(null) + .isNotNull() .isNotEqualTo(new FPOrWontFixNotification(change, Collections.emptySet(), WONT_FIX)) .isNotEqualTo(new FPOrWontFixNotification(change, ImmutableSet.of(changedIssues.iterator().next()), WONT_FIX)) .isNotEqualTo(new FPOrWontFixNotification(new AnalysisChange(14), changedIssues, WONT_FIX)) diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/IssuesChangesNotificationBuilderTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/IssuesChangesNotificationBuilderTest.java index d4409c40fe2..46ff4518ebb 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/IssuesChangesNotificationBuilderTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/IssuesChangesNotificationBuilderTest.java @@ -193,7 +193,7 @@ public class IssuesChangesNotificationBuilderTest { public void AnalysisChange_not_equal_with_null() { AnalysisChange analysisChange1 = new AnalysisChange(1_000_000_000L); - assertThat(analysisChange1).isNotEqualTo(null); + assertThat(analysisChange1).isNotNull(); } @Test diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/NewIssuesNotificationTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/NewIssuesNotificationTest.java index e38a488bbd3..6cb03a4c049 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/NewIssuesNotificationTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/NewIssuesNotificationTest.java @@ -440,13 +440,13 @@ public class NewIssuesNotificationTest { assertThat(underTest) .isEqualTo(underTest) - .isEqualTo(new RuleDefinition(name, language)); - assertThat(underTest).isNotEqualTo(new RuleDefinition(language, name)); - assertThat(underTest).isNotEqualTo(new RuleDefinition(randomAlphabetic(7), name)); - assertThat(underTest).isNotEqualTo(new RuleDefinition(language, randomAlphabetic(7))); - assertThat(underTest).isNotEqualTo(new RuleDefinition(language, null)); - assertThat(underTest).isNotEqualTo(null); - assertThat(underTest).isNotEqualTo(new Object()); + .isEqualTo(new RuleDefinition(name, language)) + .isNotEqualTo(new RuleDefinition(language, name)) + .isNotEqualTo(new RuleDefinition(randomAlphabetic(7), name)) + .isNotEqualTo(new RuleDefinition(language, randomAlphabetic(7))) + .isNotEqualTo(new RuleDefinition(language, null)) + .isNotNull() + .isNotEqualTo(new Object()); } @Test @@ -455,14 +455,15 @@ public class NewIssuesNotificationTest { String language = randomAlphabetic(6); RuleDefinition underTest = new RuleDefinition(name, language); + assertThat(underTest) + .hasSameHashCodeAs(underTest) + .hasSameHashCodeAs(new RuleDefinition(name, language)); + assertThat(underTest.hashCode()) - .isEqualTo(underTest.hashCode()) - .isEqualTo(new RuleDefinition(name, language).hashCode()); - assertThat(underTest.hashCode()).isNotEqualTo(new RuleDefinition(language, name).hashCode()); - assertThat(underTest.hashCode()).isNotEqualTo(new RuleDefinition(randomAlphabetic(7), name).hashCode()); - assertThat(underTest.hashCode()).isNotEqualTo(new RuleDefinition(language, randomAlphabetic(7)).hashCode()); - assertThat(underTest.hashCode()).isNotEqualTo(new RuleDefinition(language, null).hashCode()); - assertThat(underTest.hashCode()).isNotEqualTo(null); - assertThat(underTest.hashCode()).isNotEqualTo(new Object().hashCode()); + .isNotEqualTo(new RuleDefinition(language, name).hashCode()) + .isNotEqualTo(new RuleDefinition(randomAlphabetic(7), name).hashCode()) + .isNotEqualTo(new RuleDefinition(language, randomAlphabetic(7)).hashCode()) + .isNotEqualTo(new RuleDefinition(language, null).hashCode()) + .isNotEqualTo(new Object().hashCode()); } } diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/NewIssuesStatisticsTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/NewIssuesStatisticsTest.java index cd94d5baf70..eef14dffc2c 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/NewIssuesStatisticsTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/NewIssuesStatisticsTest.java @@ -73,9 +73,9 @@ public class NewIssuesStatisticsTest { underTest.add(issue.setAssigneeUuid("james")); underTest.add(issue.setAssigneeUuid("keenan")); - assertThat(countDistributionTotal(Metric.ASSIGNEE, "maynard")).isEqualTo(1); - assertThat(countDistributionTotal(Metric.ASSIGNEE, "james")).isEqualTo(1); - assertThat(countDistributionTotal(Metric.ASSIGNEE, "keenan")).isEqualTo(1); + assertThat(countDistributionTotal(Metric.ASSIGNEE, "maynard")).isOne(); + assertThat(countDistributionTotal(Metric.ASSIGNEE, "james")).isOne(); + assertThat(countDistributionTotal(Metric.ASSIGNEE, "keenan")).isOne(); assertThat(countDistributionTotal(Metric.ASSIGNEE, "wrong.login")).isNull(); assertThat(countDistributionTotal(Metric.COMPONENT, "file-uuid")).isEqualTo(3); assertThat(countDistributionTotal(Metric.COMPONENT, "wrong-uuid")).isNull(); @@ -156,7 +156,7 @@ public class NewIssuesStatisticsTest { Stream.of(globalDistribution, assigneeDistribution) .forEach(distribution -> { assertThat(distribution.getTotal()).isZero(); - assertThat(distribution.getForLabel(null).isPresent()).isFalse(); + assertThat(distribution.getForLabel(null)).isEmpty(); }); } @@ -201,7 +201,7 @@ public class NewIssuesStatisticsTest { Stream.of(globalDistribution, assigneeDistribution) .forEach(distribution -> { assertThat(distribution.getTotal()).isZero(); - assertThat(distribution.getForLabel(null).isPresent()).isFalse(); + assertThat(distribution.getForLabel(null)).isEmpty(); }); } @@ -217,17 +217,17 @@ public class NewIssuesStatisticsTest { assignees.forEach(assignee -> { NewIssuesStatistics.Stats stats = underTest.getAssigneesStatistics().get(assignee); DistributedMetricStatsInt assigneeStats = stats.getDistributedMetricStats(Metric.ASSIGNEE); - assertThat(assigneeStats.getOnCurrentAnalysis()).isEqualTo(1); - assertThat(assigneeStats.getTotal()).isEqualTo(1); + assertThat(assigneeStats.getOnCurrentAnalysis()).isOne(); + assertThat(assigneeStats.getTotal()).isOne(); assignees.forEach(s -> { Optional<MetricStatsInt> forLabelOpts = assigneeStats.getForLabel(s); if (s.equals(assignee)) { - assertThat(forLabelOpts.isPresent()).isTrue(); + assertThat(forLabelOpts).isPresent(); MetricStatsInt forLabel = forLabelOpts.get(); - assertThat(forLabel.getOnCurrentAnalysis()).isEqualTo(1); - assertThat(forLabel.getTotal()).isEqualTo(1); + assertThat(forLabel.getOnCurrentAnalysis()).isOne(); + assertThat(forLabel.getTotal()).isOne(); } else { - assertThat(forLabelOpts.isPresent()).isFalse(); + assertThat(forLabelOpts).isEmpty(); } }); }); @@ -246,16 +246,16 @@ public class NewIssuesStatisticsTest { NewIssuesStatistics.Stats stats = underTest.getAssigneesStatistics().get(assignee); DistributedMetricStatsInt assigneeStats = stats.getDistributedMetricStats(Metric.ASSIGNEE); assertThat(assigneeStats.getOnCurrentAnalysis()).isZero(); - assertThat(assigneeStats.getTotal()).isEqualTo(1); + assertThat(assigneeStats.getTotal()).isOne(); assignees.forEach(s -> { Optional<MetricStatsInt> forLabelOpts = assigneeStats.getForLabel(s); if (s.equals(assignee)) { - assertThat(forLabelOpts.isPresent()).isTrue(); + assertThat(forLabelOpts).isPresent(); MetricStatsInt forLabel = forLabelOpts.get(); assertThat(forLabel.getOnCurrentAnalysis()).isZero(); - assertThat(forLabel.getTotal()).isEqualTo(1); + assertThat(forLabel.getTotal()).isOne(); } else { - assertThat(forLabelOpts.isPresent()).isFalse(); + assertThat(forLabelOpts).isEmpty(); } }); }); @@ -267,7 +267,7 @@ public class NewIssuesStatisticsTest { DistributedMetricStatsInt globalDistribution = underTest.globalStatistics().getDistributedMetricStats(Metric.ASSIGNEE); assertThat(globalDistribution.getTotal()).isZero(); - assertThat(globalDistribution.getForLabel(null).isPresent()).isFalse(); + assertThat(globalDistribution.getForLabel(null)).isEmpty(); assertThat(underTest.getAssigneesStatistics()).isEmpty(); } @@ -305,7 +305,7 @@ public class NewIssuesStatisticsTest { Stream.of(globalDistribution, assigneeDistribution) .forEach(distribution -> { assertThat(distribution.getTotal()).isZero(); - assertThat(distribution.getForLabel(null).isPresent()).isFalse(); + assertThat(distribution.getForLabel(null)).isEmpty(); }); } diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/issue/workflow/TransitionTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/issue/workflow/TransitionTest.java index 31c84dece6c..30f22c4d1a2 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/issue/workflow/TransitionTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/issue/workflow/TransitionTest.java @@ -128,11 +128,11 @@ public class TransitionTest { Transition t2 = Transition.create("resolve", "REOPENED", "RESOLVED"); Transition t3 = Transition.create("confirm", "OPEN", "CONFIRMED"); - assertThat(t1).isNotEqualTo(t2); - assertThat(t1).isNotEqualTo(t3); - assertThat(t1).isEqualTo(t1); - - assertThat(t1.hashCode()).isEqualTo(t1.hashCode()); + assertThat(t1) + .isNotEqualTo(t2) + .isNotEqualTo(t3) + .isEqualTo(t1) + .hasSameHashCodeAs(t1); } @Test diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexerTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexerTest.java index d0c7bb9f620..8d4f02ba6b8 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexerTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexerTest.java @@ -197,8 +197,8 @@ public class ProjectMeasuresIndexerTest { IndexingResult result = indexProject(project, PROJECT_KEY_UPDATE); assertThatIndexContainsOnly(project); - assertThat(result.getTotal()).isEqualTo(1L); - assertThat(result.getSuccess()).isEqualTo(1L); + assertThat(result.getTotal()).isOne(); + assertThat(result.getSuccess()).isOne(); } @Test @@ -208,8 +208,8 @@ public class ProjectMeasuresIndexerTest { IndexingResult result = indexProject(project, PROJECT_CREATION); assertThatIndexContainsOnly(project); - assertThat(result.getTotal()).isEqualTo(1L); - assertThat(result.getSuccess()).isEqualTo(1L); + assertThat(result.getTotal()).isOne(); + assertThat(result.getSuccess()).isOne(); } @Test @@ -225,8 +225,8 @@ public class ProjectMeasuresIndexerTest { IndexingResult result = indexProject(project, PROJECT_TAGS_UPDATE); assertThatProjectHasTag(project, "bar"); - assertThat(result.getTotal()).isEqualTo(1L); - assertThat(result.getSuccess()).isEqualTo(1L); + assertThat(result.getTotal()).isOne(); + assertThat(result.getSuccess()).isOne(); } @Test @@ -239,8 +239,8 @@ public class ProjectMeasuresIndexerTest { IndexingResult result = indexProject(project, PROJECT_DELETION); assertThat(es.countDocuments(TYPE_PROJECT_MEASURES)).isZero(); - assertThat(result.getTotal()).isEqualTo(1L); - assertThat(result.getSuccess()).isEqualTo(1L); + assertThat(result.getTotal()).isOne(); + assertThat(result.getSuccess()).isOne(); } @Test @@ -260,21 +260,21 @@ public class ProjectMeasuresIndexerTest { es.lockWrites(TYPE_PROJECT_MEASURES); IndexingResult result = indexProject(project, PROJECT_CREATION); - assertThat(result.getTotal()).isEqualTo(1L); - assertThat(result.getFailures()).isEqualTo(1L); + assertThat(result.getTotal()).isOne(); + assertThat(result.getFailures()).isOne(); // index is still read-only, fail to recover result = recover(); - assertThat(result.getTotal()).isEqualTo(1L); - assertThat(result.getFailures()).isEqualTo(1L); + assertThat(result.getTotal()).isOne(); + assertThat(result.getFailures()).isOne(); assertThat(es.countDocuments(TYPE_PROJECT_MEASURES)).isZero(); assertThatEsQueueTableHasSize(1); es.unlockWrites(TYPE_PROJECT_MEASURES); result = recover(); - assertThat(result.getTotal()).isEqualTo(1L); - assertThat(result.getFailures()).isEqualTo(0L); + assertThat(result.getTotal()).isOne(); + assertThat(result.getFailures()).isZero(); assertThatEsQueueTableHasSize(0); assertThatIndexContainsOnly(project); } diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/notification/EmailRecipientTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/notification/EmailRecipientTest.java index dc3fcf339fa..528a1724ff2 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/notification/EmailRecipientTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/notification/EmailRecipientTest.java @@ -54,7 +54,7 @@ public class EmailRecipientTest { assertThat(underTest) .isEqualTo(new EmailRecipient(login, email)) - .isNotEqualTo(null) + .isNotNull() .isNotEqualTo(new Object()) .isNotEqualTo(new EmailRecipient(email, login)) .isNotEqualTo(new EmailRecipient(randomAlphabetic(5), email)) 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 6f8a2b18d86..db8121646bb 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 @@ -70,7 +70,7 @@ public class AuthorizationDocTest { public void projectUuidOf_returns_argument_if_does_not_starts_with_id_prefix() { String id = randomAlphabetic(1 + new Random().nextInt(10)); assertThat(AuthorizationDoc.projectUuidOf(id)).isEqualTo(id); - assertThat(AuthorizationDoc.projectUuidOf("")).isEqualTo(""); + assertThat(AuthorizationDoc.projectUuidOf("")).isEmpty(); } @Test diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/platform/UrlSettingsTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/platform/UrlSettingsTest.java index 832145e2650..159f210f8ab 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/platform/UrlSettingsTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/platform/UrlSettingsTest.java @@ -40,7 +40,7 @@ public class UrlSettingsTest { @Test public void use_default_context_path() { - assertThat(underTest().getContextPath()).isEqualTo(""); + assertThat(underTest().getContextPath()).isEmpty(); } @Test diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/project/ProjectTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/project/ProjectTest.java index ef1c1044962..d5e1371d85f 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/project/ProjectTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/project/ProjectTest.java @@ -60,7 +60,7 @@ public class ProjectTest { Project project2 = new Project("U1", "K1", "N1", "D1", emptyList()); assertThat(project1).isEqualTo(project1) - .isNotEqualTo(null) + .isNotNull() .isNotEqualTo(new Object()) .isEqualTo(new Project("U1", "K1", "N1", null, emptyList())) .isNotEqualTo(new Project("U1", "K2", "N1", null, emptyList())) diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/ConditionTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/ConditionTest.java index 1acf39a9985..1225287d8ba 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/ConditionTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/ConditionTest.java @@ -30,7 +30,6 @@ public class ConditionTest { private static final Condition.Operator OPERATOR = Condition.Operator.GREATER_THAN; private static final String ERROR_THRESHOLD = "2"; - private Condition underTest = new Condition(METRIC_KEY, OPERATOR, ERROR_THRESHOLD); @Test @@ -69,29 +68,29 @@ public class ConditionTest { @Test public void equals_is_based_on_all_fields() { - assertThat(underTest).isEqualTo(underTest); - assertThat(underTest).isNotEqualTo(null); - assertThat(underTest).isNotEqualTo(new Object()); - assertThat(underTest).isEqualTo(new Condition(METRIC_KEY, OPERATOR, ERROR_THRESHOLD)); - assertThat(underTest).isNotEqualTo(new Condition("other_metric_key", OPERATOR, ERROR_THRESHOLD)); + assertThat(underTest) + .isEqualTo(underTest) + .isNotNull() + .isNotEqualTo(new Object()) + .isEqualTo(new Condition(METRIC_KEY, OPERATOR, ERROR_THRESHOLD)) + .isNotEqualTo(new Condition("other_metric_key", OPERATOR, ERROR_THRESHOLD)); Arrays.stream(Condition.Operator.values()) - .filter(s -> !OPERATOR.equals(s)) - .forEach(otherOperator -> assertThat(underTest) - .isNotEqualTo(new Condition(METRIC_KEY, otherOperator, ERROR_THRESHOLD))); + .filter(s -> !OPERATOR.equals(s)) + .forEach(otherOperator -> assertThat(underTest) + .isNotEqualTo(new Condition(METRIC_KEY, otherOperator, ERROR_THRESHOLD))); assertThat(underTest).isNotEqualTo(new Condition(METRIC_KEY, OPERATOR, "other_error_threshold")); } @Test public void hashcode_is_based_on_all_fields() { - assertThat(underTest.hashCode()).isEqualTo(underTest.hashCode()); - assertThat(underTest.hashCode()).isNotEqualTo(null); + assertThat(underTest).hasSameHashCodeAs(underTest); assertThat(underTest.hashCode()).isNotEqualTo(new Object().hashCode()); - assertThat(underTest.hashCode()).isEqualTo(new Condition(METRIC_KEY, OPERATOR, ERROR_THRESHOLD).hashCode()); + assertThat(underTest).hasSameHashCodeAs(new Condition(METRIC_KEY, OPERATOR, ERROR_THRESHOLD)); assertThat(underTest.hashCode()).isNotEqualTo(new Condition("other_metric_key", OPERATOR, ERROR_THRESHOLD).hashCode()); Arrays.stream(Condition.Operator.values()) - .filter(s -> !OPERATOR.equals(s)) - .forEach(otherOperator -> assertThat(underTest.hashCode()) - .isNotEqualTo(new Condition(METRIC_KEY, otherOperator, ERROR_THRESHOLD).hashCode())); + .filter(s -> !OPERATOR.equals(s)) + .forEach(otherOperator -> assertThat(underTest.hashCode()) + .isNotEqualTo(new Condition(METRIC_KEY, otherOperator, ERROR_THRESHOLD).hashCode())); assertThat(underTest.hashCode()).isNotEqualTo(new Condition(METRIC_KEY, OPERATOR, "other_error_threshold").hashCode()); } } diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/EvaluatedConditionTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/EvaluatedConditionTest.java index 641301e106a..b8153ed520c 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/EvaluatedConditionTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/EvaluatedConditionTest.java @@ -30,7 +30,6 @@ import static org.sonar.server.qualitygate.EvaluatedCondition.EvaluationStatus.O public class EvaluatedConditionTest { private static final Condition CONDITION_1 = new Condition("metricKey", GREATER_THAN, "2"); - private EvaluatedCondition underTest = new EvaluatedCondition(CONDITION_1, ERROR, "value"); @Test @@ -81,25 +80,26 @@ public class EvaluatedConditionTest { @Test public void equals_is_based_on_all_fields() { - assertThat(underTest).isEqualTo(underTest); - assertThat(underTest).isEqualTo(new EvaluatedCondition(CONDITION_1, ERROR, "value")); - assertThat(underTest).isNotEqualTo(null); - assertThat(underTest).isNotEqualTo(new Object()); - assertThat(underTest).isNotEqualTo(new EvaluatedCondition(new Condition("other_metric", GREATER_THAN, "a"), ERROR, "value")); - assertThat(underTest).isNotEqualTo(new EvaluatedCondition(CONDITION_1, OK, "value")); - assertThat(underTest).isNotEqualTo(new EvaluatedCondition(CONDITION_1, ERROR, null)); - assertThat(underTest).isNotEqualTo(new EvaluatedCondition(CONDITION_1, ERROR, "other_value")); + assertThat(underTest) + .isEqualTo(underTest) + .isEqualTo(new EvaluatedCondition(CONDITION_1, ERROR, "value")) + .isNotNull() + .isNotEqualTo(new Object()) + .isNotEqualTo(new EvaluatedCondition(new Condition("other_metric", GREATER_THAN, "a"), ERROR, "value")) + .isNotEqualTo(new EvaluatedCondition(CONDITION_1, OK, "value")) + .isNotEqualTo(new EvaluatedCondition(CONDITION_1, ERROR, null)) + .isNotEqualTo(new EvaluatedCondition(CONDITION_1, ERROR, "other_value")); } @Test public void hashcode_is_based_on_all_fields() { - assertThat(underTest.hashCode()).isEqualTo(underTest.hashCode()); - assertThat(underTest.hashCode()).isEqualTo(new EvaluatedCondition(CONDITION_1, ERROR, "value").hashCode()); - assertThat(underTest.hashCode()).isNotEqualTo(null); - assertThat(underTest.hashCode()).isNotEqualTo(new Object().hashCode()); - assertThat(underTest.hashCode()).isNotEqualTo(new EvaluatedCondition(new Condition("other_metric", GREATER_THAN, "a"), ERROR, "value").hashCode()); - assertThat(underTest.hashCode()).isNotEqualTo(new EvaluatedCondition(CONDITION_1, OK, "value").hashCode()); - assertThat(underTest.hashCode()).isNotEqualTo(new EvaluatedCondition(CONDITION_1, ERROR, null).hashCode()); - assertThat(underTest.hashCode()).isNotEqualTo(new EvaluatedCondition(CONDITION_1, ERROR, "other_value").hashCode()); + assertThat(underTest) + .hasSameHashCodeAs(underTest) + .hasSameHashCodeAs(new EvaluatedCondition(CONDITION_1, ERROR, "value")); + assertThat(underTest.hashCode()).isNotEqualTo(new Object().hashCode()) + .isNotEqualTo(new EvaluatedCondition(new Condition("other_metric", GREATER_THAN, "a"), ERROR, "value").hashCode()) + .isNotEqualTo(new EvaluatedCondition(CONDITION_1, OK, "value").hashCode()) + .isNotEqualTo(new EvaluatedCondition(CONDITION_1, ERROR, null).hashCode()) + .isNotEqualTo(new EvaluatedCondition(CONDITION_1, ERROR, "other_value").hashCode()); } } diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/EvaluatedQualityGateTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/EvaluatedQualityGateTest.java index 7925687d756..df716f84cfb 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/EvaluatedQualityGateTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/EvaluatedQualityGateTest.java @@ -46,7 +46,6 @@ public class EvaluatedQualityGateTest { private static final QualityGate ALL_CONDITIONS_QUALITY_GATE = new QualityGate(QUALITY_GATE_ID, QUALITY_GATE_NAME, new HashSet<>(Arrays.asList(CONDITION_1, CONDITION_2, CONDITION_3))); - private final Random random = new Random(); private final Level randomStatus = Level.values()[random.nextInt(Level.values().length)]; private final EvaluatedCondition.EvaluationStatus randomEvaluationStatus = EvaluatedCondition.EvaluationStatus.values()[random @@ -66,7 +65,7 @@ public class EvaluatedQualityGateTest { @Test public void addCondition_fails_with_NPE_if_condition_is_null() { - assertThatThrownBy(() -> builder.addEvaluatedCondition(null, EvaluatedCondition.EvaluationStatus.ERROR, "a_value")) + assertThatThrownBy(() -> builder.addEvaluatedCondition(null, EvaluatedCondition.EvaluationStatus.ERROR, "a_value")) .isInstanceOf(NullPointerException.class) .hasMessage("condition can't be null"); } @@ -179,17 +178,18 @@ public class EvaluatedQualityGateTest { .addEvaluatedCondition(CONDITION_1, EvaluatedCondition.EvaluationStatus.ERROR, "foo"); EvaluatedQualityGate underTest = builder.build(); - assertThat(underTest).isEqualTo(builder.build()); - assertThat(underTest).isNotSameAs(builder.build()); - assertThat(underTest).isNotEqualTo(null); - assertThat(underTest).isNotEqualTo(new Object()); - assertThat(underTest).isNotEqualTo(builder.setQualityGate(new QualityGate("other_id", QUALITY_GATE_NAME, singleton(CONDITION_1))).build()); - assertThat(underTest).isNotEqualTo(builder.setQualityGate(ONE_CONDITION_QUALITY_GATE).setStatus(Level.OK).build()); - assertThat(underTest).isNotEqualTo(newBuilder() - .setQualityGate(ONE_CONDITION_QUALITY_GATE) - .setStatus(Level.ERROR) - .addEvaluatedCondition(CONDITION_1, EvaluatedCondition.EvaluationStatus.OK, "foo") - .build()); + assertThat(underTest) + .isEqualTo(builder.build()) + .isNotSameAs(builder.build()) + .isNotNull() + .isNotEqualTo(new Object()) + .isNotEqualTo(builder.setQualityGate(new QualityGate("other_id", QUALITY_GATE_NAME, singleton(CONDITION_1))).build()) + .isNotEqualTo(builder.setQualityGate(ONE_CONDITION_QUALITY_GATE).setStatus(Level.OK).build()) + .isNotEqualTo(newBuilder() + .setQualityGate(ONE_CONDITION_QUALITY_GATE) + .setStatus(Level.ERROR) + .addEvaluatedCondition(CONDITION_1, EvaluatedCondition.EvaluationStatus.OK, "foo") + .build()); } @Test @@ -200,9 +200,8 @@ public class EvaluatedQualityGateTest { .addEvaluatedCondition(CONDITION_1, EvaluatedCondition.EvaluationStatus.ERROR, "foo"); EvaluatedQualityGate underTest = builder.build(); - assertThat(underTest.hashCode()).isEqualTo(builder.build().hashCode()); + assertThat(underTest).hasSameHashCodeAs(builder.build()); assertThat(underTest.hashCode()).isNotSameAs(builder.build().hashCode()); - assertThat(underTest.hashCode()).isNotEqualTo(null); assertThat(underTest.hashCode()).isNotEqualTo(new Object().hashCode()); assertThat(underTest.hashCode()).isNotEqualTo(builder.setQualityGate(new QualityGate("other_id", QUALITY_GATE_NAME, singleton(CONDITION_1))).build().hashCode()); assertThat(underTest.hashCode()).isNotEqualTo(builder.setQualityGate(ONE_CONDITION_QUALITY_GATE).setStatus(Level.OK).build().hashCode()); diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/QualityGateTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/QualityGateTest.java index d6c5bee2f62..6f7c1100f65 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/QualityGateTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/QualityGateTest.java @@ -55,7 +55,7 @@ public class QualityGateTest { @Test public void constructor_fails_with_NPE_if_conditions_is_null() { - assertThatThrownBy(() ->new QualityGate("id", "name", null)) + assertThatThrownBy(() -> new QualityGate("id", "name", null)) .isInstanceOf(NullPointerException.class) .hasMessage("conditions can't be null"); } @@ -65,17 +65,17 @@ public class QualityGateTest { Random random = new Random(); Set<Condition> conditions = Stream.of( - IntStream.range(0, random.nextInt(5)) - .mapToObj(i -> new Condition("m_before_" + i, Condition.Operator.GREATER_THAN, "10")), - Stream.of((Condition) null), - IntStream.range(0, random.nextInt(5)) - .mapToObj(i -> new Condition("m_after_" + i, Condition.Operator.GREATER_THAN, "10"))) + IntStream.range(0, random.nextInt(5)) + .mapToObj(i -> new Condition("m_before_" + i, Condition.Operator.GREATER_THAN, "10")), + Stream.of((Condition) null), + IntStream.range(0, random.nextInt(5)) + .mapToObj(i -> new Condition("m_after_" + i, Condition.Operator.GREATER_THAN, "10"))) .flatMap(s -> s) .collect(Collectors.toSet()); assertThatThrownBy(() -> new QualityGate("id", "name", conditions)) .isInstanceOf(NullPointerException.class) - .hasMessageContaining("condition can't be null"); + .hasMessageContaining("condition can't be null"); } @Test @@ -96,31 +96,32 @@ public class QualityGateTest { @Test public void equals_is_based_on_all_fields() { - assertThat(underTest).isEqualTo(underTest); - assertThat(underTest).isEqualTo(new QualityGate(QUALIGATE_ID, QUALIGATE_NAME, ImmutableSet.of(CONDITION_2, CONDITION_1))); - assertThat(underTest).isNotEqualTo(null); - assertThat(underTest).isNotEqualTo(new Object()); - assertThat(underTest).isNotEqualTo(new QualityGate("other_id", QUALIGATE_NAME, ImmutableSet.of(CONDITION_2, CONDITION_1))); - assertThat(underTest).isNotEqualTo(new QualityGate(QUALIGATE_ID, "other_name", ImmutableSet.of(CONDITION_2, CONDITION_1))); - assertThat(underTest).isNotEqualTo(new QualityGate(QUALIGATE_ID, QUALIGATE_NAME, emptySet())); - assertThat(underTest).isNotEqualTo(new QualityGate(QUALIGATE_ID, QUALIGATE_NAME, ImmutableSet.of(CONDITION_1))); - assertThat(underTest).isNotEqualTo(new QualityGate(QUALIGATE_ID, QUALIGATE_NAME, ImmutableSet.of(CONDITION_2))); - assertThat(underTest).isNotEqualTo( - new QualityGate(QUALIGATE_ID, QUALIGATE_NAME, ImmutableSet.of(CONDITION_1, CONDITION_2, new Condition("new", Condition.Operator.GREATER_THAN, "a")))); + assertThat(underTest) + .isEqualTo(underTest) + .isEqualTo(new QualityGate(QUALIGATE_ID, QUALIGATE_NAME, ImmutableSet.of(CONDITION_2, CONDITION_1))) + .isNotNull() + .isNotEqualTo(new Object()) + .isNotEqualTo(new QualityGate("other_id", QUALIGATE_NAME, ImmutableSet.of(CONDITION_2, CONDITION_1))) + .isNotEqualTo(new QualityGate(QUALIGATE_ID, "other_name", ImmutableSet.of(CONDITION_2, CONDITION_1))) + .isNotEqualTo(new QualityGate(QUALIGATE_ID, QUALIGATE_NAME, emptySet())) + .isNotEqualTo(new QualityGate(QUALIGATE_ID, QUALIGATE_NAME, ImmutableSet.of(CONDITION_1))) + .isNotEqualTo(new QualityGate(QUALIGATE_ID, QUALIGATE_NAME, ImmutableSet.of(CONDITION_2))) + .isNotEqualTo( + new QualityGate(QUALIGATE_ID, QUALIGATE_NAME, ImmutableSet.of(CONDITION_1, CONDITION_2, new Condition("new", Condition.Operator.GREATER_THAN, "a")))); } @Test public void hashcode_is_based_on_all_fields() { - assertThat(underTest.hashCode()).isEqualTo(underTest.hashCode()); - assertThat(underTest.hashCode()).isEqualTo(new QualityGate(QUALIGATE_ID, QUALIGATE_NAME, ImmutableSet.of(CONDITION_2, CONDITION_1)).hashCode()); - assertThat(underTest.hashCode()).isNotEqualTo(null); - assertThat(underTest.hashCode()).isNotEqualTo(new Object().hashCode()); - assertThat(underTest.hashCode()).isNotEqualTo(new QualityGate("other_id", QUALIGATE_NAME, ImmutableSet.of(CONDITION_2, CONDITION_1)).hashCode()); - assertThat(underTest.hashCode()).isNotEqualTo(new QualityGate(QUALIGATE_ID, "other_name", ImmutableSet.of(CONDITION_2, CONDITION_1)).hashCode()); - assertThat(underTest.hashCode()).isNotEqualTo(new QualityGate(QUALIGATE_ID, QUALIGATE_NAME, emptySet()).hashCode()); - assertThat(underTest.hashCode()).isNotEqualTo(new QualityGate(QUALIGATE_ID, QUALIGATE_NAME, ImmutableSet.of(CONDITION_1)).hashCode()); - assertThat(underTest.hashCode()).isNotEqualTo(new QualityGate(QUALIGATE_ID, QUALIGATE_NAME, ImmutableSet.of(CONDITION_2)).hashCode()); - assertThat(underTest.hashCode()).isNotEqualTo( - new QualityGate(QUALIGATE_ID, QUALIGATE_NAME, ImmutableSet.of(CONDITION_1, CONDITION_2, new Condition("new", Condition.Operator.GREATER_THAN, "a"))).hashCode()); + assertThat(underTest) + .hasSameHashCodeAs(underTest) + .hasSameHashCodeAs(new QualityGate(QUALIGATE_ID, QUALIGATE_NAME, ImmutableSet.of(CONDITION_2, CONDITION_1))); + assertThat(underTest.hashCode()).isNotEqualTo(new Object().hashCode()) + .isNotEqualTo(new QualityGate("other_id", QUALIGATE_NAME, ImmutableSet.of(CONDITION_2, CONDITION_1)).hashCode()) + .isNotEqualTo(new QualityGate(QUALIGATE_ID, "other_name", ImmutableSet.of(CONDITION_2, CONDITION_1)).hashCode()) + .isNotEqualTo(new QualityGate(QUALIGATE_ID, QUALIGATE_NAME, emptySet()).hashCode()) + .isNotEqualTo(new QualityGate(QUALIGATE_ID, QUALIGATE_NAME, ImmutableSet.of(CONDITION_1)).hashCode()) + .isNotEqualTo(new QualityGate(QUALIGATE_ID, QUALIGATE_NAME, ImmutableSet.of(CONDITION_2)).hashCode()) + .isNotEqualTo( + new QualityGate(QUALIGATE_ID, QUALIGATE_NAME, ImmutableSet.of(CONDITION_1, CONDITION_2, new Condition("new", Condition.Operator.GREATER_THAN, "a"))).hashCode()); } } diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/qualityprofile/ActiveRuleChangeTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/qualityprofile/ActiveRuleChangeTest.java index 5f1a7db815c..f52f52c7b1c 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/qualityprofile/ActiveRuleChangeTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/qualityprofile/ActiveRuleChangeTest.java @@ -47,6 +47,6 @@ public class ActiveRuleChangeTest { assertThat(result.getChangeType()).isEqualTo(ACTIVATED.name()); assertThat(result.getRulesProfileUuid()).isEqualTo(profile.getRulesProfileUuid()); assertThat(result.getUserUuid()).isEqualTo(A_USER_UUID); - assertThat(result.getDataAsMap().get("ruleUuid")).isEqualTo(ruleUuid); + assertThat(result.getDataAsMap()).containsEntry("ruleUuid", ruleUuid); } } diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/qualityprofile/QualityProfileTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/qualityprofile/QualityProfileTest.java index d155a16800c..eb9de539bb6 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/qualityprofile/QualityProfileTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/qualityprofile/QualityProfileTest.java @@ -36,9 +36,7 @@ public class QualityProfileTest { @Test public void constructor_throws_NPE_if_qkKey_arg_is_null() { - assertThatThrownBy(() -> { - new QualityProfile(null, SOME_QP_NAME, SOME_LANGUAGE_KEY, SOME_DATE); - }) + assertThatThrownBy(() -> new QualityProfile(null, SOME_QP_NAME, SOME_LANGUAGE_KEY, SOME_DATE)) .isInstanceOf(NullPointerException.class); } @@ -82,9 +80,10 @@ public class QualityProfileTest { @Test public void verify_equals() { - assertThat(QUALITY_PROFILE).isEqualTo(new QualityProfile(SOME_QP_KEY, SOME_QP_NAME, SOME_LANGUAGE_KEY, SOME_DATE)); - assertThat(QUALITY_PROFILE).isEqualTo(QUALITY_PROFILE); - assertThat(QUALITY_PROFILE).isNotEqualTo(null); + assertThat(QUALITY_PROFILE) + .isEqualTo(new QualityProfile(SOME_QP_KEY, SOME_QP_NAME, SOME_LANGUAGE_KEY, SOME_DATE)) + .isEqualTo(QUALITY_PROFILE) + .isNotNull(); } @Test diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest.java index c1a778231c2..cbf67faf73d 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest.java @@ -139,7 +139,7 @@ public class ActiveRuleIndexerTest { public void commitAndIndex_deletes_the_documents_that_dont_exist_in_database() { ActiveRuleDto ar = db.qualityProfiles().activateRule(profile1, rule1); indexAll(); - assertThat(es.countDocuments(TYPE_ACTIVE_RULE)).isEqualTo(1); + assertThat(es.countDocuments(TYPE_ACTIVE_RULE)).isOne(); db.getDbClient().activeRuleDao().delete(db.getSession(), ar.getKey()); commitAndIndex(rule1, ar); @@ -176,11 +176,11 @@ public class ActiveRuleIndexerTest { public void commitDeletionOfProfiles_does_nothing_if_profiles_are_not_indexed() { db.qualityProfiles().activateRule(profile1, rule1); indexAll(); - assertThat(es.countDocuments(TYPE_ACTIVE_RULE)).isEqualTo(1); + assertThat(es.countDocuments(TYPE_ACTIVE_RULE)).isOne(); underTest.commitDeletionOfProfiles(db.getSession(), singletonList(profile2)); - assertThat(es.countDocuments(TYPE_ACTIVE_RULE)).isEqualTo(1); + assertThat(es.countDocuments(TYPE_ACTIVE_RULE)).isOne(); } private void assertThatEsQueueTableIsEmpty() { diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexDefinitionTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexDefinitionTest.java index 1dacc4c7f40..635cb066fea 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexDefinitionTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexDefinitionTest.java @@ -98,7 +98,7 @@ public class RuleIndexDefinitionTest { FIELD_RULE_HTML_DESCRIPTION, longText, FIELD_RULE_REPOSITORY, "squid", FIELD_RULE_KEY, "squid:S001"))); - assertThat(tester.countDocuments(TYPE_RULE)).isEqualTo(1); + assertThat(tester.countDocuments(TYPE_RULE)).isOne(); assertThat(tester.client().search(EsClient.prepareSearch(TYPE_RULE) .source(new SearchSourceBuilder() .query(matchQuery(ENGLISH_HTML_ANALYZER.subField(FIELD_RULE_HTML_DESCRIPTION), "brown fox jumps lazy")))) diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexTest.java index 206eba38cb4..ace423241a9 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexTest.java @@ -622,7 +622,7 @@ public class RuleIndexTest { private void verifySearch(RuleQuery query, RuleDefinitionDto... expectedRules) { SearchIdResult<String> result = underTest.search(query, new SearchOptions()); - assertThat(result.getTotal()).isEqualTo((long) expectedRules.length); + assertThat(result.getTotal()).isEqualTo(expectedRules.length); assertThat(result.getUuids()).hasSize(expectedRules.length); for (RuleDefinitionDto expectedRule : expectedRules) { assertThat(result.getUuids()).contains(expectedRule.getUuid()); @@ -829,10 +829,10 @@ public class RuleIndexTest { FACET_TAGS, FACET_TYPES))); Map<String, LinkedHashMap<String, Long>> facets = result.getFacets().getAll(); assertThat(facets).hasSize(4); - assertThat(facets.get(FACET_LANGUAGES).keySet()).containsOnly("cpp", "java", "cobol"); + assertThat(facets.get(FACET_LANGUAGES)).containsOnlyKeys("cpp", "java", "cobol"); assertThat(facets.get(FACET_REPOSITORIES).keySet()).containsExactly("xoo", "foo"); - assertThat(facets.get(FACET_TAGS).keySet()).containsOnly("T1", "T2", "T3", "T4"); - assertThat(facets.get(FACET_TYPES).keySet()).containsOnly("BUG", "CODE_SMELL", "VULNERABILITY"); + assertThat(facets.get(FACET_TAGS)).containsOnlyKeys("T1", "T2", "T3", "T4"); + assertThat(facets.get(FACET_TYPES)).containsOnlyKeys("BUG", "CODE_SMELL", "VULNERABILITY"); } /** @@ -847,9 +847,9 @@ public class RuleIndexTest { SearchIdResult<String> result = underTest.search(query, new SearchOptions().addFacets(asList(FACET_LANGUAGES, FACET_REPOSITORIES, FACET_TAGS))); assertThat(result.getUuids()).hasSize(3); assertThat(result.getFacets().getAll()).hasSize(3); - assertThat(result.getFacets().get(FACET_LANGUAGES).keySet()).containsOnly("cpp", "java", "cobol"); - assertThat(result.getFacets().get(FACET_REPOSITORIES).keySet()).containsOnly("foo"); - assertThat(result.getFacets().get(FACET_TAGS).keySet()).containsOnly("T2", "T3"); + assertThat(result.getFacets().get(FACET_LANGUAGES)).containsOnlyKeys("cpp", "java", "cobol"); + assertThat(result.getFacets().get(FACET_REPOSITORIES)).containsOnlyKeys("foo"); + assertThat(result.getFacets().get(FACET_TAGS)).containsOnlyKeys("T2", "T3"); } @Test @@ -859,7 +859,7 @@ public class RuleIndexTest { SearchIdResult<String> result = underTest.search(new RuleQuery(), new SearchOptions().addFacets(singletonList(FACET_LANGUAGES))); - assertThat(result.getFacets().get(FACET_LANGUAGES).size()).isEqualTo(100); + assertThat(result.getFacets().get(FACET_LANGUAGES)).hasSize(100); } @Test @@ -869,7 +869,7 @@ public class RuleIndexTest { SearchIdResult<String> result = underTest.search(new RuleQuery(), new SearchOptions().addFacets(singletonList(FACET_REPOSITORIES))); - assertThat(result.getFacets().get(FACET_REPOSITORIES).size()).isEqualTo(10); + assertThat(result.getFacets().get(FACET_REPOSITORIES)).hasSize(10); } @Test @@ -895,7 +895,7 @@ public class RuleIndexTest { RuleQuery query = new RuleQuery(); SearchOptions options = new SearchOptions().addFacets(singletonList(FACET_TAGS)); SearchIdResult<String> result = underTest.search(query, options); - assertThat(result.getFacets().get(FACET_TAGS).size()).isEqualTo(100); + assertThat(result.getFacets().get(FACET_TAGS)).hasSize(100); assertThat(result.getFacets().get(FACET_TAGS)).contains(entry("tag0", 1L), entry("tag25", 1L), entry("tag99", 1L)); assertThat(result.getFacets().get(FACET_TAGS)).doesNotContain(entry("tagA", 1L)); } @@ -911,7 +911,7 @@ public class RuleIndexTest { .setTags(singletonList("tagA")); SearchOptions options = new SearchOptions().addFacets(singletonList(FACET_TAGS)); SearchIdResult<String> result = underTest.search(query, options); - assertThat(result.getFacets().get(FACET_TAGS).size()).isEqualTo(101); + assertThat(result.getFacets().get(FACET_TAGS)).hasSize(101); assertThat(result.getFacets().get(FACET_TAGS).entrySet()).extracting(e -> entry(e.getKey(), e.getValue())).contains( // check that selected item is added, although there are 100 other items @@ -948,9 +948,9 @@ public class RuleIndexTest { assertThat(result.getUuids()).hasSize(1); Facets facets = result.getFacets(); assertThat(facets.getAll()).hasSize(3); - assertThat(facets.get(FACET_LANGUAGES).keySet()).containsOnly("cpp", "java"); - assertThat(facets.get(FACET_REPOSITORIES).keySet()).containsOnly("foo"); - assertThat(facets.get(FACET_TAGS).keySet()).containsOnly("T2", "T3"); + assertThat(facets.get(FACET_LANGUAGES)).containsOnlyKeys("cpp", "java"); + assertThat(facets.get(FACET_REPOSITORIES)).containsOnlyKeys("foo"); + assertThat(facets.get(FACET_TAGS)).containsOnlyKeys("T2", "T3"); } /** @@ -973,10 +973,10 @@ public class RuleIndexTest { FACET_TYPES))); assertThat(result.getUuids()).hasSize(2); assertThat(result.getFacets().getAll()).hasSize(4); - assertThat(result.getFacets().get(FACET_LANGUAGES).keySet()).containsOnly("cpp", "java"); - assertThat(result.getFacets().get(FACET_REPOSITORIES).keySet()).containsOnly("foo", "xoo"); - assertThat(result.getFacets().get(FACET_TAGS).keySet()).containsOnly("T1", "T2", "T3"); - assertThat(result.getFacets().get(FACET_TYPES).keySet()).containsOnly("CODE_SMELL"); + assertThat(result.getFacets().get(FACET_LANGUAGES)).containsOnlyKeys("cpp", "java"); + assertThat(result.getFacets().get(FACET_REPOSITORIES)).containsOnlyKeys("foo", "xoo"); + assertThat(result.getFacets().get(FACET_TAGS)).containsOnlyKeys("T1", "T2", "T3"); + assertThat(result.getFacets().get(FACET_TYPES)).containsOnlyKeys("CODE_SMELL"); } @Test diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexerTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexerTest.java index ab9e0080d0f..4c8f7d0ef8d 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexerTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexerTest.java @@ -98,7 +98,7 @@ public class RuleIndexerTest { @Test public void index_nothing() { underTest.index(dbSession, emptyList()); - assertThat(es.countDocuments(TYPE_RULE)).isEqualTo(0L); + assertThat(es.countDocuments(TYPE_RULE)).isZero(); } @Test @@ -106,7 +106,7 @@ public class RuleIndexerTest { dbClient.ruleDao().insert(dbSession, rule); underTest.commitAndIndex(dbSession, rule.getUuid()); - assertThat(es.countDocuments(TYPE_RULE)).isEqualTo(1); + assertThat(es.countDocuments(TYPE_RULE)).isOne(); } @Test @@ -115,13 +115,13 @@ public class RuleIndexerTest { dbClient.ruleDao().insert(dbSession, rule.setStatus(RuleStatus.READY)); dbSession.commit(); underTest.commitAndIndex(dbTester.getSession(), rule.getUuid()); - assertThat(es.countDocuments(TYPE_RULE)).isEqualTo(1); + assertThat(es.countDocuments(TYPE_RULE)).isOne(); // Remove rule dbTester.getDbClient().ruleDao().update(dbTester.getSession(), rule.setStatus(RuleStatus.READY).setUpdatedAt(2000000000000L)); underTest.commitAndIndex(dbTester.getSession(), rule.getUuid()); - assertThat(es.countDocuments(TYPE_RULE)).isEqualTo(1); + assertThat(es.countDocuments(TYPE_RULE)).isOne(); } @Test @@ -130,7 +130,7 @@ public class RuleIndexerTest { RuleDefinitionDto rule = dbTester.rules().insert(r -> r.setDescription(description)); underTest.commitAndIndex(dbTester.getSession(), rule.getUuid()); - assertThat(es.countDocuments(TYPE_RULE)).isEqualTo(1); + assertThat(es.countDocuments(TYPE_RULE)).isOne(); } @Test diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/setting/DatabaseSettingLoaderTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/setting/DatabaseSettingLoaderTest.java index 2d9cfd43b02..fc40b9fb13e 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/setting/DatabaseSettingLoaderTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/setting/DatabaseSettingLoaderTest.java @@ -50,13 +50,13 @@ public class DatabaseSettingLoaderTest { public void null_value_in_db_is_considered_as_empty_string() { insertPropertyIntoDb(A_KEY, null); - assertThat(underTest.load(A_KEY)).isEqualTo(""); + assertThat(underTest.load(A_KEY)).isEmpty(); } @Test public void test_empty_value_in_db() { insertPropertyIntoDb(A_KEY, ""); - assertThat(underTest.load(A_KEY)).isEqualTo(""); + assertThat(underTest.load(A_KEY)).isEmpty(); } @Test diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/setting/ThreadLocalSettingsTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/setting/ThreadLocalSettingsTest.java index 284eb6e4d23..5655f9e3df8 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/setting/ThreadLocalSettingsTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/setting/ThreadLocalSettingsTest.java @@ -121,7 +121,7 @@ public class ThreadLocalSettingsTest { underTest = create(system, ImmutableMap.of("foo", "from_system")); assertThat(underTest.get("foo")).hasValue("from_system"); - assertThat(underTest.getProperties().get("foo")).isEqualTo("from_system"); + assertThat(underTest.getProperties()).containsEntry("foo", "from_system"); } @Test diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/user/index/UserIndexerTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/user/index/UserIndexerTest.java index cea87c4183c..8f789825694 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/user/index/UserIndexerTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/user/index/UserIndexerTest.java @@ -48,7 +48,7 @@ public class UserIndexerTest { public void index_nothing_on_startup() { underTest.indexOnStartup(new HashSet<>()); - assertThat(es.countDocuments(TYPE_USER)).isEqualTo(0L); + assertThat(es.countDocuments(TYPE_USER)).isZero(); } @Test diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java index c6afeab94f4..291595f179a 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java @@ -60,7 +60,7 @@ public class ViewIndexerTest { @Test public void index_nothing() { underTest.indexOnStartup(emptySet()); - assertThat(es.countDocuments(TYPE_VIEW)).isEqualTo(0L); + assertThat(es.countDocuments(TYPE_VIEW)).isZero(); } @Test diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/webhook/ProjectAnalysisTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/webhook/ProjectAnalysisTest.java index 491965a80a7..f95f5bb2988 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/webhook/ProjectAnalysisTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/webhook/ProjectAnalysisTest.java @@ -93,19 +93,20 @@ public class ProjectAnalysisTest { @Test public void defines_equals_based_on_all_fields() { - assertThat(underTest).isEqualTo(underTest); - assertThat(underTest).isEqualTo(new ProjectAnalysis(project, ceTask, analysis, branch, qualityGate, 1L, properties)); - assertThat(underTest).isNotEqualTo(null); - assertThat(underTest).isNotEqualTo(new Object()); - assertThat(underTest).isNotEqualTo(new ProjectAnalysis(project, new CeTask("2", CeTask.Status.SUCCESS), analysis, branch, qualityGate, 1L, properties)); - assertThat(underTest).isNotEqualTo(new ProjectAnalysis(new Project("A", "B", "C"), ceTask, analysis, branch, qualityGate, 1L, properties)); - assertThat(underTest).isNotEqualTo(new ProjectAnalysis(new Project("A", "B", "C"), ceTask, analysis, branch, qualityGate, 1L, properties)); - assertThat(underTest).isNotEqualTo(new ProjectAnalysis(project, null, null, null, qualityGate, 1L, properties)); - assertThat(underTest).isNotEqualTo(new ProjectAnalysis(project, ceTask, null, null, qualityGate, 1L, properties)); - assertThat(underTest).isNotEqualTo(new ProjectAnalysis(project, ceTask, new Analysis("foo", 1_500L, "sha1"), null, qualityGate, 1L, properties)); - assertThat(underTest).isNotEqualTo(new ProjectAnalysis(project, ceTask, analysis, null, qualityGate, 1L, properties)); - assertThat(underTest).isNotEqualTo(new ProjectAnalysis(project, ceTask, analysis, new Branch(false, "B", Branch.Type.BRANCH), qualityGate, 1L, properties)); - assertThat(underTest).isNotEqualTo(new ProjectAnalysis(project, ceTask, analysis, branch, null, 1L, properties)); + assertThat(underTest) + .isEqualTo(underTest) + .isEqualTo(new ProjectAnalysis(project, ceTask, analysis, branch, qualityGate, 1L, properties)) + .isNotNull() + .isNotEqualTo(new Object()) + .isNotEqualTo(new ProjectAnalysis(project, new CeTask("2", CeTask.Status.SUCCESS), analysis, branch, qualityGate, 1L, properties)) + .isNotEqualTo(new ProjectAnalysis(new Project("A", "B", "C"), ceTask, analysis, branch, qualityGate, 1L, properties)) + .isNotEqualTo(new ProjectAnalysis(new Project("A", "B", "C"), ceTask, analysis, branch, qualityGate, 1L, properties)) + .isNotEqualTo(new ProjectAnalysis(project, null, null, null, qualityGate, 1L, properties)) + .isNotEqualTo(new ProjectAnalysis(project, ceTask, null, null, qualityGate, 1L, properties)) + .isNotEqualTo(new ProjectAnalysis(project, ceTask, new Analysis("foo", 1_500L, "sha1"), null, qualityGate, 1L, properties)) + .isNotEqualTo(new ProjectAnalysis(project, ceTask, analysis, null, qualityGate, 1L, properties)) + .isNotEqualTo(new ProjectAnalysis(project, ceTask, analysis, new Branch(false, "B", Branch.Type.BRANCH), qualityGate, 1L, properties)) + .isNotEqualTo(new ProjectAnalysis(project, ceTask, analysis, branch, null, 1L, properties)); EvaluatedQualityGate otherQualityGate = EvaluatedQualityGate.newBuilder() .setQualityGate(new QualityGate("A", "B", emptySet())) .setStatus(Metric.Level.ERROR) @@ -119,29 +120,33 @@ public class ProjectAnalysisTest { @Test public void defines_hashcode_based_on_all_fields() { - assertThat(underTest.hashCode()).isEqualTo(underTest.hashCode()); - assertThat(underTest.hashCode()).isEqualTo(new ProjectAnalysis(project, ceTask, analysis, branch, qualityGate, 1L, properties).hashCode()); - assertThat(underTest.hashCode()).isNotEqualTo(new Object().hashCode()); - assertThat(underTest.hashCode()).isNotEqualTo(new ProjectAnalysis(project, new CeTask("2", CeTask.Status.SUCCESS), analysis, branch, qualityGate, 1L, properties).hashCode()); - assertThat(underTest.hashCode()).isNotEqualTo(new ProjectAnalysis(new Project("A", "B", "C"), ceTask, analysis, branch, qualityGate, 1L, properties).hashCode()); - assertThat(underTest.hashCode()).isNotEqualTo(new ProjectAnalysis(new Project("A", "B", "C"), ceTask, analysis, branch, qualityGate, 1L, properties).hashCode()); - assertThat(underTest.hashCode()).isNotEqualTo(new ProjectAnalysis(project, null, null, null, qualityGate, 1L, properties).hashCode()); - assertThat(underTest.hashCode()).isNotEqualTo(new ProjectAnalysis(project, ceTask, null, null, qualityGate, 1L, properties).hashCode()); - assertThat(underTest.hashCode()).isNotEqualTo(new ProjectAnalysis(project, ceTask, new Analysis("foo", 1_500L, "sha1"), null, qualityGate, 1L, properties).hashCode()); - assertThat(underTest.hashCode()).isNotEqualTo(new ProjectAnalysis(project, ceTask, analysis, null, qualityGate, 1L, properties).hashCode()); + assertThat(underTest) + .hasSameHashCodeAs(underTest) + .hasSameHashCodeAs(new ProjectAnalysis(project, ceTask, analysis, branch, qualityGate, 1L, properties)); + assertThat(underTest.hashCode()) - .isNotEqualTo(new ProjectAnalysis(project, ceTask, analysis, new Branch(false, "B", Branch.Type.BRANCH), qualityGate, 1L, properties).hashCode()); - assertThat(underTest.hashCode()).isNotEqualTo(new ProjectAnalysis(project, ceTask, analysis, branch, null, 1L, properties).hashCode()); + .isNotEqualTo(new Object().hashCode()) + .isNotEqualTo(new ProjectAnalysis(project, new CeTask("2", CeTask.Status.SUCCESS), analysis, branch, qualityGate, 1L, properties).hashCode()) + .isNotEqualTo(new ProjectAnalysis(new Project("A", "B", "C"), ceTask, analysis, branch, qualityGate, 1L, properties).hashCode()) + .isNotEqualTo(new ProjectAnalysis(new Project("A", "B", "C"), ceTask, analysis, branch, qualityGate, 1L, properties).hashCode()) + .isNotEqualTo(new ProjectAnalysis(project, null, null, null, qualityGate, 1L, properties).hashCode()) + .isNotEqualTo(new ProjectAnalysis(project, ceTask, null, null, qualityGate, 1L, properties).hashCode()) + .isNotEqualTo(new ProjectAnalysis(project, ceTask, new Analysis("foo", 1_500L, "sha1"), null, qualityGate, 1L, properties).hashCode()) + .isNotEqualTo(new ProjectAnalysis(project, ceTask, analysis, null, qualityGate, 1L, properties).hashCode()) + .isNotEqualTo(new ProjectAnalysis(project, ceTask, analysis, new Branch(false, "B", Branch.Type.BRANCH), qualityGate, 1L, properties).hashCode()) + .isNotEqualTo(new ProjectAnalysis(project, ceTask, analysis, branch, null, 1L, properties).hashCode()); + EvaluatedQualityGate otherQualityGate = EvaluatedQualityGate.newBuilder() .setQualityGate(new QualityGate("A", "B", emptySet())) .setStatus(Metric.Level.ERROR) .build(); + assertThat(underTest.hashCode()) - .isNotEqualTo(new ProjectAnalysis(project, ceTask, analysis, branch, otherQualityGate, 1L, properties).hashCode()); - assertThat(underTest.hashCode()).isNotEqualTo(new ProjectAnalysis(project, ceTask, analysis, branch, this.qualityGate, null, properties).hashCode()); - assertThat(underTest.hashCode()).isNotEqualTo(new ProjectAnalysis(project, ceTask, analysis, branch, this.qualityGate, 2L, properties).hashCode()); - assertThat(underTest.hashCode()).isNotEqualTo(new ProjectAnalysis(project, ceTask, analysis, branch, this.qualityGate, 1L, emptyMap()).hashCode()); - assertThat(underTest.hashCode()).isNotEqualTo(new ProjectAnalysis(project, ceTask, analysis, branch, this.qualityGate, 1L, ImmutableMap.of("B", "C")).hashCode()); + .isNotEqualTo(new ProjectAnalysis(project, ceTask, analysis, branch, otherQualityGate, 1L, properties).hashCode()) + .isNotEqualTo(new ProjectAnalysis(project, ceTask, analysis, branch, this.qualityGate, null, properties).hashCode()) + .isNotEqualTo(new ProjectAnalysis(project, ceTask, analysis, branch, this.qualityGate, 2L, properties).hashCode()) + .isNotEqualTo(new ProjectAnalysis(project, ceTask, analysis, branch, this.qualityGate, 1L, emptyMap()).hashCode()) + .isNotEqualTo(new ProjectAnalysis(project, ceTask, analysis, branch, this.qualityGate, 1L, ImmutableMap.of("B", "C")).hashCode()); } @Test diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/webhook/SynchronousWebHooksImplTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/webhook/SynchronousWebHooksImplTest.java index 1a09af24652..ef19614e4b3 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/webhook/SynchronousWebHooksImplTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/webhook/SynchronousWebHooksImplTest.java @@ -136,7 +136,7 @@ public class SynchronousWebHooksImplTest { underTest.sendProjectAnalysisUpdate(new WebHooks.Analysis(projectDto.getUuid(), "1", "#1"), () -> mock, taskStatistics); - assertThat(caller.countSent()).isEqualTo(1); + assertThat(caller.countSent()).isOne(); assertThat(logTester.logs(DEBUG)).contains("Sent webhook 'First' | url=http://url1 | time=1234ms | status=200"); verify(deliveryStorage).persist(any(WebhookDelivery.class)); verify(deliveryStorage).purge(projectDto.getUuid()); diff --git a/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/ServerPluginRepository.java b/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/ServerPluginRepository.java index ace04fd1a0a..3a28d206038 100644 --- a/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/ServerPluginRepository.java +++ b/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/ServerPluginRepository.java @@ -60,7 +60,7 @@ public class ServerPluginRepository implements PluginRepository { @Override public Collection<PluginInfo> getPluginInfos() { - return Collections.unmodifiableCollection(pluginByKey.values().stream().map(ServerPlugin::getPluginInfo).collect(Collectors.toList())); + return pluginByKey.values().stream().map(ServerPlugin::getPluginInfo).collect(Collectors.toUnmodifiableList()); } @Override diff --git a/server/sonar-webserver-api/src/test/java/org/sonar/server/exceptions/MessageTest.java b/server/sonar-webserver-api/src/test/java/org/sonar/server/exceptions/MessageTest.java index bf3e75dbc1e..25a75923ccb 100644 --- a/server/sonar-webserver-api/src/test/java/org/sonar/server/exceptions/MessageTest.java +++ b/server/sonar-webserver-api/src/test/java/org/sonar/server/exceptions/MessageTest.java @@ -57,19 +57,21 @@ public class MessageTest { Message message4 = Message.of("key1%s", "param2"); Message sameAsMessage1 = Message.of("key1%s", "param1"); - assertThat(message1).isEqualTo(message1); - assertThat(message1).isNotEqualTo(message2); - assertThat(message1).isNotEqualTo(message3); - assertThat(message1).isNotEqualTo(message4); - assertThat(message1).isEqualTo(sameAsMessage1); - assertThat(message1).isNotEqualTo(null); - assertThat(message1).isNotEqualTo(new Object()); + assertThat(message1) + .isEqualTo(message1) + .isNotEqualTo(message2) + .isNotEqualTo(message3) + .isNotEqualTo(message4) + .isEqualTo(sameAsMessage1) + .isNotNull() + .isNotEqualTo(new Object()) + .hasSameHashCodeAs(message1) + .hasSameHashCodeAs(sameAsMessage1); - assertThat(message1.hashCode()).isEqualTo(message1.hashCode()); - assertThat(message1.hashCode()).isNotEqualTo(message2.hashCode()); - assertThat(message1.hashCode()).isNotEqualTo(message3.hashCode()); - assertThat(message1.hashCode()).isNotEqualTo(message4.hashCode()); - assertThat(message1.hashCode()).isEqualTo(sameAsMessage1.hashCode()); + assertThat(message1.hashCode()) + .isNotEqualTo(message2.hashCode()) + .isNotEqualTo(message3.hashCode()) + .isNotEqualTo(message4.hashCode()); } @Test diff --git a/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/ServerPluginRepositoryTest.java b/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/ServerPluginRepositoryTest.java index 461c5d9f255..37578713596 100644 --- a/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/ServerPluginRepositoryTest.java +++ b/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/ServerPluginRepositoryTest.java @@ -22,6 +22,7 @@ package org.sonar.server.plugins; import java.util.Arrays; import java.util.Collection; import java.util.Collections; + import org.junit.Assert; import org.junit.Test; import org.sonar.api.Plugin; diff --git a/server/sonar-webserver-api/src/test/java/org/sonar/server/project/RekeyedProjectTest.java b/server/sonar-webserver-api/src/test/java/org/sonar/server/project/RekeyedProjectTest.java index e743cfc5ec6..aa8c0f57136 100644 --- a/server/sonar-webserver-api/src/test/java/org/sonar/server/project/RekeyedProjectTest.java +++ b/server/sonar-webserver-api/src/test/java/org/sonar/server/project/RekeyedProjectTest.java @@ -59,12 +59,13 @@ public class RekeyedProjectTest { String previousKey = randomAlphanumeric(6); RekeyedProject underTest = new RekeyedProject(project, previousKey); - assertThat(underTest).isEqualTo(underTest); - assertThat(underTest).isEqualTo(new RekeyedProject(project, previousKey)); - assertThat(underTest).isNotEqualTo(new RekeyedProject(project, randomAlphanumeric(11))); - assertThat(underTest).isNotEqualTo(new RekeyedProject(newRandomProject(), previousKey)); - assertThat(underTest).isNotEqualTo(new Object()); - assertThat(underTest).isNotEqualTo(null); + assertThat(underTest) + .isEqualTo(underTest) + .isEqualTo(new RekeyedProject(project, previousKey)) + .isNotEqualTo(new RekeyedProject(project, randomAlphanumeric(11))) + .isNotEqualTo(new RekeyedProject(newRandomProject(), previousKey)) + .isNotEqualTo(new Object()) + .isNotNull(); } @Test @@ -73,12 +74,13 @@ public class RekeyedProjectTest { String previousKey = randomAlphanumeric(6); RekeyedProject underTest = new RekeyedProject(project, previousKey); - assertThat(underTest.hashCode()).isEqualTo(underTest.hashCode()); - assertThat(underTest.hashCode()).isEqualTo(new RekeyedProject(project, previousKey).hashCode()); - assertThat(underTest.hashCode()).isNotEqualTo(new RekeyedProject(project, randomAlphanumeric(11)).hashCode()); - assertThat(underTest.hashCode()).isNotEqualTo(new RekeyedProject(newRandomProject(), previousKey).hashCode()); - assertThat(underTest.hashCode()).isNotEqualTo(new Object().hashCode()); - assertThat(underTest.hashCode()).isNotEqualTo(null); + assertThat(underTest) + .hasSameHashCodeAs(underTest) + .hasSameHashCodeAs(new RekeyedProject(project, previousKey)); + assertThat(underTest.hashCode()) + .isNotEqualTo(new RekeyedProject(project, randomAlphanumeric(11)).hashCode()) + .isNotEqualTo(new RekeyedProject(newRandomProject(), previousKey).hashCode()) + .isNotEqualTo(new Object().hashCode()); } @Test diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/authentication/CredentialsLocalAuthentication.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/authentication/CredentialsLocalAuthentication.java index fe7dcc2ce72..db42569ef58 100644 --- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/authentication/CredentialsLocalAuthentication.java +++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/authentication/CredentialsLocalAuthentication.java @@ -60,7 +60,7 @@ public class CredentialsLocalAuthentication { private final EnumMap<HashMethod, HashFunction> hashFunctions = new EnumMap<>(HashMethod.class); public enum HashMethod { - SHA1, BCRYPT, PBKDF2; + SHA1, BCRYPT, PBKDF2 } public CredentialsLocalAuthentication(DbClient dbClient, Configuration configuration) { diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/authentication/IdentityProviderRepository.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/authentication/IdentityProviderRepository.java index 398ed500a1c..9c1f6fc693b 100644 --- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/authentication/IdentityProviderRepository.java +++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/authentication/IdentityProviderRepository.java @@ -26,11 +26,10 @@ import com.google.common.collect.Ordering; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import javax.annotation.Nonnull; import org.sonar.api.server.authentication.IdentityProvider; -import static com.google.common.collect.FluentIterable.from; - public class IdentityProviderRepository { protected final Map<String, IdentityProvider> providersByKey = new HashMap<>(); @@ -43,7 +42,7 @@ public class IdentityProviderRepository { * Used by pico when no identity provider available */ public IdentityProviderRepository() { - this.providersByKey.clear(); + // nothing to do } public IdentityProvider getEnabledByKey(String key) { @@ -55,11 +54,10 @@ public class IdentityProviderRepository { } public List<IdentityProvider> getAllEnabledAndSorted() { - return from(providersByKey.values()) + return providersByKey.values().stream() .filter(IsEnabledFilter.INSTANCE) - .toSortedList( - Ordering.natural().onResultOf(ToName.INSTANCE) - ); + .sorted(Ordering.natural().onResultOf(ToName.INSTANCE)) + .collect(Collectors.toList()); } private enum IsEnabledFilter implements Predicate<IdentityProvider> { diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/BasicAuthenticationTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/BasicAuthenticationTest.java index d5c8d769c96..b041162a1f8 100644 --- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/BasicAuthenticationTest.java +++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/BasicAuthenticationTest.java @@ -139,7 +139,7 @@ public class BasicAuthenticationTest { Optional<UserDto> userAuthenticated = underTest.authenticate(request); - assertThat(userAuthenticated.isPresent()).isTrue(); + assertThat(userAuthenticated).isPresent(); assertThat(userAuthenticated.get().getLogin()).isEqualTo(user.getLogin()); verify(authenticationEvent).loginSuccess(request, user.getLogin(), Source.local(BASIC_TOKEN)); } diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/CredentialsTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/CredentialsTest.java index 5f2b4a1faa3..d9963c10b4c 100644 --- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/CredentialsTest.java +++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/CredentialsTest.java @@ -59,11 +59,11 @@ public class CredentialsTest { @Test public void test_equality() { - assertThat(new Credentials("foo", "bar")).isEqualTo(new Credentials("foo", "bar")); - assertThat(new Credentials("foo", "bar")).isNotEqualTo(new Credentials("foo", "baaaar")); - assertThat(new Credentials("foo", "bar")).isNotEqualTo(new Credentials("foooooo", "bar")); - assertThat(new Credentials("foo", "bar")).isNotEqualTo(new Credentials("foo", null)); - - assertThat(new Credentials("foo", "bar").hashCode()).isEqualTo(new Credentials("foo", "bar").hashCode()); + assertThat(new Credentials("foo", "bar")) + .isEqualTo(new Credentials("foo", "bar")) + .isNotEqualTo(new Credentials("foo", "baaaar")) + .isNotEqualTo(new Credentials("foooooo", "bar")) + .isNotEqualTo(new Credentials("foo", null)) + .hasSameHashCodeAs(new Credentials("foo", "bar")); } } diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/JwtSerializerTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/JwtSerializerTest.java index 6c60d8a9355..f92ae6b473e 100644 --- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/JwtSerializerTest.java +++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/JwtSerializerTest.java @@ -100,7 +100,7 @@ public class JwtSerializerTest { assertThat(token).isNotEmpty(); Claims claims = underTest.decode(token).get(); - assertThat(claims.get("custom")).isEqualTo("property"); + assertThat(claims).containsEntry("custom", "property"); } @Test @@ -290,7 +290,7 @@ public class JwtSerializerTest { assertThat(result.getIssuer()).isEqualTo("sonarqube"); assertThat(result.getIssuedAt()).isEqualTo(createdAt); assertThat(((long) result.get("lastRefreshTime"))).isGreaterThanOrEqualTo(now.getTime()); - assertThat(result.get("key")).isEqualTo("value"); + assertThat(result).containsEntry("key", "value"); // Expiration date has been changed assertThat(result.getExpiration()).isNotEqualTo(expiredAt) .isAfterOrEqualTo(addMinutes(new Date(), 19)); diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/UserRegistrarImplTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/UserRegistrarImplTest.java index 4fef0b19761..e1f987697ba 100644 --- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/UserRegistrarImplTest.java +++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/UserRegistrarImplTest.java @@ -333,7 +333,7 @@ public class UserRegistrarImplTest { underTest.register(newUserRegistration()); // no new user should be created - assertThat(db.countRowsOfTable(db.getSession(), "users")).isEqualTo(1); + assertThat(db.countRowsOfTable(db.getSession(), "users")).isOne(); assertThat(db.getDbClient().userDao().selectByUuid(db.getSession(), user.getUuid())) .extracting(UserDto::getLogin, UserDto::getName, UserDto::getEmail, UserDto::getExternalId, UserDto::getExternalLogin, UserDto::getExternalIdentityProvider, UserDto::isActive) diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQProfileInsertImplTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQProfileInsertImplTest.java index 0b14896fc1b..777dbd7d5c2 100644 --- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQProfileInsertImplTest.java +++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQProfileInsertImplTest.java @@ -216,7 +216,7 @@ public class BuiltInQProfileInsertImplTest { assertThat(change.getUuid()).isNotEmpty(); assertThat(change.getUserUuid()).isNull(); assertThat(change.getRulesProfileUuid()).isEqualTo(profile.getRulesProfileUuid()); - assertThat(change.getDataAsMap().get("severity")).isEqualTo(expectedSeverity); + assertThat(change.getDataAsMap()).containsEntry("severity", expectedSeverity); } private QProfileDto verifyProfileInDb(BuiltInQProfile builtIn) { diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/user/DefaultUserTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/user/DefaultUserTest.java index a7a53d31752..48545a4ea2a 100644 --- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/user/DefaultUserTest.java +++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/user/DefaultUserTest.java @@ -30,9 +30,10 @@ public class DefaultUserTest { DefaultUser john = new DefaultUser().setLogin("john").setName("John"); DefaultUser eric = new DefaultUser().setLogin("eric").setName("Eric"); - assertThat(john).isEqualTo(john); - assertThat(john).isNotEqualTo(eric); - assertThat(john.hashCode()).isEqualTo(john.hashCode()); + assertThat(john) + .isEqualTo(john) + .isNotEqualTo(eric) + .hasSameHashCodeAs(john); assertThat(john.toString()).contains("login=john").contains("name=John"); } diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/usertoken/UserTokenAuthenticationTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/usertoken/UserTokenAuthenticationTest.java index 19badd1d687..f0c1ef8aab6 100644 --- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/usertoken/UserTokenAuthenticationTest.java +++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/usertoken/UserTokenAuthenticationTest.java @@ -58,8 +58,9 @@ public class UserTokenAuthenticationTest { Optional<String> login = underTest.authenticate(token); - assertThat(login.isPresent()).isTrue(); - assertThat(login).contains(user1.getUuid()); + assertThat(login) + .isPresent() + .contains(user1.getUuid()); verify(userLastConnectionDatesUpdater).updateLastConnectionDateIfNeeded(any(UserTokenDto.class)); } @@ -67,7 +68,7 @@ public class UserTokenAuthenticationTest { public void return_absent_if_token_hash_is_not_found() { Optional<String> login = underTest.authenticate("unknown-token"); - assertThat(login.isPresent()).isFalse(); + assertThat(login).isEmpty(); verify(userLastConnectionDatesUpdater, never()).updateLastConnectionDateIfNeeded(any(UserTokenDto.class)); } } diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/ce/http/CeHttpClientImplTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/ce/http/CeHttpClientImplTest.java index 9c4bfcac841..6fcf1eceff0 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/ce/http/CeHttpClientImplTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/ce/http/CeHttpClientImplTest.java @@ -61,7 +61,7 @@ public class CeHttpClientImplTest { public void retrieveSystemInfo_returns_absent_if_process_is_down() { Optional<ProtobufSystemInfo.SystemInfo> info = underTest.retrieveSystemInfo(); - assertThat(info.isPresent()).isFalse(); + assertThat(info).isEmpty(); } @Test diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/es/MigrationEsClientImplTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/es/MigrationEsClientImplTest.java index dba91bdcc4d..3e1d8059e98 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/es/MigrationEsClientImplTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/es/MigrationEsClientImplTest.java @@ -81,7 +81,7 @@ public class MigrationEsClientImplTest { assertThat(loadExistingIndices()).toIterable().contains("as"); ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetadata>> mappings = mappings(); MappingMetadata mapping = mappings.get("as").get("s"); - assertThat(countMappingFields(mapping)).isEqualTo(1); + assertThat(countMappingFields(mapping)).isOne(); assertThat(field(mapping, "new_field")).isNotNull(); assertThat(logTester.logs(LoggerLevel.INFO)) diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/notification/email/EmailNotificationChannelTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/notification/email/EmailNotificationChannelTest.java index 2d7f20d524f..43f051298f5 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/notification/email/EmailNotificationChannelTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/notification/email/EmailNotificationChannelTest.java @@ -338,7 +338,7 @@ public class EmailNotificationChannelTest { int count = underTest.deliverAll(Collections.singleton(request)); - assertThat(count).isEqualTo(1); + assertThat(count).isOne(); assertThat(smtpServer.getMessages()).hasSize(1); assertThat((String) smtpServer.getMessages().iterator().next().getMimeMessage().getContent()) .contains(emailMessage11.getMessage()); diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/db/migration/DatabaseMigrationImplConcurrentAccessTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/db/migration/DatabaseMigrationImplConcurrentAccessTest.java index 55248bea7e4..65aeb9a61f7 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/db/migration/DatabaseMigrationImplConcurrentAccessTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/db/migration/DatabaseMigrationImplConcurrentAccessTest.java @@ -80,7 +80,7 @@ public class DatabaseMigrationImplConcurrentAccessTest { pool.awaitTermination(2, TimeUnit.SECONDS); - assertThat(triggerCount.get()).isEqualTo(1); + assertThat(triggerCount.get()).isOne(); } private class CallStartit implements Runnable { diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/EsIndexesSectionTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/EsIndexesSectionTest.java index 248f8e4b93b..7313625670c 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/EsIndexesSectionTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/EsIndexesSectionTest.java @@ -49,8 +49,8 @@ public class EsIndexesSectionTest { ProtobufSystemInfo.Section section = underTest.toProtobuf(); // one index "issues" - assertThat(attribute(section, "Index issues - Docs").getLongValue()).isEqualTo(0L); - assertThat(attribute(section, "Index issues - Shards").getLongValue()).isGreaterThan(0); + assertThat(attribute(section, "Index issues - Docs").getLongValue()).isZero(); + assertThat(attribute(section, "Index issues - Shards").getLongValue()).isPositive(); assertThat(attribute(section, "Index issues - Store Size").getStringValue()).isNotNull(); } diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/cluster/EsClusterStateSectionTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/cluster/EsClusterStateSectionTest.java index 75ad980d23f..1e5a2c4db24 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/cluster/EsClusterStateSectionTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/cluster/EsClusterStateSectionTest.java @@ -42,7 +42,7 @@ public class EsClusterStateSectionTest { @Test public void test_attributes() { ProtobufSystemInfo.Section section = underTest.toProtobuf(); - assertThat(attribute(section, "Nodes").getLongValue()).isGreaterThan(0); + assertThat(attribute(section, "Nodes").getLongValue()).isPositive(); assertThat(attribute(section, "State").getStringValue()).isIn("RED", "YELLOW", "GREEN"); } } diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/cluster/NodeInfoTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/cluster/NodeInfoTest.java index 5a88794980d..a0aabab52cc 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/cluster/NodeInfoTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/cluster/NodeInfoTest.java @@ -35,8 +35,9 @@ public class NodeInfoTest { assertThat(foo.equals(bar)).isFalse(); assertThat(bar.equals(bar2)).isTrue(); - assertThat(bar.hashCode()).isEqualTo(bar.hashCode()); - assertThat(bar.hashCode()).isEqualTo(bar2.hashCode()); + assertThat(bar) + .hasSameHashCodeAs(bar) + .hasSameHashCodeAs(bar2); } } diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/cluster/NodeSystemSectionTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/cluster/NodeSystemSectionTest.java index 66d6c18f60a..0e4b6f631d7 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/cluster/NodeSystemSectionTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/cluster/NodeSystemSectionTest.java @@ -74,7 +74,7 @@ public class NodeSystemSectionTest { public void return_nb_of_processors() { ProtobufSystemInfo.Section section = underTest.toProtobuf(); - assertThat(attribute(section, "Processors").getLongValue()).isGreaterThan(0); + assertThat(attribute(section, "Processors").getLongValue()).isPositive(); } @Test diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/qualitygate/ProjectsInWarningDaemonTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/qualitygate/ProjectsInWarningDaemonTest.java index 78c49687110..d7d2ad96e61 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/qualitygate/ProjectsInWarningDaemonTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/qualitygate/ProjectsInWarningDaemonTest.java @@ -182,8 +182,8 @@ public class ProjectsInWarningDaemonTest { underTest.notifyStart(); waitForValueToBeComputed(1L); - assertThat(projectsInWarning.count()).isEqualTo(1L); - assertThat(countNumberOfProjectsInWarning()).isEqualTo(0L); + assertThat(projectsInWarning.count()).isOne(); + assertThat(countNumberOfProjectsInWarning()).isZero(); } private void waitForValueToBeComputed(long expectedValue) throws InterruptedException { diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/RegisterRulesTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/RegisterRulesTest.java index 5eb8a2d39c9..cbcaf854a7c 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/RegisterRulesTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/RegisterRulesTest.java @@ -448,7 +448,7 @@ public class RegisterRulesTest { assertThat(rule1.getName()).isEqualTo("Name2"); assertThat(rule1.getDescription()).isEqualTo("Description"); - assertThat(ruleIndex.search(new RuleQuery().setQueryText("Name2"), new SearchOptions()).getTotal()).isEqualTo(1); + assertThat(ruleIndex.search(new RuleQuery().setQueryText("Name2"), new SearchOptions()).getTotal()).isOne(); assertThat(ruleIndex.search(new RuleQuery().setQueryText("Name1"), new SearchOptions()).getTotal()).isZero(); } @@ -509,7 +509,7 @@ public class RegisterRulesTest { RuleDto rule1 = dbClient.ruleDao().selectOrFailByKey(db.getSession(), RuleKey.of(repository, ruleKey1)); SearchIdResult<String> searchRule1 = ruleIndex.search(new RuleQuery().setQueryText("Name1"), new SearchOptions()); assertThat(searchRule1.getUuids()).containsOnly(rule1.getUuid()); - assertThat(searchRule1.getTotal()).isEqualTo(1); + assertThat(searchRule1.getTotal()).isOne(); system.setNow(DATE2.getTime()); execute(context -> { @@ -529,7 +529,7 @@ public class RegisterRulesTest { SearchIdResult<String> searchRule2 = ruleIndex.search(new RuleQuery().setQueryText("Name2"), new SearchOptions()); assertThat(searchRule2.getUuids()).containsOnly(rule2.getUuid()); - assertThat(searchRule2.getTotal()).isEqualTo(1); + assertThat(searchRule2.getTotal()).isOne(); assertThat(ruleIndex.search(new RuleQuery().setQueryText("Name1"), new SearchOptions()).getTotal()).isZero(); } @@ -551,7 +551,7 @@ public class RegisterRulesTest { RuleDto rule1 = dbClient.ruleDao().selectOrFailByKey(db.getSession(), RuleKey.of(repository1, ruleKey)); SearchIdResult<String> searchRule1 = ruleIndex.search(new RuleQuery().setQueryText("Name1"), new SearchOptions()); assertThat(searchRule1.getUuids()).containsOnly(rule1.getUuid()); - assertThat(searchRule1.getTotal()).isEqualTo(1); + assertThat(searchRule1.getTotal()).isOne(); system.setNow(DATE2.getTime()); execute(context -> { @@ -571,7 +571,7 @@ public class RegisterRulesTest { SearchIdResult<String> searchRule2 = ruleIndex.search(new RuleQuery().setQueryText("Name2"), new SearchOptions()); assertThat(searchRule2.getUuids()).containsOnly(rule2.getUuid()); - assertThat(searchRule2.getTotal()).isEqualTo(1); + assertThat(searchRule2.getTotal()).isOne(); assertThat(ruleIndex.search(new RuleQuery().setQueryText("Name1"), new SearchOptions()).getTotal()).isZero(); } @@ -687,7 +687,7 @@ public class RegisterRulesTest { assertThat(rule1.getName()).isEqualTo("Name"); assertThat(rule1.getDescription()).isEqualTo("Desc2"); - assertThat(ruleIndex.search(new RuleQuery().setQueryText("Desc2"), new SearchOptions()).getTotal()).isEqualTo(1); + assertThat(ruleIndex.search(new RuleQuery().setQueryText("Desc2"), new SearchOptions()).getTotal()).isOne(); assertThat(ruleIndex.search(new RuleQuery().setQueryText("Desc1"), new SearchOptions()).getTotal()).isZero(); } @@ -753,7 +753,7 @@ public class RegisterRulesTest { rule = dbClient.ruleDao().selectOrFailByKey(db.getSession(), RULE_KEY1); assertThat(rule.getStatus()).isEqualTo(RuleStatus.BETA); - assertThat(ruleIndex.search(new RuleQuery().setKey(RULE_KEY1.toString()), new SearchOptions()).getTotal()).isEqualTo(1); + assertThat(ruleIndex.search(new RuleQuery().setKey(RULE_KEY1.toString()), new SearchOptions()).getTotal()).isOne(); } @Test diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/SingleDeprecatedRuleKeyTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/SingleDeprecatedRuleKeyTest.java index 0675f348f1e..a9a95853054 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/SingleDeprecatedRuleKeyTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/SingleDeprecatedRuleKeyTest.java @@ -104,19 +104,22 @@ public class SingleDeprecatedRuleKeyTest { SingleDeprecatedRuleKey singleDeprecatedRuleKey1 = SingleDeprecatedRuleKey.from(deprecatedRuleKeyDto1); SingleDeprecatedRuleKey singleDeprecatedRuleKey2 = SingleDeprecatedRuleKey.from(deprecatedRuleKeyDto2); - assertThat(singleDeprecatedRuleKey1).isEqualTo(singleDeprecatedRuleKey1); - assertThat(singleDeprecatedRuleKey1).isEqualTo(SingleDeprecatedRuleKey.from(deprecatedRuleKeyDto1)); - assertThat(singleDeprecatedRuleKey1).isEqualTo(SingleDeprecatedRuleKey.from(deprecatedRuleKeyDto1WithoutUuid)); + assertThat(singleDeprecatedRuleKey1) + .isEqualTo(singleDeprecatedRuleKey1) + .isEqualTo(SingleDeprecatedRuleKey.from(deprecatedRuleKeyDto1)) + .isEqualTo(SingleDeprecatedRuleKey.from(deprecatedRuleKeyDto1WithoutUuid)); assertThat(singleDeprecatedRuleKey2).isEqualTo(SingleDeprecatedRuleKey.from(deprecatedRuleKeyDto2)); - assertThat(singleDeprecatedRuleKey1.hashCode()).isEqualTo(singleDeprecatedRuleKey1.hashCode()); - assertThat(singleDeprecatedRuleKey1.hashCode()).isEqualTo(SingleDeprecatedRuleKey.from(deprecatedRuleKeyDto1).hashCode()); - assertThat(singleDeprecatedRuleKey1.hashCode()).isEqualTo(SingleDeprecatedRuleKey.from(deprecatedRuleKeyDto1WithoutUuid).hashCode()); - assertThat(singleDeprecatedRuleKey2.hashCode()).isEqualTo(SingleDeprecatedRuleKey.from(deprecatedRuleKeyDto2).hashCode()); + assertThat(singleDeprecatedRuleKey1) + .hasSameHashCodeAs(singleDeprecatedRuleKey1) + .hasSameHashCodeAs(SingleDeprecatedRuleKey.from(deprecatedRuleKeyDto1)) + .hasSameHashCodeAs(SingleDeprecatedRuleKey.from(deprecatedRuleKeyDto1WithoutUuid)); + assertThat(singleDeprecatedRuleKey2).hasSameHashCodeAs(SingleDeprecatedRuleKey.from(deprecatedRuleKeyDto2)); - assertThat(singleDeprecatedRuleKey1).isNotEqualTo(null); - assertThat(singleDeprecatedRuleKey1).isNotEqualTo(""); - assertThat(singleDeprecatedRuleKey1).isNotEqualTo(singleDeprecatedRuleKey2); + assertThat(singleDeprecatedRuleKey1) + .isNotNull() + .isNotEqualTo("") + .isNotEqualTo(singleDeprecatedRuleKey2); assertThat(singleDeprecatedRuleKey2).isNotEqualTo(singleDeprecatedRuleKey1); assertThat(singleDeprecatedRuleKey1.hashCode()).isNotEqualTo(singleDeprecatedRuleKey2.hashCode()); diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/search/BaseDocTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/search/BaseDocTest.java index db2094a43c4..a66b14091fe 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/search/BaseDocTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/search/BaseDocTest.java @@ -150,6 +150,6 @@ public class BaseDocTest { assertThat((Map) fields.get(index.getJoinField())) .isEqualTo(ImmutableMap.of("name", relationType.getName(), "parent", "miam")); - assertThat(fields.get("indexType")).isEqualTo(relationType.getName()); + assertThat(fields).containsEntry("indexType", relationType.getName()); } } diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/util/DateCollectorTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/util/DateCollectorTest.java index 97e64be8a61..d2d49499b64 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/util/DateCollectorTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/util/DateCollectorTest.java @@ -30,7 +30,7 @@ public class DateCollectorTest { @Test public void max_is_zero_if_no_dates() { - assertThat(collector.getMax()).isEqualTo(0L); + assertThat(collector.getMax()).isZero(); } @Test diff --git a/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQuery.java b/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQuery.java index d76d1f10e82..d3be5a82a4f 100644 --- a/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQuery.java +++ b/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQuery.java @@ -19,7 +19,6 @@ */ package org.sonar.server.issue.index; -import com.google.common.collect.ImmutableSet; import java.time.ZoneId; import java.util.Collection; import java.util.Collections; diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/es/IndexCreatorTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/es/IndexCreatorTest.java index 09130fbe76a..cbfcc521a51 100644 --- a/server/sonar-webserver-es/src/test/java/org/sonar/server/es/IndexCreatorTest.java +++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/es/IndexCreatorTest.java @@ -108,8 +108,8 @@ public class IndexCreatorTest { ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetadata>> mappings = mappings(); MappingMetadata mapping = mappings.get("fakes").get("fake"); assertThat(countMappingFields(mapping)).isEqualTo(3); - assertThat(field(mapping, "updatedAt").get("type")).isEqualTo("date"); - assertThat(field(mapping, "newField").get("type")).isEqualTo("integer"); + assertThat(field(mapping, "updatedAt")).containsEntry("type", "date"); + assertThat(field(mapping, "newField")).containsEntry("type", "integer"); assertThat(es.client().get(new GetRequest(fakeIndexType.getIndex().getName(), fakeIndexType.getType(), id)).isExists()).isFalse(); } @@ -230,7 +230,7 @@ public class IndexCreatorTest { .contains("Create type fakes/fake") .contains("Create type metadatas/metadata"); putFakeDocument(); - assertThat(es.countDocuments(FakeIndexDefinition.INDEX_TYPE)).isEqualTo(1); + assertThat(es.countDocuments(FakeIndexDefinition.INDEX_TYPE)).isOne(); afterFirstStart.accept(esDbCompatibility); logTester.clear(); @@ -278,7 +278,7 @@ public class IndexCreatorTest { assertThat(mapping.type()).isEqualTo("fake"); assertThat(mapping.getSourceAsMap()).isNotEmpty(); assertThat(countMappingFields(mapping)).isEqualTo(2); - assertThat(field(mapping, "updatedAt").get("type")).isEqualTo("date"); + assertThat(field(mapping, "updatedAt")).containsEntry("type", "date"); } private static class FakeIndexDefinition implements IndexDefinition { diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/FooIndex.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/FooIndex.java index 1ffef6b5763..e3a7788e261 100644 --- a/server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/FooIndex.java +++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/FooIndex.java @@ -21,7 +21,6 @@ package org.sonar.server.permission.index; import java.util.Arrays; import java.util.List; -import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.search.SearchHits; import org.elasticsearch.search.builder.SearchSourceBuilder; diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/PermissionIndexerTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/PermissionIndexerTest.java index dc1e577f9ac..a3a1a20ec91 100644 --- a/server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/PermissionIndexerTest.java +++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/PermissionIndexerTest.java @@ -97,13 +97,13 @@ public class PermissionIndexerTest { // Simulate a indexation issue db.getDbClient().purgeDao().deleteProject(db.getSession(), project1.uuid(), PROJECT, project1.name(), project1.getKey()); underTest.prepareForRecovery(db.getSession(), asList(project1.uuid()), ProjectIndexer.Cause.PROJECT_DELETION); - assertThat(db.countRowsOfTable(db.getSession(), "es_queue")).isEqualTo(1); + assertThat(db.countRowsOfTable(db.getSession(), "es_queue")).isOne(); Collection<EsQueueDto> esQueueDtos = db.getDbClient().esQueueDao().selectForRecovery(db.getSession(), Long.MAX_VALUE, 2); underTest.index(db.getSession(), esQueueDtos); assertThat(db.countRowsOfTable(db.getSession(), "es_queue")).isZero(); - assertThat(es.countDocuments(INDEX_TYPE_FOO_AUTH)).isEqualTo(1); + assertThat(es.countDocuments(INDEX_TYPE_FOO_AUTH)).isOne(); } @Test @@ -324,21 +324,21 @@ public class PermissionIndexerTest { es.lockWrites(INDEX_TYPE_FOO_AUTH); IndexingResult result = indexPermissions(project, PERMISSION_CHANGE); - assertThat(result.getTotal()).isEqualTo(1L); - assertThat(result.getFailures()).isEqualTo(1L); + assertThat(result.getTotal()).isOne(); + assertThat(result.getFailures()).isOne(); // index is still read-only, fail to recover result = recover(); - assertThat(result.getTotal()).isEqualTo(1L); - assertThat(result.getFailures()).isEqualTo(1L); + assertThat(result.getTotal()).isOne(); + assertThat(result.getFailures()).isOne(); assertThatAuthIndexHasSize(0); assertThatEsQueueTableHasSize(1); es.unlockWrites(INDEX_TYPE_FOO_AUTH); result = recover(); - assertThat(result.getTotal()).isEqualTo(1L); - assertThat(result.getFailures()).isEqualTo(0L); + assertThat(result.getTotal()).isOne(); + assertThat(result.getFailures()).isZero(); verifyAnyoneAuthorized(project); assertThatEsQueueTableHasSize(0); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ComponentViewerJsonWriter.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ComponentViewerJsonWriter.java index c9292a1ae84..f2e59fdbe6c 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ComponentViewerJsonWriter.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ComponentViewerJsonWriter.java @@ -37,8 +37,6 @@ import org.sonar.db.property.PropertyDto; import org.sonar.db.property.PropertyQuery; import org.sonar.server.user.UserSession; -import static java.util.Arrays.asList; -import static java.util.Collections.unmodifiableList; import static org.sonar.api.measures.CoreMetrics.COVERAGE; import static org.sonar.api.measures.CoreMetrics.COVERAGE_KEY; import static org.sonar.api.measures.CoreMetrics.DUPLICATED_LINES_DENSITY; @@ -51,12 +49,12 @@ import static org.sonar.api.measures.CoreMetrics.VIOLATIONS; import static org.sonar.api.measures.CoreMetrics.VIOLATIONS_KEY; public class ComponentViewerJsonWriter { - private static final List<String> METRIC_KEYS = unmodifiableList(asList( + private static final List<String> METRIC_KEYS = List.of( LINES_KEY, VIOLATIONS_KEY, COVERAGE_KEY, DUPLICATED_LINES_DENSITY_KEY, - TESTS_KEY)); + TESTS_KEY); private final DbClient dbClient; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/IssueChangeWSSupport.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/IssueChangeWSSupport.java index d67cb1ec2cc..9b45b324427 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/IssueChangeWSSupport.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/IssueChangeWSSupport.java @@ -77,7 +77,7 @@ public class IssueChangeWSSupport { } public enum Load { - CHANGE_LOG, COMMENTS, ALL; + CHANGE_LOG, COMMENTS, ALL } public interface FormattingContext { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseLoader.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseLoader.java index 9d2bc412693..c487840e8ed 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseLoader.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseLoader.java @@ -358,7 +358,7 @@ public class SearchResponseLoader { List<RuleMetadataDto> adHocRulesMetadata = dbClient.ruleDao().selectMetadataByKeys(dbSession, adHocRuleKeys); - rules.stream().forEach(r -> { + rules.forEach(r -> { if (r.isAdHoc()) { String adHocName = adHocRulesMetadata.stream() .filter(m -> m.getRuleUuid().equals(r.getUuid())).findFirst().map(RuleMetadataDto::getAdHocName) diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/MeasureMatrix.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/MeasureMatrix.java index ffa64caf5ca..cf09304594c 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/MeasureMatrix.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/MeasureMatrix.java @@ -30,7 +30,6 @@ import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Optional; -import java.util.function.Function; import java.util.function.Predicate; import java.util.stream.Stream; import javax.annotation.Nullable; diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/azure/ImportAzureProjectActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/azure/ImportAzureProjectActionTest.java index bd3b5926298..70ddec3e9f3 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/azure/ImportAzureProjectActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/azure/ImportAzureProjectActionTest.java @@ -189,7 +189,7 @@ public class ImportAzureProjectActionTest { .setParam("projectName", "project-name") .setParam("repositoryName", "repo-name"); - assertThatThrownBy(() -> request.execute()) + assertThatThrownBy(request::execute) .isInstanceOf(ForbiddenException.class) .hasMessage("Insufficient privileges"); } @@ -205,7 +205,7 @@ public class ImportAzureProjectActionTest { .setParam("projectName", "project-name") .setParam("repositoryName", "repo-name"); - assertThatThrownBy(() -> request.execute()) + assertThatThrownBy(request::execute) .isInstanceOf(IllegalArgumentException.class) .hasMessage("personal access token for '" + almSetting.getKey() + "' is missing"); } @@ -220,7 +220,7 @@ public class ImportAzureProjectActionTest { TestRequest request = ws.newRequest() .setParam("almSetting", "testKey"); - assertThatThrownBy(() -> request.execute()) + assertThatThrownBy(request::execute) .isInstanceOf(NotFoundException.class) .hasMessage("ALM Setting 'testKey' not found"); } @@ -246,7 +246,7 @@ public class ImportAzureProjectActionTest { .setParam("projectName", "project-name") .setParam("repositoryName", "repo-name"); - assertThatThrownBy(() -> request.execute()) + assertThatThrownBy(request::execute) .isInstanceOf(BadRequestException.class) .hasMessage("Could not create null, key already exists: " + projectKey); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/azure/SearchAzureReposActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/azure/SearchAzureReposActionTest.java index 792d279205b..a52954b9956 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/azure/SearchAzureReposActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/azure/SearchAzureReposActionTest.java @@ -363,7 +363,6 @@ public class SearchAzureReposActionTest { private GsonAzureRepo getGsonAzureRepo(String projectName, String repoName) { GsonAzureProject project = new GsonAzureProject(projectName, "the best project ever"); - GsonAzureRepo gsonAzureRepo = new GsonAzureRepo("repo-id", repoName, "url", project, "repo-default-branch"); - return gsonAzureRepo; + return new GsonAzureRepo("repo-id", repoName, "url", project, "repo-default-branch"); } } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketcloud/ImportBitbucketCloudRepoActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketcloud/ImportBitbucketCloudRepoActionTest.java index 918232dbee6..4f44307721a 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketcloud/ImportBitbucketCloudRepoActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketcloud/ImportBitbucketCloudRepoActionTest.java @@ -227,8 +227,7 @@ public class ImportBitbucketCloudRepoActionTest { private Repository getGsonBBCRepo() { Project project1 = new Project("PROJECT-UUID-ONE", "projectKey1", "projectName1"); MainBranch mainBranch = new MainBranch("branch", "develop"); - Repository repo1 = new Repository("REPO-UUID-ONE", "repo-slug-1", "repoName1", project1, mainBranch); - return repo1; + return new Repository("REPO-UUID-ONE", "repo-slug-1", "repoName1", project1, mainBranch); } } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketcloud/SearchBitbucketCloudReposActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketcloud/SearchBitbucketCloudReposActionTest.java index f6531353b11..8abdd0b6171 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketcloud/SearchBitbucketCloudReposActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketcloud/SearchBitbucketCloudReposActionTest.java @@ -86,7 +86,7 @@ public class SearchBitbucketCloudReposActionTest { .executeProtobuf(SearchBitbucketcloudReposWsResponse.class); assertThat(response.getIsLastPage()).isFalse(); - assertThat(response.getPaging().getPageIndex()).isEqualTo(1); + assertThat(response.getPaging().getPageIndex()).isOne(); assertThat(response.getPaging().getPageSize()).isEqualTo(100); assertThat(response.getRepositoriesList()) .extracting(BBCRepo::getUuid, BBCRepo::getName, BBCRepo::getSlug, BBCRepo::getProjectKey, BBCRepo::getSqProjectKey, BBCRepo::getWorkspace) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketserver/ListBitbucketServerProjectsActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketserver/ListBitbucketServerProjectsActionTest.java index 6fdd7f74497..ee1ca53448e 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketserver/ListBitbucketServerProjectsActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketserver/ListBitbucketServerProjectsActionTest.java @@ -88,7 +88,7 @@ public class ListBitbucketServerProjectsActionTest { .setParam("almSetting", almSetting.getKey()) .executeProtobuf(ListBitbucketserverProjectsWsResponse.class); - assertThat(response.getProjectsCount()).isEqualTo(1); + assertThat(response.getProjectsCount()).isOne(); assertThat(response.getProjectsList()) .extracting(AlmIntegrations.AlmProject::getKey, AlmIntegrations.AlmProject::getName) .containsExactly(tuple("key", "name")); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/github/ImportGithubProjectActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/github/ImportGithubProjectActionTest.java index 02be206424c..31575cfa77e 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/github/ImportGithubProjectActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/github/ImportGithubProjectActionTest.java @@ -128,7 +128,7 @@ public class ImportGithubProjectActionTest { .setParam(PARAM_ALM_SETTING, githubAlmSetting.getKey()) .setParam(PARAM_ORGANIZATION, "octocat") .setParam(PARAM_REPOSITORY_KEY, "octocat/Hello-World"); - assertThatThrownBy(() -> request.execute()) + assertThatThrownBy(request::execute) .isInstanceOf(BadRequestException.class) .hasMessage("Could not create null, key already exists: octocat_Hello-World"); } @@ -139,15 +139,14 @@ public class ImportGithubProjectActionTest { .setParam(PARAM_ALM_SETTING, "asdfghjkl") .setParam(PARAM_ORGANIZATION, "test") .setParam(PARAM_REPOSITORY_KEY, "test/repo"); - assertThatThrownBy(() -> request - .execute()) + assertThatThrownBy(request::execute) .isInstanceOf(UnauthorizedException.class); } @Test public void fail_when_missing_create_project_permission() { TestRequest request = ws.newRequest(); - assertThatThrownBy(() -> request.execute()) + assertThatThrownBy(request::execute) .isInstanceOf(UnauthorizedException.class); } @@ -160,8 +159,7 @@ public class ImportGithubProjectActionTest { .setParam(PARAM_ALM_SETTING, "unknown") .setParam(PARAM_ORGANIZATION, "test") .setParam(PARAM_REPOSITORY_KEY, "test/repo"); - assertThatThrownBy(() -> request - .execute()) + assertThatThrownBy(request::execute) .isInstanceOf(NotFoundException.class) .hasMessage("ALM Setting 'unknown' not found"); } @@ -174,7 +172,7 @@ public class ImportGithubProjectActionTest { .setParam(PARAM_ALM_SETTING, githubAlmSetting.getKey()) .setParam(PARAM_ORGANIZATION, "test") .setParam(PARAM_REPOSITORY_KEY, "test/repo"); - assertThatThrownBy(() -> request.execute()) + assertThatThrownBy(request::execute) .isInstanceOf(IllegalArgumentException.class) .hasMessage("No personal access token found"); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ws/AlmSettingsWsModuleTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ws/AlmSettingsWsModuleTest.java index 233b7a63f8c..b524bea4fdd 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ws/AlmSettingsWsModuleTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ws/AlmSettingsWsModuleTest.java @@ -23,7 +23,6 @@ import org.junit.Test; import org.sonar.core.platform.ComponentContainer; import static org.assertj.core.api.Assertions.assertThat; -import static org.sonar.core.platform.ComponentContainer.COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER; public class AlmSettingsWsModuleTest { diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ws/CountBindingActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ws/CountBindingActionTest.java index 140f4b50837..5c2e3e1482e 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ws/CountBindingActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ws/CountBindingActionTest.java @@ -82,7 +82,7 @@ public class CountBindingActionTest { .executeProtobuf(CountBindingWsResponse.class); assertThat(response.getKey()).isEqualTo(almSetting.getKey()); - assertThat(response.getProjects()).isEqualTo(1); + assertThat(response.getProjects()).isOne(); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ws/CreateGitlabActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ws/CreateGitlabActionTest.java index 3ce4aa1dffc..9e1e9975789 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ws/CreateGitlabActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ws/CreateGitlabActionTest.java @@ -71,7 +71,7 @@ public class CreateGitlabActionTest { .setParam("key", "Gitlab - Dev Team") .setParam("personalAccessToken", "98765432100"); - Assertions.assertThatThrownBy(() -> request.execute()) + Assertions.assertThatThrownBy(request::execute) .isInstanceOf(IllegalArgumentException.class) .hasMessage("The 'url' parameter is missing"); } @@ -102,7 +102,7 @@ public class CreateGitlabActionTest { .setParam("url", "") .setParam("personalAccessToken", "98765432100"); - Assertions.assertThatThrownBy(() -> request.execute()) + Assertions.assertThatThrownBy(request::execute) .isInstanceOf(IllegalArgumentException.class) .hasMessage("The 'url' parameter is missing"); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ws/UpdateGitlabActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ws/UpdateGitlabActionTest.java index 7b249ada4a8..0e679fef49e 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ws/UpdateGitlabActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ws/UpdateGitlabActionTest.java @@ -72,7 +72,7 @@ public class UpdateGitlabActionTest { .setParam("key", "Gitlab - Dev Team") .setParam("personalAccessToken", "98765432100"); - Assertions.assertThatThrownBy(() -> request.execute()) + Assertions.assertThatThrownBy(request::execute) .isInstanceOf(IllegalArgumentException.class) .hasMessage("The 'url' parameter is missing"); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/batch/ProjectActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/batch/ProjectActionTest.java index 7aa5c8d4c6e..961446e4d4f 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/batch/ProjectActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/batch/ProjectActionTest.java @@ -93,7 +93,7 @@ public class ProjectActionTest { .setParam("profile", "Default") .executeProtobuf(WsProjectResponse.class); assertThat(wsProjectResponse.getFileDataByModuleAndPathMap()).isEmpty(); - assertThat(wsProjectResponse.getFileDataByPathCount()).isEqualTo(1); + assertThat(wsProjectResponse.getFileDataByPathCount()).isOne(); assertThat(wsProjectResponse.getFileDataByPathMap().get("src/main/java/SomeClass.java")).isNotNull(); } @@ -111,10 +111,10 @@ public class ProjectActionTest { .executeProtobuf(WsProjectResponse.class); assertThat(wsProjectResponse.getFileDataByPathMap()).isEmpty(); - assertThat(wsProjectResponse.getFileDataByModuleAndPathCount()).isEqualTo(1); + assertThat(wsProjectResponse.getFileDataByModuleAndPathCount()).isOne(); WsProjectResponse.FileDataByPath moduleData = wsProjectResponse.getFileDataByModuleAndPathMap().get("module-1"); assertThat(moduleData).isNotNull(); - assertThat(moduleData.getFileDataByPathCount()).isEqualTo(1); + assertThat(moduleData.getFileDataByPathCount()).isOne(); WsProjectResponse.FileData fileData = moduleData.getFileDataByPathMap().get("src/main/java/SomeClass.java"); assertThat(fileData).isNotNull(); assertThat(fileData.getHash()).isEqualTo("789456"); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/queue/CeQueueCleanerTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/queue/CeQueueCleanerTest.java index 263deea3cf6..6ae65a417c7 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/queue/CeQueueCleanerTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/queue/CeQueueCleanerTest.java @@ -55,8 +55,8 @@ public class CeQueueCleanerTest { runCleaner(); - assertThat(dbTester.getDbClient().ceQueueDao().countByStatus(dbTester.getSession(), CeQueueDto.Status.PENDING)).isEqualTo(1); - assertThat(dbTester.getDbClient().ceQueueDao().countByStatus(dbTester.getSession(), CeQueueDto.Status.IN_PROGRESS)).isEqualTo(1); + assertThat(dbTester.getDbClient().ceQueueDao().countByStatus(dbTester.getSession(), CeQueueDto.Status.PENDING)).isOne(); + assertThat(dbTester.getDbClient().ceQueueDao().countByStatus(dbTester.getSession(), CeQueueDto.Status.IN_PROGRESS)).isOne(); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/ActivityActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/ActivityActionTest.java index 92da8486bb5..9fdaa66bdb9 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/ActivityActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/ActivityActionTest.java @@ -166,7 +166,7 @@ public class ActivityActionTest { .setParam(PARAM_MIN_SUBMITTED_AT, today) .setParam(PARAM_MAX_EXECUTED_AT, today)); - assertThat(activityResponse.getTasksCount()).isEqualTo(1); + assertThat(activityResponse.getTasksCount()).isOne(); } @Test @@ -182,7 +182,7 @@ public class ActivityActionTest { ws.newRequest() .setParam("onlyCurrents", "true")); - assertThat(activityResponse.getTasksCount()).isEqualTo(1); + assertThat(activityResponse.getTasksCount()).isOne(); assertThat(activityResponse.getTasks(0).getId()).isEqualTo("T2"); } @@ -253,7 +253,7 @@ public class ActivityActionTest { ActivityResponse activityResponse = call(ws.newRequest().setParam("componentId", project1.uuid())); - assertThat(activityResponse.getTasksCount()).isEqualTo(1); + assertThat(activityResponse.getTasksCount()).isOne(); assertThat(activityResponse.getTasks(0).getId()).isEqualTo("T1"); assertThat(activityResponse.getTasks(0).getStatus()).isEqualTo(Ce.TaskStatus.SUCCESS); assertThat(activityResponse.getTasks(0).getComponentId()).isEqualTo(project1.uuid()); @@ -270,7 +270,7 @@ public class ActivityActionTest { ActivityResponse activityResponse = call(ws.newRequest().setParam("component", project1.getDbKey())); - assertThat(activityResponse.getTasksCount()).isEqualTo(1); + assertThat(activityResponse.getTasksCount()).isOne(); assertThat(activityResponse.getTasks(0).getId()).isEqualTo("T1"); assertThat(activityResponse.getTasks(0).getStatus()).isEqualTo(Ce.TaskStatus.SUCCESS); assertThat(activityResponse.getTasks(0).getComponentId()).isEqualTo(project1.uuid()); @@ -340,7 +340,7 @@ public class ActivityActionTest { .setParam(Param.TEXT_QUERY, "T1") .setParam(PARAM_STATUS, PENDING.name())); - assertThat(result.getTasksCount()).isEqualTo(1); + assertThat(result.getTasksCount()).isOne(); assertThat(result.getTasks(0).getId()).isEqualTo("T1"); } @@ -352,7 +352,7 @@ public class ActivityActionTest { ActivityResponse result = call(ws.newRequest().setParam(Param.TEXT_QUERY, "T1")); - assertThat(result.getTasksCount()).isEqualTo(1); + assertThat(result.getTasksCount()).isOne(); assertThat(result.getTasks(0).getId()).isEqualTo("T1"); } @@ -383,7 +383,7 @@ public class ActivityActionTest { .setParam(PARAM_TYPE, CeTaskTypes.REPORT) .setParam(PARAM_STATUS, "SUCCESS,FAILED,CANCELED,IN_PROGRESS,PENDING")); - assertThat(result.getTasksCount()).isEqualTo(1); + assertThat(result.getTasksCount()).isOne(); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/ActivityStatusActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/ActivityStatusActionTest.java index ce1560fffeb..d60c848c20d 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/ActivityStatusActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/ActivityStatusActionTest.java @@ -113,7 +113,7 @@ public class ActivityStatusActionTest { Ce.ActivityStatusWsResponse result = callByComponentKey(projectKey); assertThat(result.getPending()).isEqualTo(2); - assertThat(result.getFailing()).isEqualTo(1); + assertThat(result.getFailing()).isOne(); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/WorkerCountActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/WorkerCountActionTest.java index 7a04e556559..bb101337cb4 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/WorkerCountActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/ws/WorkerCountActionTest.java @@ -60,7 +60,7 @@ public class WorkerCountActionTest { WorkerCountResponse response = ws.newRequest().executeProtobuf(WorkerCountResponse.class); - assertThat(response.getValue()).isEqualTo(1); + assertThat(response.getValue()).isOne(); assertThat(response.getCanSetWorkerCount()).isFalse(); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ComponentCleanerServiceTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ComponentCleanerServiceTest.java index c5b5c192955..9df95f7544a 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ComponentCleanerServiceTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ComponentCleanerServiceTest.java @@ -141,8 +141,8 @@ public class ComponentCleanerServiceTest { underTest.delete(dbSession, asList(projectDto1, projectDto2)); - assertThat(db.countRowsOfTable(db.getSession(), "webhooks")).isEqualTo(1); - assertThat(db.countRowsOfTable(db.getSession(), "webhook_deliveries")).isEqualTo(1); + assertThat(db.countRowsOfTable(db.getSession(), "webhooks")).isOne(); + assertThat(db.countRowsOfTable(db.getSession(), "webhook_deliveries")).isOne(); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchActionTest.java index 1dbe1437862..fcd3143117a 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchActionTest.java @@ -159,7 +159,7 @@ public class SearchActionTest { assertThat(response.getComponentsList()).extracting(Component::getKey) .containsExactlyInAnyOrder(project1.getDbKey()); - assertThat(response.getPaging().getTotal()).isEqualTo(1); + assertThat(response.getPaging().getTotal()).isOne(); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java index 5bbb19db0df..c9d220bc611 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java @@ -307,7 +307,7 @@ public class SearchProjectsActionTest { assertThat(result.getComponentsCount()).isZero(); Common.Paging paging = result.getPaging(); - assertThat(paging.getPageIndex()).isEqualTo(1); + assertThat(paging.getPageIndex()).isOne(); assertThat(paging.getPageSize()).isEqualTo(100); assertThat(paging.getTotal()).isZero(); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/TreeActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/TreeActionTest.java index a0aa1d6fffd..c6997209afe 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/TreeActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/TreeActionTest.java @@ -68,8 +68,6 @@ import static org.sonar.db.component.ComponentTesting.newDirectory; import static org.sonar.db.component.ComponentTesting.newModuleDto; import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto; import static org.sonar.db.component.ComponentTesting.newProjectCopy; -import static org.sonar.db.component.ComponentTesting.newSubPortfolio; -import static org.sonar.db.component.ComponentTesting.newPortfolio; import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_BRANCH; import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_COMPONENT; import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_PULL_REQUEST; @@ -308,7 +306,7 @@ public class TreeActionTest { assertThat(response.getComponentsList()).isEmpty(); assertThat(response.getPaging().getTotal()).isZero(); assertThat(response.getPaging().getPageSize()).isEqualTo(100); - assertThat(response.getPaging().getPageIndex()).isEqualTo(1); + assertThat(response.getPaging().getPageIndex()).isOne(); } @Test @@ -326,7 +324,7 @@ public class TreeActionTest { .executeProtobuf(TreeWsResponse.class); assertThat(response.getBaseComponent().getKey()).isEqualTo(view.getDbKey()); - assertThat(response.getComponentsCount()).isEqualTo(1); + assertThat(response.getComponentsCount()).isOne(); assertThat(response.getComponents(0).getKey()).isEqualTo(projectCopy.getDbKey()); assertThat(response.getComponents(0).getRefKey()).isEqualTo(project.getDbKey()); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/duplication/ws/DuplicationsParserTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/duplication/ws/DuplicationsParserTest.java index 103accf040d..814239f2b36 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/duplication/ws/DuplicationsParserTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/duplication/ws/DuplicationsParserTest.java @@ -221,16 +221,16 @@ public class DuplicationsParserTest { assertThat(comparator.compare(Duplication.newComponent(currentFile, 2, 2), Duplication.newComponent(fileOnSameProject, 5, 2))).isEqualTo(-1); assertThat(comparator.compare(Duplication.newComponent(fileOnSameProject, 2, 2), - Duplication.newComponent(currentFile, 5, 2))).isEqualTo(1); + Duplication.newComponent(currentFile, 5, 2))).isOne(); // Different files on different projects assertThat(comparator.compare(Duplication.newComponent(fileOnSameProject, 5, 2), Duplication.newComponent(fileOnDifferentProject, 2, 2))).isEqualTo(-1); assertThat(comparator.compare(Duplication.newComponent(fileOnDifferentProject, 5, 2), - Duplication.newComponent(fileOnSameProject, 2, 2))).isEqualTo(1); + Duplication.newComponent(fileOnSameProject, 2, 2))).isOne(); // Files on 2 different projects ComponentDto project3 = db.components().insertPrivateProject(); assertThat(comparator.compare(Duplication.newComponent(fileOnDifferentProject, 5, 2), - Duplication.newComponent(project3, 2, 2))).isEqualTo(1); + Duplication.newComponent(project3, 2, 2))).isOne(); // With null duplications assertThat(comparator.compare(null, Duplication.newComponent(fileOnSameProject, 2, 2))).isEqualTo(-1); @@ -241,7 +241,7 @@ public class DuplicationsParserTest { assertThat(comparator.compare(Duplication.newComponent(currentFile, 2, 2), Duplication.newRemovedComponent("key1", 5, 2))).isEqualTo(-1); assertThat(comparator.compare(Duplication.newRemovedComponent("key2", 2, 2), - Duplication.newComponent(currentFile, 5, 2))).isEqualTo(1); + Duplication.newComponent(currentFile, 5, 2))).isOne(); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/favorite/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/favorite/ws/SearchActionTest.java index 87d3196b7ad..6a7540c843f 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/favorite/ws/SearchActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/favorite/ws/SearchActionTest.java @@ -110,7 +110,7 @@ public class SearchActionTest { SearchResponse result = call(); - assertThat(result.getFavoritesCount()).isEqualTo(1); + assertThat(result.getFavoritesCount()).isOne(); assertThat(result.getFavorites(0).getKey()).isEqualTo("K1"); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/health/ClusterHealthTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/health/ClusterHealthTest.java index 8778c609662..22efaa205a3 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/health/ClusterHealthTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/health/ClusterHealthTest.java @@ -76,7 +76,7 @@ public class ClusterHealthTest { .isEqualTo(underTest) .isEqualTo(new ClusterHealth(health, nodeHealths)) .isNotEqualTo(new Object()) - .isNotEqualTo(null) + .isNotNull() .isNotEqualTo(new ClusterHealth( newHealthCheckBuilder() .setStatus(health.getStatus()) @@ -94,7 +94,7 @@ public class ClusterHealthTest { Set<NodeHealth> nodeHealths = randomNodeHealths(); ClusterHealth underTest = new ClusterHealth(health, nodeHealths); - assertThat(underTest.hashCode()).isEqualTo(underTest.hashCode()); + assertThat(underTest).hasSameHashCodeAs(underTest); } @Test 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 04976b1e8a7..402b80bbefb 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 @@ -118,9 +118,10 @@ public class HealthTest { @Test public void not_equals_to_null_nor_other_type() { - assertThat(Health.GREEN).isNotEqualTo(null); - assertThat(Health.GREEN).isNotEqualTo(new Object()); - assertThat(Health.GREEN).isNotEqualTo(Health.Status.GREEN); + assertThat(Health.GREEN) + .isNotNull() + .isNotEqualTo(new Object()) + .isNotEqualTo(Health.Status.GREEN); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/ChangeStatusActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/ChangeStatusActionTest.java index 74bde6f0a38..6744c310ea8 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/ChangeStatusActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/ChangeStatusActionTest.java @@ -395,7 +395,6 @@ public class ChangeStatusActionTest { ComponentDto project = dbTester.components().insertPublicProject(); userSessionRule.logIn().registerComponents(project) .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, project); - ; ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); IssueDto hotspot = dbTester.issues().insertHotspot(project, file, h -> h.setStatus(STATUS_TO_REVIEW).setResolution(null)); when(transitionService.doTransition(any(), any(), any())).thenReturn(transitionDone); @@ -542,7 +541,6 @@ public class ChangeStatusActionTest { ComponentDto project = dbTester.components().insertPublicProject(); userSessionRule.logIn().registerComponents(project) .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, project); - ; ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); IssueDto hotspot = dbTester.issues().insertHotspot(project, file, h -> h.setStatus(status).setResolution(resolution)); String comment = randomAlphabetic(12); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/EditCommentActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/EditCommentActionTest.java index 90dd409192d..6a1ece33582 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/EditCommentActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/EditCommentActionTest.java @@ -35,7 +35,6 @@ import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.exceptions.UnauthorizedException; import org.sonar.server.tester.UserSessionRule; import org.sonar.server.ws.TestRequest; -import org.sonar.server.ws.TestResponse; import org.sonar.server.ws.WsActionTester; import org.sonarqube.ws.Common; diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/SearchActionTest.java index 3d99388e5ef..af34743e568 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/SearchActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/SearchActionTest.java @@ -1205,7 +1205,7 @@ public class SearchActionTest { .extracting(SearchWsResponse.Hotspot::getKey) .containsExactly(hotspots.stream().limit(100).map(IssueDto::getKey).toArray(String[]::new)); assertThat(response.getPaging().getTotal()).isEqualTo(hotspots.size()); - assertThat(response.getPaging().getPageIndex()).isEqualTo(1); + assertThat(response.getPaging().getPageIndex()).isOne(); assertThat(response.getPaging().getPageSize()).isEqualTo(100); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/RulesAggregationTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/RulesAggregationTest.java index a64db9dbf85..6795b73b84f 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/RulesAggregationTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/RulesAggregationTest.java @@ -67,12 +67,12 @@ public class RulesAggregationTest { RulesAggregation.Rule ruleSameRuleKey = new RulesAggregation.Rule(RuleKey.of("xoo", "S001"), "S001"); RulesAggregation.Rule ruleWithDifferentRuleKey = new RulesAggregation.Rule(RuleKey.of("xoo", "S002"), "S002"); - assertThat(rule).isEqualTo(rule); - assertThat(rule).isEqualTo(ruleSameRuleKey); - assertThat(rule).isNotEqualTo(ruleWithDifferentRuleKey); - - assertThat(rule.hashCode()).isEqualTo(rule.hashCode()); - assertThat(rule.hashCode()).isEqualTo(ruleSameRuleKey.hashCode()); + assertThat(rule) + .isEqualTo(rule) + .isEqualTo(ruleSameRuleKey) + .isNotEqualTo(ruleWithDifferentRuleKey) + .hasSameHashCodeAs(rule) + .hasSameHashCodeAs(ruleSameRuleKey); assertThat(rule.hashCode()).isNotEqualTo(ruleWithDifferentRuleKey.hashCode()); } } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/WebIssueStorageTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/WebIssueStorageTest.java index 47f0712c54c..5e61c61b881 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/WebIssueStorageTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/WebIssueStorageTest.java @@ -114,7 +114,7 @@ public class WebIssueStorageTest { underTest.save(db.getSession(), singletonList(issue)); - assertThat(db.countRowsOfTable("issues")).isEqualTo(1); + assertThat(db.countRowsOfTable("issues")).isOne(); assertThat(db.selectFirst("select * from issues")) .containsEntry("PROJECT_UUID", project.uuid()) .containsEntry("COMPONENT_UUID", file.uuid()) @@ -123,7 +123,7 @@ public class WebIssueStorageTest { .containsEntry("STATUS", issue.status()) .containsEntry("SEVERITY", issue.severity()); - assertThat(db.countRowsOfTable("issue_changes")).isEqualTo(1); + assertThat(db.countRowsOfTable("issue_changes")).isOne(); assertThat(db.selectFirst("select * from issue_changes")) .containsEntry("KEE", comment.key()) .containsEntry("ISSUE_KEY", issue.key()) @@ -158,7 +158,7 @@ public class WebIssueStorageTest { underTest.save(db.getSession(), singletonList(issue)); - assertThat(db.countRowsOfTable("issues")).isEqualTo(1); + assertThat(db.countRowsOfTable("issues")).isOne(); assertThat(db.countRowsOfTable("issue_changes")).isZero(); DefaultIssue updated = new DefaultIssue() @@ -191,7 +191,7 @@ public class WebIssueStorageTest { underTest.save(db.getSession(), singletonList(updated)); - assertThat(db.countRowsOfTable("issues")).isEqualTo(1); + assertThat(db.countRowsOfTable("issues")).isOne(); assertThat(db.selectFirst("select * from issues")) .containsEntry("ASSIGNEE", updated.assignee()) .containsEntry("AUTHOR_LOGIN", updated.authorLogin()) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java index 95a711c8b56..eed32a04b3b 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java @@ -281,7 +281,7 @@ public class SearchActionTest { SearchWsResponse result = ws.newRequest().executeProtobuf(SearchWsResponse.class); - assertThat(result.getIssuesCount()).isEqualTo(1); + assertThat(result.getIssuesCount()).isOne(); assertThat(result.getIssues(0).getFlows(0).getLocationsList()).extracting(Common.Location::getComponent, Common.Location::getMsg) .containsExactlyInAnyOrder( tuple(file.getKey(), "FLOW MESSAGE"), @@ -1220,7 +1220,7 @@ public class SearchActionTest { SearchWsResponse response = ws.newRequest().executeProtobuf(SearchWsResponse.class); - assertThat(response.getIssuesList().size()).isEqualTo(1); + assertThat(response.getIssuesList()).hasSize(1); assertThat(response.getIssuesList().get(0).getQuickFixAvailable()).isFalse(); } @@ -1231,7 +1231,7 @@ public class SearchActionTest { SearchWsResponse response = ws.newRequest().executeProtobuf(SearchWsResponse.class); - assertThat(response.getIssuesList().size()).isEqualTo(1); + assertThat(response.getIssuesList()).hasSize(1); assertThat(response.getIssuesList().get(0).getQuickFixAvailable()).isTrue(); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/LiveMeasureComputerImplTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/LiveMeasureComputerImplTest.java index 9517e8e9e13..b0da25f1de9 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/LiveMeasureComputerImplTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/LiveMeasureComputerImplTest.java @@ -453,44 +453,32 @@ public class LiveMeasureComputerImplTest { private IssueMetricFormula newIncrementalFormula() { Metric metric = new Metric.Builder(intMetric.getKey(), intMetric.getShortName(), Metric.ValueType.valueOf(intMetric.getValueType())).create(); AtomicInteger counter = new AtomicInteger(); - return new IssueMetricFormula(metric, false, (ctx, issues) -> { - ctx.setValue(counter.incrementAndGet()); - }); + return new IssueMetricFormula(metric, false, (ctx, issues) -> ctx.setValue(counter.incrementAndGet())); } private IssueMetricFormula newIntConstantFormula(double constant) { Metric metric = new Metric.Builder(intMetric.getKey(), intMetric.getShortName(), Metric.ValueType.valueOf(intMetric.getValueType())).create(); - return new IssueMetricFormula(metric, false, (ctx, issues) -> { - ctx.setValue(constant); - }); + return new IssueMetricFormula(metric, false, (ctx, issues) -> ctx.setValue(constant)); } private IssueMetricFormula newRatingConstantFormula(Rating constant) { Metric metric = new Metric.Builder(ratingMetric.getKey(), ratingMetric.getShortName(), Metric.ValueType.valueOf(ratingMetric.getValueType())).create(); - return new IssueMetricFormula(metric, false, (ctx, issues) -> { - ctx.setValue(constant); - }); + return new IssueMetricFormula(metric, false, (ctx, issues) -> ctx.setValue(constant)); } private IssueMetricFormula newRatingLeakFormula(Rating rating) { Metric metric = new Metric.Builder(ratingMetric.getKey(), ratingMetric.getShortName(), Metric.ValueType.valueOf(ratingMetric.getValueType())).create(); - return new IssueMetricFormula(metric, true, (ctx, issues) -> { - ctx.setLeakValue(rating); - }); + return new IssueMetricFormula(metric, true, (ctx, issues) -> ctx.setLeakValue(rating)); } private IssueMetricFormula newQualifierBasedIntFormula() { Metric metric = new Metric.Builder(intMetric.getKey(), intMetric.getShortName(), Metric.ValueType.valueOf(intMetric.getValueType())).create(); - return new IssueMetricFormula(metric, false, (ctx, issues) -> { - ctx.setValue(ORDERED_BOTTOM_UP.indexOf(ctx.getComponent().qualifier())); - }); + return new IssueMetricFormula(metric, false, (ctx, issues) -> ctx.setValue(ORDERED_BOTTOM_UP.indexOf(ctx.getComponent().qualifier()))); } private IssueMetricFormula newQualifierBasedIntLeakFormula() { Metric metric = new Metric.Builder(intMetric.getKey(), intMetric.getShortName(), Metric.ValueType.valueOf(intMetric.getValueType())).create(); - return new IssueMetricFormula(metric, true, (ctx, issues) -> { - ctx.setLeakValue(ORDERED_BOTTOM_UP.indexOf(ctx.getComponent().qualifier())); - }); + return new IssueMetricFormula(metric, true, (ctx, issues) -> ctx.setLeakValue(ORDERED_BOTTOM_UP.indexOf(ctx.getComponent().qualifier()))); } private void assertThatProjectChanged(List<QGChangeEvent> events, ComponentDto... projects) { diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java index 44297a42475..f156f4569a9 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java @@ -93,7 +93,7 @@ public class ComponentActionTest { ComponentWsResponse response = newRequest(project.getKey(), metric.getKey()); - assertThat(response.getMetrics().getMetricsCount()).isEqualTo(1); + assertThat(response.getMetrics().getMetricsCount()).isOne(); assertThat(response.hasPeriod()).isFalse(); assertThat(response.getPeriods().getPeriodsCount()).isZero(); assertThat(response.getComponent().getKey()).isEqualTo(project.getDbKey()); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchActionTest.java index 9d4a42e08b9..8d75949c664 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchActionTest.java @@ -263,7 +263,7 @@ public class SearchActionTest { userSession.setRoot(); result = call(singletonList(project1.getDbKey()), singletonList(metric.getKey())); - assertThat(result.getMeasuresCount()).isEqualTo(1); + assertThat(result.getMeasuresCount()).isOne(); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchHistoryActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchHistoryActionTest.java index 97706e532ef..0375a2c9f0d 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchHistoryActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchHistoryActionTest.java @@ -271,7 +271,7 @@ public class SearchHistoryActionTest { .setMetrics(asList("optimized", "new_optimized")) .build(); result = call(request); - assertThat(result.getMeasuresList().get(0).getHistoryCount()).isEqualTo(1); + assertThat(result.getMeasuresList().get(0).getHistoryCount()).isOne(); assertThat(result.getMeasuresList().get(0).getHistory(0).hasDate()).isTrue(); assertThat(result.getMeasuresList().get(0).getHistory(0).hasValue()).isFalse(); } @@ -288,7 +288,7 @@ public class SearchHistoryActionTest { SearchHistoryResponse result = call(request); // one analysis in setUp method - assertThat(result.getPaging().getTotal()).isEqualTo(1); + assertThat(result.getPaging().getTotal()).isOne(); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/newcodeperiod/ws/ListActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/newcodeperiod/ws/ListActionTest.java index 393da42626b..a4ced509c0e 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/newcodeperiod/ws/ListActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/newcodeperiod/ws/ListActionTest.java @@ -189,7 +189,7 @@ public class ListActionTest { .executeProtobuf(ListWSResponse.class); assertThat(response).isNotNull(); - assertThat(response.getNewCodePeriodsCount()).isEqualTo(1); + assertThat(response.getNewCodePeriodsCount()).isOne(); assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey) .containsOnly("master"); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/newcodeperiod/ws/SetActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/newcodeperiod/ws/SetActionTest.java index a82e1f475f7..9476a0df7b7 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/newcodeperiod/ws/SetActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/newcodeperiod/ws/SetActionTest.java @@ -378,7 +378,7 @@ public class SetActionTest { } private void assertTableContainsOnly(@Nullable String projectUuid, @Nullable String branchUuid, NewCodePeriodType type, @Nullable String value) { - assertThat(db.countRowsOfTable(dbSession, "new_code_periods")).isEqualTo(1); + assertThat(db.countRowsOfTable(dbSession, "new_code_periods")).isOne(); assertThat(db.selectFirst(dbSession, "select project_uuid, branch_uuid, type, value from new_code_periods")) .containsOnly(entry("PROJECT_UUID", projectUuid), entry("BRANCH_UUID", branchUuid), entry("TYPE", type.name()), entry("VALUE", value)); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/newcodeperiod/ws/UnsetActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/newcodeperiod/ws/UnsetActionTest.java index 80163bf66af..dd8924dfee9 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/newcodeperiod/ws/UnsetActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/newcodeperiod/ws/UnsetActionTest.java @@ -217,7 +217,7 @@ public class UnsetActionTest { } private void assertTableContainsOnly(@Nullable String projectUuid, @Nullable String branchUuid, NewCodePeriodType type, @Nullable String value) { - assertThat(db.countRowsOfTable(dbSession, "new_code_periods")).isEqualTo(1); + assertThat(db.countRowsOfTable(dbSession, "new_code_periods")).isOne(); assertThat(db.selectFirst(dbSession, "select project_uuid, branch_uuid, type, value from new_code_periods")) .containsOnly(entry("PROJECT_UUID", projectUuid), entry("BRANCH_UUID", branchUuid), entry("TYPE", type.name()), entry("VALUE", value)); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/DefaultTemplatesResolverImplTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/DefaultTemplatesResolverImplTest.java index 6891aefa615..93cf5bcb755 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/DefaultTemplatesResolverImplTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/DefaultTemplatesResolverImplTest.java @@ -102,9 +102,7 @@ public class DefaultTemplatesResolverImplTest { @Test public void fail_when_default_template_for_project_is_missing() { DbSession session = db.getSession(); - assertThatThrownBy(() -> { - underTestWithPortfoliosInstalled.resolve(session); - }) + assertThatThrownBy(() -> underTestWithPortfoliosInstalled.resolve(session)) .isInstanceOf(IllegalStateException.class) .hasMessage("Default template for project is missing"); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/AddGroupActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/AddGroupActionTest.java index 6d8a920bc5c..fb561401b0d 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/AddGroupActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/AddGroupActionTest.java @@ -116,7 +116,7 @@ public class AddGroupActionTest extends BasePermissionWsTest<AddGroupAction> { loginAsAdmin(); newRequest() - .setParam(PARAM_GROUP_ID, group.getUuid().toString()) + .setParam(PARAM_GROUP_ID, group.getUuid()) .setParam(PARAM_PERMISSION, SYSTEM_ADMIN) .execute(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/RemoveGroupActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/RemoveGroupActionTest.java index b3cc6cfd5f6..04eeab7ac16 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/RemoveGroupActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/RemoveGroupActionTest.java @@ -108,7 +108,7 @@ public class RemoveGroupActionTest extends BasePermissionWsTest<RemoveGroupActio loginAsAdmin(); newRequest() - .setParam(PARAM_GROUP_ID, aGroup.getUuid().toString()) + .setParam(PARAM_GROUP_ID, aGroup.getUuid()) .setParam(PARAM_PERMISSION, PROVISION_PROJECTS.getKey()) .execute(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/plugins/ws/InstallActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/plugins/ws/InstallActionTest.java index 37a85f9119a..4b6ec2df3ae 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/plugins/ws/InstallActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/plugins/ws/InstallActionTest.java @@ -95,7 +95,6 @@ public class InstallActionTest { assertThatThrownBy(request::execute) .isInstanceOf(ForbiddenException.class) .hasMessage("Insufficient privileges"); - ; } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/SearchMyProjectsActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/SearchMyProjectsActionTest.java index f1840280bd1..26ab46870d7 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/SearchMyProjectsActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/SearchMyProjectsActionTest.java @@ -111,7 +111,7 @@ public class SearchMyProjectsActionTest { SearchMyProjectsWsResponse result = callWs(); - assertThat(result.getProjectsCount()).isEqualTo(1); + assertThat(result.getProjectsCount()).isOne(); } @Test @@ -167,7 +167,7 @@ public class SearchMyProjectsActionTest { SearchMyProjectsWsResponse result = callWs(); - assertThat(result.getProjectsCount()).isEqualTo(1); + assertThat(result.getProjectsCount()).isOne(); } @Test @@ -180,7 +180,7 @@ public class SearchMyProjectsActionTest { SearchMyProjectsWsResponse result = callWs(); - assertThat(result.getProjectsCount()).isEqualTo(1); + assertThat(result.getProjectsCount()).isOne(); } @Test @@ -209,7 +209,7 @@ public class SearchMyProjectsActionTest { SearchMyProjectsWsResponse result = callWs(); - assertThat(result.getProjectsCount()).isEqualTo(1); + assertThat(result.getProjectsCount()).isOne(); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateKeyActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateKeyActionTest.java index e00579359fc..968f34e5a5a 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateKeyActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateKeyActionTest.java @@ -66,7 +66,7 @@ public class UpdateKeyActionTest { call(project.getDbKey(), ANOTHER_KEY); - assertThat(selectByKey(project.getDbKey()).isPresent()).isFalse(); + assertThat(selectByKey(project.getDbKey())).isEmpty(); assertThat(selectByKey(ANOTHER_KEY).get().uuid()).isEqualTo(project.uuid()); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/RegisterQualityGatesTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/RegisterQualityGatesTest.java index 9cbe0e42b3f..0a69b7211b6 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/RegisterQualityGatesTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/RegisterQualityGatesTest.java @@ -95,7 +95,7 @@ public class RegisterQualityGatesTest { underTest.start(); - assertThat(db.countRowsOfTable("quality_gates")).isEqualTo(1); + assertThat(db.countRowsOfTable("quality_gates")).isOne(); verifyCorrectBuiltInQualityGate(); assertThat( logTester.logs(LoggerLevel.INFO).contains("Built-in quality gate's conditions of [Sonar way] has been updated")).isTrue(); @@ -113,7 +113,7 @@ public class RegisterQualityGatesTest { underTest.start(); - assertThat(db.countRowsOfTable("quality_gates")).isEqualTo(1); + assertThat(db.countRowsOfTable("quality_gates")).isOne(); verifyCorrectBuiltInQualityGate(); assertThat( logTester.logs(LoggerLevel.INFO).contains("Built-in quality gate's conditions of [Sonar way] has been updated")).isTrue(); @@ -131,7 +131,7 @@ public class RegisterQualityGatesTest { underTest.start(); - assertThat(db.countRowsOfTable("quality_gates")).isEqualTo(1); + assertThat(db.countRowsOfTable("quality_gates")).isOne(); verifyCorrectBuiltInQualityGate(); assertThat( logTester.logs(LoggerLevel.INFO).contains("Built-in quality gate's conditions of [Sonar way] has been updated")).isTrue(); @@ -151,7 +151,7 @@ public class RegisterQualityGatesTest { underTest.start(); - assertThat(db.countRowsOfTable("quality_gates")).isEqualTo(1); + assertThat(db.countRowsOfTable("quality_gates")).isOne(); verifyCorrectBuiltInQualityGate(); assertThat( logTester.logs(LoggerLevel.INFO).contains("Quality gate [Sonar way] has been set as built-in")).isTrue(); @@ -166,7 +166,7 @@ public class RegisterQualityGatesTest { underTest.start(); - assertThat(db.countRowsOfTable("quality_gates")).isEqualTo(1); + assertThat(db.countRowsOfTable("quality_gates")).isOne(); verifyCorrectBuiltInQualityGate(); // Log must not be present assertThat( diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/AddGroupActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/AddGroupActionTest.java index 4b871cc4f2d..3ab273a6fbb 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/AddGroupActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/AddGroupActionTest.java @@ -142,7 +142,7 @@ public class AddGroupActionTest { .setParam(PARAM_GATE_NAME, qualityGateDto.getName()) .setParam(PARAM_GROUP_NAME, "unknown"); - assertThatThrownBy(() -> request.execute()) + assertThatThrownBy(request::execute) .isInstanceOf(NotFoundException.class) .hasMessage("Group with name 'unknown' is not found"); } @@ -156,7 +156,7 @@ public class AddGroupActionTest { .setParam(PARAM_GATE_NAME, "unknown") .setParam(PARAM_GROUP_NAME, group.getName()); - assertThatThrownBy(() -> request.execute()) + assertThatThrownBy(request::execute) .isInstanceOf(NotFoundException.class) .hasMessage("No quality gate has been found for name unknown"); } @@ -170,6 +170,6 @@ public class AddGroupActionTest { .setParam(PARAM_GATE_NAME, qualityGateDto.getName()) .setParam(PARAM_GROUP_NAME, group.getName()); - assertThatThrownBy(() -> request.execute()).isInstanceOf(ForbiddenException.class); + assertThatThrownBy(request::execute).isInstanceOf(ForbiddenException.class); } } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/AddUserActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/AddUserActionTest.java index b2fea3ffa02..7f51ff81e51 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/AddUserActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/AddUserActionTest.java @@ -133,7 +133,7 @@ public class AddUserActionTest { .setParam(PARAM_GATE_NAME, qualityGateDto.getName()) .setParam(PARAM_LOGIN, "unknown"); - assertThatThrownBy(() -> request.execute()) + assertThatThrownBy(request::execute) .isInstanceOf(NotFoundException.class) .hasMessage("User with login 'unknown' is not found"); @@ -148,7 +148,7 @@ public class AddUserActionTest { .setParam(PARAM_GATE_NAME, "unknown") .setParam(PARAM_LOGIN, user.getLogin()); - assertThatThrownBy(() -> request.execute()) + assertThatThrownBy(request::execute) .isInstanceOf(NotFoundException.class) .hasMessage("No quality gate has been found for name unknown"); } @@ -162,6 +162,6 @@ public class AddUserActionTest { .setParam(PARAM_GATE_NAME, qualityGateDto.getName()) .setParam(PARAM_LOGIN, user.getLogin()); - assertThatThrownBy(() -> request.execute()).isInstanceOf(ForbiddenException.class); + assertThatThrownBy(request::execute).isInstanceOf(ForbiddenException.class); } -}
\ No newline at end of file +} 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 67bdb32bd0f..f9c79ec7db7 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 @@ -67,7 +67,7 @@ public class QualityGateDetailsFormatterTest { assertThat(conditions).extracting("actualValue").containsExactly("82.2985024398452", "1", "0"); // check periods - assertThat(result.getPeriodsCount()).isEqualTo(1); + assertThat(result.getPeriodsCount()).isOne(); List<ProjectStatusResponse.Period> periods = result.getPeriodsList(); assertThat(periods).extracting("index").containsExactly(1); assertThat(periods).extracting("mode").containsExactly("last_version"); @@ -87,7 +87,7 @@ public class QualityGateDetailsFormatterTest { ProjectStatus result = underTest.format(); // check conditions - assertThat(result.getConditionsCount()).isEqualTo(1); + assertThat(result.getConditionsCount()).isOne(); List<ProjectStatusResponse.Condition> conditions = result.getConditionsList(); assertThat(conditions).extracting("status").containsExactly(ProjectStatusResponse.Status.ERROR); assertThat(conditions).extracting("metricKey").containsExactly("new_coverage"); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/RemoveUserActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/RemoveUserActionTest.java index 15b338692c7..25c1e92d604 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/RemoveUserActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/RemoveUserActionTest.java @@ -134,7 +134,7 @@ public class RemoveUserActionTest { .setParam(PARAM_GATE_NAME, qualityGate.getName()) .setParam(PARAM_LOGIN, "unknown"); - assertThatThrownBy(() -> request.execute()) + assertThatThrownBy(request::execute) .isInstanceOf(NotFoundException.class) .hasMessage("User with login 'unknown' is not found"); } @@ -148,7 +148,7 @@ public class RemoveUserActionTest { .setParam(PARAM_GATE_NAME, "unknown") .setParam(PARAM_LOGIN, user.getLogin()); - assertThatThrownBy(() -> request.execute()) + assertThatThrownBy(request::execute) .isInstanceOf(NotFoundException.class) .hasMessage("No quality gate has been found for name unknown"); } @@ -163,7 +163,7 @@ public class RemoveUserActionTest { .setParam(PARAM_GATE_NAME, qualityGate.getName()) .setParam(PARAM_LOGIN, user.getLogin()); - assertThatThrownBy(() -> request.execute()) + assertThatThrownBy(request::execute) .isInstanceOf(IllegalArgumentException.class) .hasMessage(String.format("Operation forbidden for built-in Quality Gate '%s'", qualityGate.getName())); } @@ -178,7 +178,7 @@ public class RemoveUserActionTest { .setParam(PARAM_GATE_NAME, qualityGate.getName()) .setParam(PARAM_LOGIN, user.getLogin()); - assertThatThrownBy(() -> request.execute()) + assertThatThrownBy(request::execute) .isInstanceOf(ForbiddenException.class); } } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/SearchUsersActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/SearchUsersActionTest.java index f1b32a2e6d6..2dbd3758a0e 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/SearchUsersActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/SearchUsersActionTest.java @@ -288,7 +288,7 @@ public class SearchUsersActionTest { TestRequest request = ws.newRequest().setParam(PARAM_GATE_NAME, "unknown"); - assertThatThrownBy(() -> request.execute()) + assertThatThrownBy(request::execute) .isInstanceOf(NotFoundException.class) .hasMessage("No quality gate has been found for name unknown"); } @@ -302,7 +302,7 @@ public class SearchUsersActionTest { TestRequest request = ws.newRequest().setParam(PARAM_GATE_NAME, gate.getName()); - assertThatThrownBy(() -> request.execute()) + assertThatThrownBy(request::execute) .isInstanceOf(ForbiddenException.class); } } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryImplTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryImplTest.java index 9e7fcdf9239..0d94a1ff112 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryImplTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryImplTest.java @@ -318,10 +318,10 @@ public class QProfileFactoryImplTest { private void assertThatCustomProfileExists(QProfileDto profile) { assertThat(db.countSql(dbSession, "select count(*) from org_qprofiles where uuid = '" + profile.getKee() + "'")).isPositive(); // assertThat(db.countSql(dbSession, "select count(*) from project_qprofiles where profile_key = '" + profile.getKee() + - // "'")).isGreaterThan(0); + // "'")).isPositive(); // assertThat(db.countSql(dbSession, "select count(*) from default_qprofiles where qprofile_uuid = '" + profile.getKee() + - // "'")).isGreaterThan(0); - assertThat(db.countSql(dbSession, "select count(*) from rules_profiles where uuid = '" + profile.getRulesProfileUuid() + "'")).isEqualTo(1); + // "'")).isPositive(); + assertThat(db.countSql(dbSession, "select count(*) from rules_profiles where uuid = '" + profile.getRulesProfileUuid() + "'")).isOne(); assertThat(db.countSql(dbSession, "select count(*) from active_rules where profile_uuid = '" + profile.getRulesProfileUuid() + "'")).isPositive(); assertThat(db.countSql(dbSession, "select count(*) from qprofile_changes where rules_profile_uuid = '" + profile.getRulesProfileUuid() + "'")).isPositive(); // TODO active_rule_parameters diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileRuleImplTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileRuleImplTest.java index bad6cdc8336..63b73b8bb72 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileRuleImplTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileRuleImplTest.java @@ -780,7 +780,7 @@ public class QProfileRuleImplTest { .setQProfile(childProfile); BulkChangeResult bulkChangeResult = underTest.bulkDeactivateAndCommit(db.getSession(), childProfile, ruleQuery); - assertThat(bulkChangeResult.countFailed()).isEqualTo(1); + assertThat(bulkChangeResult.countFailed()).isOne(); assertThat(bulkChangeResult.countSucceeded()).isZero(); assertThat(bulkChangeResult.getChanges()).isEmpty(); assertThatRuleIsActivated(parentProfile, rule, null, rule.getSeverityString(), null, emptyMap()); @@ -806,7 +806,7 @@ public class QProfileRuleImplTest { BulkChangeResult result = underTest.bulkActivateAndCommit(db.getSession(), parentProfile, query, "BLOCKER"); assertThat(result.getChanges()).hasSize(3); - assertThat(result.countSucceeded()).isEqualTo(1); + assertThat(result.countSucceeded()).isOne(); assertThat(result.countFailed()).isZero(); // Rule1 must be activated with BLOCKER on all profiles 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 4bccc1dc98c..3af5b22d068 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 @@ -121,8 +121,9 @@ public class QProfileReferenceTest { assertThat(key1.equals(key2)).isFalse(); assertThat(key1.equals(name)).isFalse(); - assertThat(key1.hashCode()).isEqualTo(key1.hashCode()); - assertThat(key1.hashCode()).isEqualTo(key1bis.hashCode()); + assertThat(key1) + .hasSameHashCodeAs(key1) + .hasSameHashCodeAs(key1bis); } @Test @@ -139,8 +140,9 @@ public class QProfileReferenceTest { assertThat(name1.equals(name1OtherLang)).isFalse(); assertThat(name1.equals(key)).isFalse(); - assertThat(name1.hashCode()).isEqualTo(name1.hashCode()); - assertThat(name1.hashCode()).isEqualTo(name1bis.hashCode()); + assertThat(name1) + .hasSameHashCodeAs(name1) + .hasSameHashCodeAs(name1bis); } } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsMediumTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsMediumTest.java index 137e0d7360b..21079150684 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsMediumTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsMediumTest.java @@ -254,7 +254,7 @@ public class QProfilesWsMediumTest { ActiveRuleKey activeRuleKey = ActiveRuleKey.of(profile, rule.getKey()); Optional<ActiveRuleDto> activeRuleDto = dbClient.activeRuleDao().selectByKey(dbSession, activeRuleKey); - assertThat(activeRuleDto.isPresent()).isTrue(); + assertThat(activeRuleDto).isPresent(); assertThat(activeRuleDto.get().getSeverityString()).isEqualTo(Severity.MINOR); } @@ -413,7 +413,7 @@ public class QProfilesWsMediumTest { // 0. assert rule child rule is minor Optional<ActiveRuleDto> activeRuleDto = dbClient.activeRuleDao().selectByKey(dbSession, active2.getKey()); - assertThat(activeRuleDto.isPresent()).isTrue(); + assertThat(activeRuleDto).isPresent(); assertThat(activeRuleDto.get().getSeverityString()).isEqualTo(Severity.MINOR); // 1. reset child rule @@ -426,7 +426,7 @@ public class QProfilesWsMediumTest { // 2. assert rule child rule is NOT minor activeRuleDto = dbClient.activeRuleDao().selectByKey(dbSession, active2.getKey()); - assertThat(activeRuleDto.isPresent()).isTrue(); + assertThat(activeRuleDto).isPresent(); assertThat(activeRuleDto.get().getSeverityString()).isNotEqualTo(Severity.MINOR); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java index f72724412cb..a7b1de1b7be 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/SearchActionTest.java @@ -354,7 +354,7 @@ public class SearchActionTest { SearchWsResponse result = call(ws.newRequest()); - assertThat(result.getProfilesCount()).isEqualTo(1); + assertThat(result.getProfilesCount()).isOne(); assertThat(result.getProfiles(0).getRulesUpdatedAt()).isEqualTo("2016-12-21T19:10:03+0100"); assertThat(parseDateTime(result.getProfiles(0).getLastUsed()).getTime()).isEqualTo(time); assertThat(parseDateTime(result.getProfiles(0).getUserUpdatedAt()).getTime()).isEqualTo(time); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/ListActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/ListActionTest.java index d99eb2790ab..8986c0c6585 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/ListActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/ListActionTest.java @@ -58,8 +58,8 @@ public class ListActionTest { assertThat(listResponse.getRulesCount()).isEqualTo(2); assertThat(listResponse.getRules(0).getKey()).isEqualTo("S001"); - assertThat(listResponse.getRules(0).getInternalKey()).isEqualTo(""); - assertThat(listResponse.getRules(0).getName()).isEqualTo(""); + assertThat(listResponse.getRules(0).getInternalKey()).isEmpty(); + assertThat(listResponse.getRules(0).getName()).isEmpty(); assertThat(listResponse.getRules(1).getKey()).isEqualTo("S002"); assertThat(listResponse.getRules(1).getInternalKey()).isEqualTo("I002"); assertThat(listResponse.getRules(1).getName()).isEqualTo("Rule Two"); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/SearchActionTest.java index 6f33104fa57..ed21d4f2ad3 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/SearchActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/SearchActionTest.java @@ -141,8 +141,8 @@ public class SearchActionTest { .setParam(WebService.Param.FIELDS, "actives") .executeProtobuf(Rules.SearchResponse.class); - assertThat(response.getTotal()).isEqualTo(0L); - assertThat(response.getP()).isEqualTo(1); + assertThat(response.getTotal()).isZero(); + assertThat(response.getP()).isOne(); assertThat(response.getRulesCount()).isZero(); } @@ -371,7 +371,7 @@ public class SearchActionTest { .setParam("f", "repo,name") .setParam("facets", "tags") .executeProtobuf(SearchResponse.class); - assertThat(result.getFacets().getFacets(0).getValuesList()).extracting(v -> v.getVal(), v -> v.getCount()) + assertThat(result.getFacets().getFacets(0).getValuesList()).extracting(Common.FacetValue::getVal, Common.FacetValue::getCount) .contains(tuple("tag0", 1L), tuple("tag25", 1L), tuple("tag99", 1L)) .doesNotContain(tuple("x", 1L)); } @@ -387,7 +387,7 @@ public class SearchActionTest { .setParam("f", "repo,name") .setParam("facets", "tags") .executeProtobuf(SearchResponse.class); - assertThat(result.getFacets().getFacets(0).getValuesList()).extracting(v -> v.getVal(), v -> v.getCount()) + assertThat(result.getFacets().getFacets(0).getValuesList()).extracting(Common.FacetValue::getVal, Common.FacetValue::getCount) .containsExactly(tuple("tag2", 2L), tuple("tag1", 1L), tuple("tag3", 1L), tuple("tag4", 1L), tuple("tag5", 1L), tuple("tag6", 1L), tuple("tag7", 1L), tuple("tag8", 1L), tuple("tag9", 1L), tuple("tagA", 1L)); } @@ -461,8 +461,8 @@ public class SearchActionTest { SearchResponse result = ws.newRequest() .setParam("f", "langName") .executeProtobuf(SearchResponse.class); - assertThat(result.getTotal()).isEqualTo(1); - assertThat(result.getRulesCount()).isEqualTo(1); + assertThat(result.getTotal()).isOne(); + assertThat(result.getRulesCount()).isOne(); Rule searchedRule = result.getRules(0); assertThat(searchedRule).isNotNull(); @@ -486,8 +486,8 @@ public class SearchActionTest { SearchResponse result = ws.newRequest() .setParam("f", "debtRemFn,debtOverloaded,defaultDebtRemFn") .executeProtobuf(SearchResponse.class); - assertThat(result.getTotal()).isEqualTo(1); - assertThat(result.getRulesCount()).isEqualTo(1); + assertThat(result.getTotal()).isOne(); + assertThat(result.getRulesCount()).isOne(); Rule searchedRule = result.getRules(0); assertThat(searchedRule).isNotNull(); @@ -520,8 +520,8 @@ public class SearchActionTest { SearchResponse result = ws.newRequest() .setParam("f", "debtRemFn,debtOverloaded,defaultDebtRemFn") .executeProtobuf(SearchResponse.class); - assertThat(result.getTotal()).isEqualTo(1); - assertThat(result.getRulesCount()).isEqualTo(1); + assertThat(result.getTotal()).isOne(); + assertThat(result.getRulesCount()).isOne(); Rule searchedRule = result.getRules(0); assertThat(searchedRule).isNotNull(); @@ -554,8 +554,8 @@ public class SearchActionTest { SearchResponse result = ws.newRequest() .setParam("f", "debtRemFn,debtOverloaded,defaultDebtRemFn") .executeProtobuf(SearchResponse.class); - assertThat(result.getTotal()).isEqualTo(1); - assertThat(result.getRulesCount()).isEqualTo(1); + assertThat(result.getTotal()).isOne(); + assertThat(result.getRulesCount()).isOne(); Rule searchedRule = result.getRules(0); assertThat(searchedRule).isNotNull(); @@ -584,8 +584,8 @@ public class SearchActionTest { .setParam("f", "isTemplate") .setParam("is_template", "true") .executeProtobuf(SearchResponse.class); - assertThat(result.getTotal()).isEqualTo(1); - assertThat(result.getRulesCount()).isEqualTo(1); + assertThat(result.getTotal()).isOne(); + assertThat(result.getRulesCount()).isOne(); Rule searchedRule = result.getRules(0); assertThat(searchedRule).isNotNull(); @@ -606,8 +606,8 @@ public class SearchActionTest { .setParam("f", "templateKey") .setParam("template_key", templateRule.getRepositoryKey() + ":" + templateRule.getRuleKey()) .executeProtobuf(SearchResponse.class); - assertThat(result.getTotal()).isEqualTo(1); - assertThat(result.getRulesCount()).isEqualTo(1); + assertThat(result.getTotal()).isOne(); + assertThat(result.getRulesCount()).isOne(); Rule searchedRule = result.getRules(0); assertThat(searchedRule).isNotNull(); @@ -639,8 +639,8 @@ public class SearchActionTest { .setParam("q", rule.getName()) .setParam("activation", "true") .executeProtobuf(SearchResponse.class); - assertThat(result.getTotal()).isEqualTo(1); - assertThat(result.getRulesCount()).isEqualTo(1); + assertThat(result.getTotal()).isOne(); + assertThat(result.getRulesCount()).isOne(); Rule searchedRule = result.getRules(0); assertThat(searchedRule).isNotNull(); @@ -682,8 +682,8 @@ public class SearchActionTest { .setParam("activation", "true") .setParam("qprofile", profile.getKee()) .executeProtobuf(SearchResponse.class); - assertThat(result.getTotal()).isEqualTo(1); - assertThat(result.getRulesCount()).isEqualTo(1); + assertThat(result.getTotal()).isOne(); + assertThat(result.getRulesCount()).isOne(); assertThat(result.getActives()).isNotNull(); assertThat(result.getActives().getActives().get(rule.getKey().toString())).isNotNull(); assertThat(result.getActives().getActives().get(rule.getKey().toString()).getActiveListList()).hasSize(1); @@ -737,8 +737,8 @@ public class SearchActionTest { .setParam("qprofile", profile.getKee()) .executeProtobuf(SearchResponse.class); - assertThat(result.getTotal()).isEqualTo(1); - assertThat(result.getRulesCount()).isEqualTo(1); + assertThat(result.getTotal()).isOne(); + assertThat(result.getRulesCount()).isOne(); assertThat(result.getActives()).isNotNull(); assertThat(result.getActives().getActives().get(rule.getKey().toString())).isNotNull(); assertThat(result.getActives().getActives().get(rule.getKey().toString()).getActiveListList()).hasSize(1); @@ -927,7 +927,7 @@ public class SearchActionTest { Rules.SearchResponse response = request .executeProtobuf(Rules.SearchResponse.class); - assertThat(response.getP()).isEqualTo(1); + assertThat(response.getP()).isOne(); RuleKey[] expectedRuleKeys = stream(expectedRules).map(RuleDefinitionDto::getKey).collect(MoreCollectors.toList()).toArray(new RuleKey[0]); assertThat(response.getRulesList()) .extracting(r -> RuleKey.parse(r.getKey())) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/UpdateActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/UpdateActionTest.java index 644e123c33d..7af269c9607 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/UpdateActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/UpdateActionTest.java @@ -192,7 +192,7 @@ public class UpdateActionTest { assertThat(updatedRule.getKey()).isEqualTo(rule.getKey().toString()); assertThat(updatedRule.getDefaultRemFnType()).isEqualTo(rule.getDefRemediationFunction()); assertThat(updatedRule.getDefaultRemFnGapMultiplier()).isEqualTo(rule.getDefRemediationGapMultiplier()); - assertThat(updatedRule.getDefaultRemFnBaseEffort()).isEqualTo(""); + assertThat(updatedRule.getDefaultRemFnBaseEffort()).isEmpty(); assertThat(updatedRule.getGapDescription()).isEqualTo(rule.getGapDescription()); assertThat(updatedRule.getRemFnType()).isEqualTo(newOffset); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ValuesActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ValuesActionTest.java index e679e0c4d9e..876a2ceb319 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ValuesActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ValuesActionTest.java @@ -290,7 +290,7 @@ public class ValuesActionTest { newComponentPropertyDto(project).setKey("property").setValue("foo")); ValuesWsResponse response = executeRequestForComponentProperties(project, "property"); - assertThat(response.getSettingsCount()).isEqualTo(1); + assertThat(response.getSettingsCount()).isOne(); assertSetting(response.getSettings(0), "property", "foo", false); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/HtmlSourceDecoratorTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/HtmlSourceDecoratorTest.java index 16707714134..3952b14a8e9 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/HtmlSourceDecoratorTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/HtmlSourceDecoratorTest.java @@ -64,7 +64,7 @@ public class HtmlSourceDecoratorTest { @Test public void should_ignore_empty_source() { - assertThat(sourceDecorator.getDecoratedSourceAsHtml("", "0,1,cppd", "")).isEqualTo(""); + assertThat(sourceDecorator.getDecoratedSourceAsHtml("", "0,1,cppd", "")).isEmpty(); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/OpeningHtmlTagTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/OpeningHtmlTagTest.java index 9d5a9f4a840..a24e182386e 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/OpeningHtmlTagTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/OpeningHtmlTagTest.java @@ -52,8 +52,9 @@ public class OpeningHtmlTagTest { OpeningHtmlTag openingHtmlTagWithSameValues = new OpeningHtmlTag(3, "tag"); OpeningHtmlTag openingHtmlTagWithDifferentValue = new OpeningHtmlTag(5, "tag2"); - assertThat(openingHtmlTag.hashCode()).isEqualTo(openingHtmlTagWithSameValues.hashCode()); - assertThat(openingHtmlTag.hashCode()).isEqualTo(openingHtmlTag.hashCode()); + assertThat(openingHtmlTag) + .hasSameHashCodeAs(openingHtmlTagWithSameValues) + .hasSameHashCodeAs(openingHtmlTag); assertThat(openingHtmlTag.hashCode()).isNotEqualTo(openingHtmlTagWithDifferentValue.hashCode()); } } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/SourceServiceTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/SourceServiceTest.java index cefd6b58a24..802c469c8a9 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/SourceServiceTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/SourceServiceTest.java @@ -68,7 +68,7 @@ public class SourceServiceTest { assertThat(linesOpt).isPresent(); List<DbFileSources.Line> lines = Lists.newArrayList(linesOpt.get()); assertThat(lines).hasSize(3); - assertThat(lines.get(0).getLine()).isEqualTo(1); + assertThat(lines.get(0).getLine()).isOne(); assertThat(lines.get(1).getLine()).isEqualTo(5); assertThat(lines.get(2).getLine()).isEqualTo(6); } @@ -76,7 +76,7 @@ public class SourceServiceTest { @Test public void get_set_of_lines() { Optional<Iterable<DbFileSources.Line>> linesOpt = underTest.getLines(dbTester.getSession(), FILE_UUID, 5, 7); - assertThat(linesOpt.isPresent()).isTrue(); + assertThat(linesOpt).isPresent(); List<DbFileSources.Line> lines = Lists.newArrayList(linesOpt.get()); assertThat(lines).hasSize(3); assertThat(lines.get(0).getLine()).isEqualTo(5); @@ -87,7 +87,7 @@ public class SourceServiceTest { @Test public void get_range_of_lines_as_raw_text() { Optional<Iterable<String>> linesOpt = underTest.getLinesAsRawText(dbTester.getSession(), FILE_UUID, 5, 7); - assertThat(linesOpt.isPresent()).isTrue(); + assertThat(linesOpt).isPresent(); List<String> lines = Lists.newArrayList(linesOpt.get()); assertThat(lines).containsExactly("SOURCE_5", "SOURCE_6", "SOURCE_7"); } @@ -99,7 +99,7 @@ public class SourceServiceTest { when(htmlDecorator.getDecoratedSourceAsHtml("SOURCE_7", "HIGHLIGHTING_7", "SYMBOLS_7")).thenReturn("HTML_7"); Optional<Iterable<String>> linesOpt = underTest.getLinesAsHtml(dbTester.getSession(), FILE_UUID, 5, 7); - assertThat(linesOpt.isPresent()).isTrue(); + assertThat(linesOpt).isPresent(); List<String> lines = Lists.newArrayList(linesOpt.get()); assertThat(lines).containsExactly("HTML_5", "HTML_6", "HTML_7"); } @@ -121,14 +121,14 @@ public class SourceServiceTest { @Test public void getLines_returns_empty_iterable_if_range_is_out_of_scope() { Optional<Iterable<DbFileSources.Line>> lines = underTest.getLines(dbTester.getSession(), FILE_UUID, 500, 510); - assertThat(lines.isPresent()).isTrue(); + assertThat(lines).isPresent(); assertThat(lines.get()).isEmpty(); } @Test public void getLines_file_does_not_exist() { Optional<Iterable<DbFileSources.Line>> lines = underTest.getLines(dbTester.getSession(), "FILE_DOES_NOT_EXIST", 1, 10); - assertThat(lines.isPresent()).isFalse(); + assertThat(lines).isEmpty(); } } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/GlobalActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/GlobalActionTest.java index 6f350accf9f..2c4cab80210 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/GlobalActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/GlobalActionTest.java @@ -48,7 +48,6 @@ import org.sonar.server.ws.WsActionTester; import org.sonar.updatecenter.common.Version; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.InstanceOfAssertFactories.optional; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.RETURNS_DEEP_STUBS; import static org.mockito.Mockito.mock; diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java index e106abce134..459e989eb48 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java @@ -244,7 +244,7 @@ public class DeactivateActionTest { UserDto user = db.users().insertUser(); QualityGateDto qualityGate = db.qualityGates().insertQualityGate(); db.qualityGates().addUserPermission(qualityGate, user); - assertThat(db.countRowsOfTable("qgate_user_permissions")).isEqualTo(1); + assertThat(db.countRowsOfTable("qgate_user_permissions")).isOne(); deactivate(user.getLogin()); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/DismissSonarlintAdActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/DismissSonarlintAdActionTest.java index 66f95825a50..0992adbbc4d 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/DismissSonarlintAdActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/DismissSonarlintAdActionTest.java @@ -56,7 +56,7 @@ public class DismissSonarlintAdActionTest { @Test public void endpoint_throw_exception_if_no_user_login() { final TestRequest request = tester.newRequest(); - assertThatThrownBy(() -> request.execute()) + assertThatThrownBy(request::execute) .isInstanceOf(UnauthorizedException.class); } @@ -73,4 +73,4 @@ public class DismissSonarlintAdActionTest { UserDto updatedUser = db.users().selectUserByLogin(user.getLogin()).get(); assertThat(updatedUser.isSonarlintAdSeen()).isTrue(); } -}
\ No newline at end of file +} diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usergroups/ws/DeleteActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usergroups/ws/DeleteActionTest.java index 86c2e44101b..f969013dfd7 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usergroups/ws/DeleteActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usergroups/ws/DeleteActionTest.java @@ -155,7 +155,7 @@ public class DeleteActionTest { template.getName(), group.getName()); db.commit(); loginAsAdmin(); - assertThat(db.countRowsOfTable("perm_templates_groups")).isEqualTo(1); + assertThat(db.countRowsOfTable("perm_templates_groups")).isOne(); newRequest() .setParam("id", group.getUuid()) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usertoken/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usertoken/ws/SearchActionTest.java index 50989852db3..e08c6a4a7ab 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usertoken/ws/SearchActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usertoken/ws/SearchActionTest.java @@ -90,7 +90,7 @@ public class SearchActionTest { SearchWsResponse response = newRequest(null); - assertThat(response.getUserTokensCount()).isEqualTo(1); + assertThat(response.getUserTokensCount()).isOne(); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/webhook/ws/WebhookDeliveriesActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/webhook/ws/WebhookDeliveriesActionTest.java index 9335610ee65..95b95ca9a7f 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/webhook/ws/WebhookDeliveriesActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/webhook/ws/WebhookDeliveriesActionTest.java @@ -224,7 +224,7 @@ public class WebhookDeliveriesActionTest { assertThat(response.getDeliveriesCount()).isEqualTo(10); assertThat(response.getPaging().getTotal()).isEqualTo(12); - assertThat(response.getPaging().getPageIndex()).isEqualTo(1); + assertThat(response.getPaging().getPageIndex()).isOne(); } @Test diff --git a/server/sonar-webserver/src/test/java/org/sonar/server/platform/web/MasterServletFilterTest.java b/server/sonar-webserver/src/test/java/org/sonar/server/platform/web/MasterServletFilterTest.java index 9e1702ae063..e7c20415697 100644 --- a/server/sonar-webserver/src/test/java/org/sonar/server/platform/web/MasterServletFilterTest.java +++ b/server/sonar-webserver/src/test/java/org/sonar/server/platform/web/MasterServletFilterTest.java @@ -122,7 +122,7 @@ public class MasterServletFilterTest { FilterChain chain = mock(FilterChain.class); filters.doFilter(request, response, chain); - assertThat(filter1.count).isEqualTo(1); + assertThat(filter1.count).isOne(); assertThat(filter2.count).isEqualTo(2); } diff --git a/server/sonar-webserver/src/test/java/org/sonar/server/platform/web/RootFilterTest.java b/server/sonar-webserver/src/test/java/org/sonar/server/platform/web/RootFilterTest.java index d078ebe6980..8b0a0362317 100644 --- a/server/sonar-webserver/src/test/java/org/sonar/server/platform/web/RootFilterTest.java +++ b/server/sonar-webserver/src/test/java/org/sonar/server/platform/web/RootFilterTest.java @@ -86,7 +86,7 @@ public class RootFilterTest { underTest.doFilter(request("POST", "/context/service/call", "param=value"), response, chain); List<String> debugLogs = logTester.logs(LoggerLevel.DEBUG); - assertThat(debugLogs.size()).isEqualTo(1); + assertThat(debugLogs.size()).isOne(); assertThat(debugLogs.get(0)).contains("Processing of request", "failed"); } |