diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2021-10-22 10:38:45 -0500 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2021-10-25 20:03:24 +0000 |
commit | 6519110cd4f98fabf3bef46896eecbead3eb646a (patch) | |
tree | ad84a08da8ba0d590dd1a2d5e9bd2f85ff1c8a8e /server | |
parent | 7525c90c3f489b47e902e5f8eecce2c9deab9658 (diff) | |
download | sonarqube-6519110cd4f98fabf3bef46896eecbead3eb646a.tar.gz sonarqube-6519110cd4f98fabf3bef46896eecbead3eb646a.zip |
Fix code quality issues
Diffstat (limited to 'server')
43 files changed, 106 insertions, 113 deletions
diff --git a/server/sonar-auth-github/src/test/java/org/sonar/auth/github/GsonEmailTest.java b/server/sonar-auth-github/src/test/java/org/sonar/auth/github/GsonEmailTest.java index 47f593c0538..7a4cd36cae6 100644 --- a/server/sonar-auth-github/src/test/java/org/sonar/auth/github/GsonEmailTest.java +++ b/server/sonar-auth-github/src/test/java/org/sonar/auth/github/GsonEmailTest.java @@ -54,7 +54,7 @@ public class GsonEmailTest { @Test public void should_have_no_arg_constructor() { - assertThat(new GsonEmail().getEmail()).isEqualTo(""); + assertThat(new GsonEmail().getEmail()).isEmpty(); } } diff --git a/server/sonar-auth-github/src/test/java/org/sonar/auth/github/GsonTeamTest.java b/server/sonar-auth-github/src/test/java/org/sonar/auth/github/GsonTeamTest.java index 3d9a055689b..698e973dd03 100644 --- a/server/sonar-auth-github/src/test/java/org/sonar/auth/github/GsonTeamTest.java +++ b/server/sonar-auth-github/src/test/java/org/sonar/auth/github/GsonTeamTest.java @@ -67,8 +67,8 @@ public class GsonTeamTest { @Test public void should_have_no_arg_constructor() { - assertThat(new GsonTeam().getId()).isEqualTo(""); - assertThat(new GsonTeam.GsonOrganization().getLogin()).isEqualTo(""); + assertThat(new GsonTeam().getId()).isEmpty(); + assertThat(new GsonTeam.GsonOrganization().getLogin()).isEmpty(); } } diff --git a/server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/LdapAutodiscoveryTest.java b/server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/LdapAutodiscoveryTest.java index f4d527f376b..d39bccde4b2 100644 --- a/server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/LdapAutodiscoveryTest.java +++ b/server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/LdapAutodiscoveryTest.java @@ -63,7 +63,7 @@ public class LdapAutodiscoveryTest { assertThat(new LdapSrvRecord("http://foo:389", 1, 1)).isEqualTo(new LdapSrvRecord("http://foo:389", 2, 0)); assertThat(new LdapSrvRecord("http://foo:389", 1, 1)).isNotEqualTo(new LdapSrvRecord("http://foo:388", 1, 1)); - assertThat(new LdapSrvRecord("http://foo:389", 1, 1).hashCode()).isEqualTo(new LdapSrvRecord("http://foo:389", 1, 1).hashCode()); + assertThat(new LdapSrvRecord("http://foo:389", 1, 1)).hasSameHashCodeAs(new LdapSrvRecord("http://foo:389", 1, 1).hashCode()); } @Test @@ -74,7 +74,7 @@ public class LdapAutodiscoveryTest { NamingEnumeration namingEnumeration = mock(NamingEnumeration.class); when(context.getAttributes(Mockito.anyString(), Mockito.anyObject())).thenReturn(attributes); - when(attributes.get(Mockito.eq("srv"))).thenReturn(attribute); + when(attributes.get("srv")).thenReturn(attribute); when(attribute.getAll()).thenReturn(namingEnumeration); when(namingEnumeration.hasMore()).thenReturn(true, true, true, true, true, false); when(namingEnumeration.next()) diff --git a/server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/LdapGroupMappingTest.java b/server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/LdapGroupMappingTest.java index d7eb43a8896..50060cf2935 100644 --- a/server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/LdapGroupMappingTest.java +++ b/server/sonar-auth-ldap/src/test/java/org/sonar/auth/ldap/LdapGroupMappingTest.java @@ -35,7 +35,7 @@ public class LdapGroupMappingTest { assertThat(groupMapping.getRequest()).isEqualTo("(&(objectClass=groupOfUniqueNames)(uniqueMember={0}))"); assertThat(groupMapping.getRequiredUserAttributes()).isEqualTo(new String[] {"dn"}); - assertThat(groupMapping.toString()).isEqualTo("LdapGroupMapping{" + + assertThat(groupMapping).hasToString("LdapGroupMapping{" + "baseDn=null," + " idAttribute=cn," + " requiredUserAttributes=[dn]," + diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/duplication/DuplicationMeasures.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/duplication/DuplicationMeasures.java index fcf48afb20b..e5224b836fc 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/duplication/DuplicationMeasures.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/duplication/DuplicationMeasures.java @@ -126,8 +126,8 @@ public class DuplicationMeasures { blocks++; addLines(duplication.getOriginal(), duplicatedLineNumbers); InnerDuplicate[] innerDuplicates = Arrays.stream(duplication.getDuplicates()) - .filter(x -> x instanceof InnerDuplicate) - .map(d -> (InnerDuplicate) d) + .filter(InnerDuplicate.class::isInstance) + .map(InnerDuplicate.class::cast) .toArray(InnerDuplicate[]::new); for (InnerDuplicate innerDuplicate : innerDuplicates) { diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/AverageFormula.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/AverageFormula.java index 89402186816..3c3b9574297 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/AverageFormula.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/AverageFormula.java @@ -49,7 +49,7 @@ public class AverageFormula implements Formula<AverageFormula.AverageCounter> { if (mainValueOptional.isPresent() && byValueOptional.isPresent()) { double mainValue = mainValueOptional.get(); double byValue = byValueOptional.get(); - if (byValue > 0d) { + if (byValue > 0D) { return Optional.of(Measure.newMeasureBuilder().create(mainValue / byValue, context.getMetric().getDecimalScale())); } } @@ -101,8 +101,8 @@ public class AverageFormula implements Formula<AverageFormula.AverageCounter> { private boolean initialized = false; - private double mainValue = 0d; - private double byValue = 0d; + private double mainValue = 0D; + private double byValue = 0D; @Override public void aggregate(AverageCounter counter) { diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/CoverageUtils.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/CoverageUtils.java index 3b3bd95d1db..09beb6e3ebc 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/CoverageUtils.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/formula/coverage/CoverageUtils.java @@ -50,7 +50,7 @@ public final class CoverageUtils { static double getMeasureVariations(CounterInitializationContext counterContext, String metricKey) { Optional<Measure> measure = counterContext.getMeasure(metricKey); if (!measure.isPresent() || !measure.get().hasVariation()) { - return 0d; + return 0D; } return measure.get().getVariation(); } diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/NewEffortAggregator.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/NewEffortAggregator.java index 9bb046942f5..706223e4464 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/NewEffortAggregator.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/NewEffortAggregator.java @@ -149,7 +149,7 @@ public class NewEffortAggregator extends IssueVisitor { private boolean isEmpty = true; void add(long newEffort) { - double previous = MoreObjects.firstNonNull(this.newEffort, 0d); + double previous = MoreObjects.firstNonNull(this.newEffort, 0D); this.newEffort = previous + newEffort; isEmpty = false; } diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/BestValueOptimization.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/BestValueOptimization.java index f7071cfdc91..e2543b5d357 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/BestValueOptimization.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/BestValueOptimization.java @@ -67,7 +67,7 @@ public class BestValueOptimization implements Predicate<Measure> { } private static boolean isVariationEmptyOrBestValue(double variation, Double bestValue) { - return compare(variation, 0d) == 0 || compare(variation, bestValue) == 0; + return compare(variation, 0D) == 0 || compare(variation, bestValue) == 0; } private static boolean isBestValue(Measure measure, Double bestValue) { diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/Measure.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/Measure.java index bf01c05bdf5..9b7d231fa91 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/Measure.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/Measure.java @@ -470,7 +470,7 @@ public interface Measure { } public Measure create(long value, @Nullable String data) { - return createInternal(ValueType.LONG, (double) value, data); + return createInternal(ValueType.LONG, value, data); } public Measure create(long value) { diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MeasureToMeasureDto.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MeasureToMeasureDto.java index 238903219d9..20aa823ca44 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MeasureToMeasureDto.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MeasureToMeasureDto.java @@ -96,7 +96,7 @@ public class MeasureToMeasureDto { private static Double valueAsDouble(Measure measure) { switch (measure.getValueType()) { case BOOLEAN: - return measure.getBooleanValue() ? 1.0d : 0.0d; + return measure.getBooleanValue() ? 1.0D : 0.0D; case INT: return (double) measure.getIntValue(); case LONG: diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/linereader/DuplicationLineReader.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/linereader/DuplicationLineReader.java index 3f6720a277c..a7268686bdd 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/linereader/DuplicationLineReader.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/linereader/DuplicationLineReader.java @@ -87,7 +87,7 @@ public class DuplicationLineReader implements LineReader { for (Duplication duplication : duplications) { duplicatedBlock.add(duplication.getOriginal()); Arrays.stream(duplication.getDuplicates()) - .filter(d -> d instanceof InnerDuplicate) + .filter(InnerDuplicate.class::isInstance) .forEach(duplicate -> duplicatedBlock.add(duplicate.getTextBlock())); } return duplicatedBlock; diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/linereader/HighlightingLineReader.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/linereader/HighlightingLineReader.java index 338fbe5c2e2..675c24d1b23 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/linereader/HighlightingLineReader.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/linereader/HighlightingLineReader.java @@ -43,8 +43,6 @@ public class HighlightingLineReader implements LineReader { private static final Logger LOG = Loggers.get(HighlightingLineReader.class); - private ReadError readError = null; - private static final Map<HighlightingType, String> cssClassByType = ImmutableMap.<HighlightingType, String>builder() .put(HighlightingType.ANNOTATION, "a") .put(HighlightingType.CONSTANT, "c") @@ -60,7 +58,7 @@ public class HighlightingLineReader implements LineReader { private final Iterator<ScannerReport.SyntaxHighlightingRule> lineHighlightingIterator; private final RangeOffsetConverter rangeOffsetConverter; private final List<ScannerReport.SyntaxHighlightingRule> highlightingList; - + private ReadError readError = null; private ScannerReport.SyntaxHighlightingRule currentItem; public HighlightingLineReader(Component file, Iterator<ScannerReport.SyntaxHighlightingRule> lineHighlightingIterator, RangeOffsetConverter rangeOffsetConverter) { 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 2013ef2bebb..9947202798b 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 @@ -40,6 +40,11 @@ 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( + ComponentLinkType.HOME, ProjectLinkDto.TYPE_HOME_PAGE, + ComponentLinkType.SCM, ProjectLinkDto.TYPE_SOURCES, + ComponentLinkType.CI, ProjectLinkDto.TYPE_CI, + ComponentLinkType.ISSUE, ProjectLinkDto.TYPE_ISSUE_TRACKER); private final AnalysisMetadataHolder analysisMetadataHolder; private final DbClient dbClient; @@ -47,12 +52,6 @@ public class PersistProjectLinksStep implements ComputationStep { private final BatchReportReader reportReader; private final UuidFactory uuidFactory; - private static final Map<ComponentLinkType, String> typesConverter = ImmutableMap.of( - ComponentLinkType.HOME, ProjectLinkDto.TYPE_HOME_PAGE, - ComponentLinkType.SCM, ProjectLinkDto.TYPE_SOURCES, - ComponentLinkType.CI, ProjectLinkDto.TYPE_CI, - ComponentLinkType.ISSUE, ProjectLinkDto.TYPE_ISSUE_TRACKER); - public PersistProjectLinksStep(AnalysisMetadataHolder analysisMetadataHolder, DbClient dbClient, TreeRootHolder treeRootHolder, BatchReportReader reportReader, UuidFactory uuidFactory) { this.analysisMetadataHolder = analysisMetadataHolder; 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 4bbb57b0de5..7476da047db 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 @@ -399,7 +399,7 @@ public class MeasureRepositoryImplTest { Map<String, Measure> rawMeasures = underTest.getRawMeasures(FILE_COMPONENT); assertThat(rawMeasures.keySet()).hasSize(2); - assertThat(rawMeasures.get(METRIC_KEY_1)).isEqualTo(addedMeasure); + assertThat(rawMeasures).containsEntry(METRIC_KEY_1, addedMeasure); assertThat(rawMeasures.get(METRIC_KEY_2)).extracting(Measure::getStringValue).isEqualTo("some value"); } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/metric/MetricImplTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/metric/MetricImplTest.java index 4594536ce91..f24a68bdb3f 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/metric/MetricImplTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/metric/MetricImplTest.java @@ -87,8 +87,8 @@ public class MetricImplTest { @Test public void all_fields_are_displayed_in_toString() { - assertThat(new MetricImpl(SOME_UUID, SOME_KEY, SOME_NAME, Metric.MetricType.FLOAT, 1, 951d, true, false).toString()) - .isEqualTo("MetricImpl{uuid=uuid, key=key, name=name, type=FLOAT, bestValue=951.0, bestValueOptimized=true, deleteHistoricalData=false}"); + assertThat(new MetricImpl(SOME_UUID, SOME_KEY, SOME_NAME, Metric.MetricType.FLOAT, 1, 951d, true, false)) + .hasToString("MetricImpl{uuid=uuid, key=key, name=name, type=FLOAT, bestValue=951.0, bestValueOptimized=true, deleteHistoricalData=false}"); } } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/taskprocessor/IndexIssuesStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/taskprocessor/IndexIssuesStepTest.java index 760e5900802..00efde25fb5 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/taskprocessor/IndexIssuesStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/taskprocessor/IndexIssuesStepTest.java @@ -32,7 +32,6 @@ import org.sonar.server.es.EsTester; import org.sonar.server.issue.index.IssueIndexer; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -81,7 +80,7 @@ public class IndexIssuesStepTest { underTest.execute(() -> null); - verify(issueIndexer, times(1)).indexOnAnalysis(eq(BRANCH_UUID)); + verify(issueIndexer, times(1)).indexOnAnalysis(BRANCH_UUID); Optional<BranchDto> branch = dbClient.branchDao().selectByUuid(dbTester.getSession(), BRANCH_UUID); assertThat(branch.get().isNeedIssueSync()).isFalse(); } @@ -99,7 +98,7 @@ public class IndexIssuesStepTest { underTest.execute(() -> null); - verify(issueIndexer, times(0)).indexOnAnalysis(eq(BRANCH_UUID)); + verify(issueIndexer, times(0)).indexOnAnalysis(BRANCH_UUID); } @Test diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/alm/setting/AlmSettingDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/alm/setting/AlmSettingDaoTest.java index 2ff6c75f8a2..075c4c4037a 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/alm/setting/AlmSettingDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/alm/setting/AlmSettingDaoTest.java @@ -182,7 +182,7 @@ public class AlmSettingDaoTest { underTest.delete(dbSession, almSettingDto); - assertThat(underTest.selectByKey(dbSession, almSettingDto.getKey()).isPresent()).isFalse(); + assertThat(underTest.selectByKey(dbSession, almSettingDto.getKey())).isNotPresent(); } } 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 10c85739995..ed402198582 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 @@ -104,7 +104,7 @@ public class SnapshotDaoTest { assertThat(result.getCreatedAt()).isEqualTo(1403042400000L); assertThat(result.getRevision()).isEqualTo("sha1"); - assertThat(underTest.selectByUuid(db.getSession(), "DOES_NOT_EXIST").isPresent()).isFalse(); + assertThat(underTest.selectByUuid(db.getSession(), "DOES_NOT_EXIST")).isNotPresent(); } @Test diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/period/DefaultPeriodCleanerTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/period/DefaultPeriodCleanerTest.java index ec30df80e1f..e0ecdc95d8e 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/period/DefaultPeriodCleanerTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/period/DefaultPeriodCleanerTest.java @@ -33,7 +33,6 @@ import org.sonar.db.purge.PurgeProfiler; import org.sonar.db.purge.PurgeableAnalysisDto; import static org.mockito.ArgumentMatchers.anyList; -import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.when; @@ -57,9 +56,9 @@ public class DefaultPeriodCleanerTest { InOrder inOrder = Mockito.inOrder(dao, filter1, filter2); inOrder.verify(filter1).log(); - inOrder.verify(dao, times(1)).deleteAnalyses(eq(session), eq(profiler), eq(ImmutableList.of("u999"))); + inOrder.verify(dao, times(1)).deleteAnalyses(session, profiler, ImmutableList.of("u999")); inOrder.verify(filter2).log(); - inOrder.verify(dao, times(1)).deleteAnalyses(eq(session), eq(profiler), eq(ImmutableList.of("u456"))); + inOrder.verify(dao, times(1)).deleteAnalyses(session, profiler, ImmutableList.of("u456")); inOrder.verifyNoMoreInteractions(); } 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 2bac02c47d9..f8bb1002e1d 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 @@ -102,7 +102,7 @@ public class RuleDaoTest { assertThat(underTest.selectDefinitionByKey(db.getSession(), RuleKey.of("NOT", "FOUND")).isPresent()).isFalse(); Optional<RuleDefinitionDto> reloaded = underTest.selectDefinitionByKey(db.getSession(), rule.getKey()); - assertThat(reloaded.isPresent()).isTrue(); + assertThat(reloaded).isPresent(); } @Test diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/user/SessionTokensDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/user/SessionTokensDaoTest.java index a12a18956e2..83352bd5ecc 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/user/SessionTokensDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/user/SessionTokensDaoTest.java @@ -52,7 +52,7 @@ public class SessionTokensDaoTest { Optional<SessionTokenDto> result = underTest.selectByUuid(dbSession, dto.getUuid()); - assertThat(result.isPresent()); + assertThat(result).isPresent(); assertThat(result.get().getUserUuid()).isEqualTo("ABCD"); assertThat(result.get().getExpirationDate()).isEqualTo(15_000_000_000L); assertThat(result.get().getCreatedAt()).isEqualTo(NOW); @@ -72,7 +72,7 @@ public class SessionTokensDaoTest { Optional<SessionTokenDto> result = underTest.selectByUuid(dbSession, dto.getUuid()); - assertThat(result.isPresent()); + assertThat(result).isPresent(); assertThat(result.get().getUuid()).isNotEqualTo("SHOULD_NOT_BE_USED"); assertThat(result.get().getCreatedAt()).isEqualTo(NOW); assertThat(result.get().getUpdatedAt()).isEqualTo(NOW); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserTokenDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserTokenDaoTest.java index 8d640e17fd0..43b4f48a66c 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserTokenDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserTokenDaoTest.java @@ -134,7 +134,7 @@ public class UserTokenDaoTest { Map<String, Integer> result = underTest.countTokensByUsers(dbSession, singletonList(user)); - assertThat(result.get(user.getUuid())).isEqualTo(2); + assertThat(result).containsEntry(user.getUuid(), 2); assertThat(result.get("unknown-user_uuid")).isNull(); } } diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/es/EsClient.java b/server/sonar-server-common/src/main/java/org/sonar/server/es/EsClient.java index eeb66afc1ac..8233054a817 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/es/EsClient.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/es/EsClient.java @@ -92,12 +92,11 @@ import static org.sonar.server.es.EsRequestDetails.computeDetailsAsString; * with context) and profiling of requests. */ public class EsClient implements Closeable { + public static final Logger LOGGER = Loggers.get("es"); private static final String ES_USERNAME = "elastic"; private final RestHighLevelClient restHighLevelClient; private final Gson gson; - public static final Logger LOGGER = Loggers.get("es"); - public EsClient(HttpHost... hosts) { this(new MinimalRestHighLevelClient(null, hosts)); } @@ -274,6 +273,10 @@ public class EsClient implements Closeable { super(buildHttpClient(searchPassword, hosts)); } + MinimalRestHighLevelClient(RestClient restClient) { + super(restClient, RestClient::close, Lists.newArrayList()); + } + @NotNull private static RestClientBuilder buildHttpClient(@Nullable String searchPassword, HttpHost[] hosts) { @@ -296,9 +299,6 @@ public class EsClient implements Closeable { return provider; } - MinimalRestHighLevelClient(RestClient restClient) { - super(restClient, RestClient::close, Lists.newArrayList()); - } } <R> R execute(EsRequestExecutor<R> executor) { diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/measure/DebtRatingGrid.java b/server/sonar-server-common/src/main/java/org/sonar/server/measure/DebtRatingGrid.java index a726267e519..a0fc119f686 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/measure/DebtRatingGrid.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/measure/DebtRatingGrid.java @@ -62,7 +62,7 @@ public class DebtRatingGrid { private static EnumMap<Rating, Bounds> buildRatingBounds(double[] gridValues) { checkState(gridValues.length == 4, "Rating grid should contains 4 values"); EnumMap<Rating, Bounds> ratingBounds = new EnumMap<>(Rating.class); - ratingBounds.put(A, new Bounds(0d, gridValues[0])); + ratingBounds.put(A, new Bounds(0D, gridValues[0])); ratingBounds.put(B, new Bounds(gridValues[0], gridValues[1])); ratingBounds.put(C, new Bounds(gridValues[1], gridValues[2])); ratingBounds.put(D, new Bounds(gridValues[2], gridValues[3])); diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleIndex.java b/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleIndex.java index dd1c529d799..40ff6350176 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleIndex.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleIndex.java @@ -217,7 +217,7 @@ public class RuleIndex { .stream().map(token -> boolQuery().should( matchQuery( SEARCH_GRAMS_ANALYZER.subField(FIELD_RULE_NAME), - StringUtils.left(token, DefaultIndexSettings.MAXIMUM_NGRAM_LENGTH)).boost(20f)) + StringUtils.left(token, DefaultIndexSettings.MAXIMUM_NGRAM_LENGTH)).boost(20F)) .should( matchPhraseQuery( ENGLISH_HTML_ANALYZER.subField(FIELD_RULE_HTML_DESCRIPTION), 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 7ff947d2c54..82647a6ec02 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 @@ -91,7 +91,7 @@ public class IssueIteratorFactoryTest { assertThat(issue.directoryPath()).isEqualTo("src/main/java"); assertThat(issue.filePath()).isEqualTo("src/main/java/Action.java"); assertThat(issue.getTags()).containsOnly("tag1", "tag2", "tag3"); - assertThat(issue.effort().toMinutes()).isGreaterThan(0L); + assertThat(issue.effort().toMinutes()).isPositive(); assertThat(issue.type().getDbConstant()).isEqualTo(2); } 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 b41cd8980b4..ef1c1044962 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 @@ -59,21 +59,20 @@ public class ProjectTest { Project project1 = new Project("U1", "K1", "N1", null, emptyList()); Project project2 = new Project("U1", "K1", "N1", "D1", emptyList()); - assertThat(project1).isEqualTo(project1); - assertThat(project1).isNotEqualTo(null); - assertThat(project1).isNotEqualTo(new Object()); - assertThat(project1).isEqualTo(new Project("U1", "K1", "N1", null, emptyList())); - assertThat(project1).isNotEqualTo(new Project("U1", "K2", "N1", null, emptyList())); - assertThat(project1).isNotEqualTo(new Project("U1", "K1", "N2", null, emptyList())); - assertThat(project1).isEqualTo(project2); + assertThat(project1).isEqualTo(project1) + .isNotEqualTo(null) + .isNotEqualTo(new Object()) + .isEqualTo(new Project("U1", "K1", "N1", null, emptyList())) + .isNotEqualTo(new Project("U1", "K2", "N1", null, emptyList())) + .isNotEqualTo(new Project("U1", "K1", "N2", null, emptyList())) + .isEqualTo(project2); - assertThat(project1.hashCode()).isEqualTo(project1.hashCode()); - assertThat(project1.hashCode()).isNotEqualTo(null); + assertThat(project1).hasSameHashCodeAs(project1); assertThat(project1.hashCode()).isNotEqualTo(new Object().hashCode()); - assertThat(project1.hashCode()).isEqualTo(new Project("U1", "K1", "N1", null, emptyList()).hashCode()); + assertThat(project1).hasSameHashCodeAs(new Project("U1", "K1", "N1", null, emptyList())); assertThat(project1.hashCode()).isNotEqualTo(new Project("U1", "K2", "N1", null, emptyList()).hashCode()); assertThat(project1.hashCode()).isNotEqualTo(new Project("U1", "K1", "N2", null, emptyList()).hashCode()); - assertThat(project1.hashCode()).isEqualTo(project2.hashCode()); + assertThat(project1).hasSameHashCodeAs(project2); } } diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/rule/HotspotRuleDescriptionTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/rule/HotspotRuleDescriptionTest.java index f936c385a00..dde32340f59 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/rule/HotspotRuleDescriptionTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/rule/HotspotRuleDescriptionTest.java @@ -63,7 +63,7 @@ public class HotspotRuleDescriptionTest { HotspotRuleDescription result = HotspotRuleDescription.from(dto); - assertThat(result.getRisk().get()).isEqualTo(description); + assertThat(result.getRisk()).contains(description); assertThat(result.getVulnerable()).isEmpty(); assertThat(result.getFixIt()).isEmpty(); } @@ -85,8 +85,8 @@ public class HotspotRuleDescriptionTest { HotspotRuleDescription result = HotspotRuleDescription.from(dto); assertThat(result.getRisk()).isEmpty(); - assertThat(result.getVulnerable().get()).isEqualTo(ASKATRISK); - assertThat(result.getFixIt().get()).isEqualTo(RECOMMENTEDCODINGPRACTICE); + assertThat(result.getVulnerable()).contains(ASKATRISK); + assertThat(result.getFixIt()).contains(RECOMMENTEDCODINGPRACTICE); } @Test @@ -95,9 +95,9 @@ public class HotspotRuleDescriptionTest { HotspotRuleDescription result = HotspotRuleDescription.from(dto); - assertThat(result.getRisk().get()).isEqualTo(DESCRIPTION); + assertThat(result.getRisk()).contains(DESCRIPTION); assertThat(result.getVulnerable()).isEmpty(); - assertThat(result.getFixIt().get()).isEqualTo(RECOMMENTEDCODINGPRACTICE); + assertThat(result.getFixIt()).contains(RECOMMENTEDCODINGPRACTICE); } @Test @@ -106,8 +106,8 @@ public class HotspotRuleDescriptionTest { HotspotRuleDescription result = HotspotRuleDescription.from(dto); - assertThat(result.getRisk().get()).isEqualTo(DESCRIPTION); - assertThat(result.getVulnerable().get()).isEqualTo(ASKATRISK); + assertThat(result.getRisk()).contains(DESCRIPTION); + assertThat(result.getVulnerable()).contains(ASKATRISK); assertThat(result.getFixIt()).isEmpty(); } @@ -117,9 +117,9 @@ public class HotspotRuleDescriptionTest { HotspotRuleDescription result = HotspotRuleDescription.from(dto); - assertThat(result.getRisk().get()).isEqualTo(DESCRIPTION); - assertThat(result.getVulnerable().get()).isEqualTo(NONCOMPLIANTCODE); - assertThat(result.getFixIt().get()).isEqualTo(COMPLIANTCODE); + assertThat(result.getRisk()).contains(DESCRIPTION); + assertThat(result.getVulnerable()).contains(NONCOMPLIANTCODE); + assertThat(result.getFixIt()).contains(COMPLIANTCODE); } @Test @@ -128,10 +128,10 @@ public class HotspotRuleDescriptionTest { HotspotRuleDescription result = HotspotRuleDescription.from(dto); - assertThat(result.getRisk().get()).isEqualTo(DESCRIPTION); + assertThat(result.getRisk()).contains(DESCRIPTION); - assertThat(result.getVulnerable().get()).isEqualTo(NONCOMPLIANTCODE); - assertThat(result.getFixIt().get()).isEqualTo(RECOMMENTEDCODINGPRACTICE + SEE); + assertThat(result.getVulnerable()).contains(NONCOMPLIANTCODE); + assertThat(result.getFixIt()).contains(RECOMMENTEDCODINGPRACTICE + SEE); } @@ -141,9 +141,9 @@ public class HotspotRuleDescriptionTest { HotspotRuleDescription result = HotspotRuleDescription.from(dto); - assertThat(result.getRisk().get()).isEqualTo(DESCRIPTION); - assertThat(result.getVulnerable().get()).isEqualTo(ASKATRISK + SENSITIVECODE); - assertThat(result.getFixIt().get()).isEqualTo(RECOMMENTEDCODINGPRACTICE + SEE); + assertThat(result.getRisk()).contains(DESCRIPTION); + assertThat(result.getVulnerable()).contains(ASKATRISK + SENSITIVECODE); + assertThat(result.getFixIt()).contains(RECOMMENTEDCODINGPRACTICE + SEE); } @Test diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/security/SecurityReviewRatingTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/security/SecurityReviewRatingTest.java index 33180576567..a6c88c5998d 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/security/SecurityReviewRatingTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/security/SecurityReviewRatingTest.java @@ -68,10 +68,10 @@ public class SecurityReviewRatingTest { @Test public void compute_percent() { assertThat(computePercent(0, 0)).isEmpty(); - assertThat(computePercent(0, 10).get()).isEqualTo(100.0); - assertThat(computePercent(1, 3).get()).isEqualTo(75.0); + assertThat(computePercent(0, 10)).contains(100.0); + assertThat(computePercent(1, 3)).contains(75.0); assertThat(computePercent(3, 4).get()).isEqualTo(57.14, DOUBLE_OFFSET); - assertThat(computePercent(10, 10).get()).isEqualTo(50.0); - assertThat(computePercent(10, 0).get()).isEqualTo(0.0); + assertThat(computePercent(10, 10)).contains(50.0); + assertThat(computePercent(10, 0)).contains(0.0); } } diff --git a/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/PluginDownloaderTest.java b/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/PluginDownloaderTest.java index c45ce0c2f11..50bb1bca588 100644 --- a/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/PluginDownloaderTest.java +++ b/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/PluginDownloaderTest.java @@ -196,7 +196,7 @@ public class PluginDownloaderTest { pluginDownloader.start(); pluginDownloader.download("foo", create("1.0")); verify(httpDownloader, never()).download(any(URI.class), any(File.class)); - assertThat(noDownloadedFiles()).isGreaterThan(0); + assertThat(noDownloadedFiles()).isPositive(); } @Test @@ -270,7 +270,7 @@ public class PluginDownloaderTest { file2.createNewFile(); pluginDownloader.start(); - assertThat(noDownloadedFiles()).isGreaterThan(0); + assertThat(noDownloadedFiles()).isPositive(); pluginDownloader.cancelDownloads(); assertThat(noDownloadedFiles()).isZero(); } diff --git a/server/sonar-webserver-api/src/test/java/org/sonar/server/qualitygate/changeevent/QGChangeEventTest.java b/server/sonar-webserver-api/src/test/java/org/sonar/server/qualitygate/changeevent/QGChangeEventTest.java index 71395cb1106..754f7f0e5e9 100644 --- a/server/sonar-webserver-api/src/test/java/org/sonar/server/qualitygate/changeevent/QGChangeEventTest.java +++ b/server/sonar-webserver-api/src/test/java/org/sonar/server/qualitygate/changeevent/QGChangeEventTest.java @@ -123,8 +123,8 @@ public class QGChangeEventTest { public void overrides_toString() { QGChangeEvent underTest = new QGChangeEvent(project, branch, analysis, configuration, previousStatus, supplier); - assertThat(underTest.toString()) - .isEqualTo("QGChangeEvent{project=bar:foo, branch=BRANCH:bar:doh:zop, analysis=pto:8999999765" + + assertThat(underTest) + .hasToString("QGChangeEvent{project=bar:foo, branch=BRANCH:bar:doh:zop, analysis=pto:8999999765" + ", projectConfiguration=" + configuration.toString() + ", previousStatus=" + previousStatus + ", qualityGateSupplier=" + supplier + "}"); 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 c7aa4d5acae..fe7dcc2ce72 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 @@ -244,7 +244,7 @@ public class CredentialsLocalAuthentication { .setSalt(saltStr); } - private String hash(byte[] salt, String password, int iterations) { + private static String hash(byte[] salt, String password, int iterations) { try { SecretKeyFactory skf = SecretKeyFactory.getInstance(ALGORITHM); PBEKeySpec spec = new PBEKeySpec(password.toCharArray(), salt, iterations, KEY_LEN); diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/InitFilterTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/InitFilterTest.java index 1a450e5f9e4..cba0e20cb44 100644 --- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/InitFilterTest.java +++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/InitFilterTest.java @@ -133,7 +133,7 @@ public class InitFilterTest { underTest.doFilter(request, response, chain); - verify(auth2AuthenticationParameters).init(eq(request), eq(response)); + verify(auth2AuthenticationParameters).init(request, response); } @Test @@ -143,7 +143,7 @@ public class InitFilterTest { underTest.doFilter(request, response, chain); - verify(auth2AuthenticationParameters, never()).init(eq(request), eq(response)); + verify(auth2AuthenticationParameters, never()).init(request, response); } @Test @@ -263,7 +263,7 @@ public class InitFilterTest { } private void verifyDeleteAuthCookie() { - verify(auth2AuthenticationParameters).delete(eq(request), eq(response)); + verify(auth2AuthenticationParameters).delete(request, response); } private static class FailWithUnauthorizedExceptionIdProvider extends FakeBasicIdentityProvider { diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/JwtHttpHandlerTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/JwtHttpHandlerTest.java index e6c24b5176b..ba25da81862 100644 --- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/JwtHttpHandlerTest.java +++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/JwtHttpHandlerTest.java @@ -119,7 +119,7 @@ public class JwtHttpHandlerTest { verify(jwtSerializer).encode(jwtArgumentCaptor.capture()); JwtSerializer.JwtSession token = jwtArgumentCaptor.getValue(); - assertThat(token.getProperties().get("xsrfToken")).isEqualTo(CSRF_STATE); + assertThat(token.getProperties()).containsEntry("xsrfToken", CSRF_STATE); } @Test @@ -200,7 +200,7 @@ public class JwtHttpHandlerTest { Claims claims = createToken(sessionToken, NOW); when(jwtSerializer.decode(JWT_TOKEN)).thenReturn(Optional.of(claims)); - assertThat(underTest.validateToken(request, response).isPresent()).isTrue(); + assertThat(underTest.validateToken(request, response)).isPresent(); verify(jwtSerializer, never()).encode(any(JwtSerializer.JwtSession.class)); } @@ -215,7 +215,7 @@ public class JwtHttpHandlerTest { claims.put("lastRefreshTime", SIX_MINUTES_AGO); when(jwtSerializer.decode(JWT_TOKEN)).thenReturn(Optional.of(claims)); - assertThat(underTest.validateToken(request, response).isPresent()).isTrue(); + assertThat(underTest.validateToken(request, response)).isPresent(); verify(jwtSerializer).refresh(any(Claims.class), eq(NOW + 3 * 24 * 60 * 60 * 1000L)); assertThat(dbClient.sessionTokensDao().selectByUuid(dbSession, sessionToken.getUuid()).get().getExpirationDate()) @@ -233,7 +233,7 @@ public class JwtHttpHandlerTest { claims.put("lastRefreshTime", FOUR_MINUTES_AGO); when(jwtSerializer.decode(JWT_TOKEN)).thenReturn(Optional.of(claims)); - assertThat(underTest.validateToken(request, response).isPresent()).isTrue(); + assertThat(underTest.validateToken(request, response)).isPresent(); verify(jwtSerializer, never()).refresh(any(Claims.class), anyInt()); } @@ -248,7 +248,7 @@ public class JwtHttpHandlerTest { claims.put("lastRefreshTime", FOUR_MINUTES_AGO); when(jwtSerializer.decode(JWT_TOKEN)).thenReturn(Optional.of(claims)); - assertThat(underTest.validateToken(request, response).isPresent()).isFalse(); + assertThat(underTest.validateToken(request, response)).isEmpty(); } @Test @@ -259,7 +259,7 @@ public class JwtHttpHandlerTest { Claims claims = createToken(sessionToken, NOW); when(jwtSerializer.decode(JWT_TOKEN)).thenReturn(Optional.of(claims)); - assertThat(underTest.validateToken(request, response).isPresent()).isFalse(); + assertThat(underTest.validateToken(request, response)).isEmpty(); } @Test @@ -268,7 +268,7 @@ public class JwtHttpHandlerTest { when(jwtSerializer.decode(JWT_TOKEN)).thenReturn(Optional.empty()); - assertThat(underTest.validateToken(request, response).isPresent()).isFalse(); + assertThat(underTest.validateToken(request, response)).isEmpty(); } @Test @@ -276,7 +276,7 @@ public class JwtHttpHandlerTest { underTest.validateToken(request, response); verifyNoInteractions(httpSession, jwtSerializer); - assertThat(underTest.validateToken(request, response).isPresent()).isFalse(); + assertThat(underTest.validateToken(request, response)).isEmpty(); } @Test @@ -286,7 +286,7 @@ public class JwtHttpHandlerTest { underTest.validateToken(request, response); verifyNoInteractions(httpSession, jwtSerializer); - assertThat(underTest.validateToken(request, response).isPresent()).isFalse(); + assertThat(underTest.validateToken(request, response)).isEmpty(); } @Test @@ -314,7 +314,7 @@ public class JwtHttpHandlerTest { underTest.validateToken(request, response); - assertThat(underTest.validateToken(request, response).isPresent()).isFalse(); + assertThat(underTest.validateToken(request, response)).isEmpty(); } @Test @@ -330,7 +330,7 @@ public class JwtHttpHandlerTest { underTest.validateToken(request, response); - assertThat(underTest.validateToken(request, response).isPresent()).isFalse(); + assertThat(underTest.validateToken(request, response)).isEmpty(); } @Test @@ -394,7 +394,7 @@ public class JwtHttpHandlerTest { private void verifyToken(JwtSerializer.JwtSession token, UserDto user, long expectedExpirationDuration, long expectedRefreshTime) { assertThat(token.getExpirationTime()).isEqualTo(NOW + expectedExpirationDuration * 1000L); assertThat(token.getUserLogin()).isEqualTo(user.getUuid()); - assertThat(token.getProperties().get("lastRefreshTime")).isEqualTo(expectedRefreshTime); + assertThat(token.getProperties()).containsEntry("lastRefreshTime", expectedRefreshTime); } private Optional<Cookie> findCookie(String name) { diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/OAuth2ContextFactoryTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/OAuth2ContextFactoryTest.java index 88bb0e0b719..ea5ebad1ccb 100644 --- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/OAuth2ContextFactoryTest.java +++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/OAuth2ContextFactoryTest.java @@ -209,7 +209,7 @@ public class OAuth2ContextFactoryTest { callback.redirectToRequestedPage(); - verify(oAuthParameters).delete(eq(request), eq(response)); + verify(oAuthParameters).delete(request, response); } private OAuth2IdentityProvider.InitContext newInitContext() { 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 0659c0520eb..b1919b83d59 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 @@ -62,7 +62,7 @@ public class UserTokenAuthenticationTest { Optional<String> login = underTest.authenticate(token); assertThat(login.isPresent()).isTrue(); - assertThat(login.get()).isEqualTo(user1.getUuid()); + assertThat(login).contains(user1.getUuid()); verify(userLastConnectionDatesUpdater).updateLastConnectionDateIfNeeded(any(UserTokenDto.class)); } diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/AbstractSystemInfoWriter.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/AbstractSystemInfoWriter.java index aff00e45cf1..1cdae261b7c 100644 --- a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/AbstractSystemInfoWriter.java +++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/AbstractSystemInfoWriter.java @@ -51,7 +51,7 @@ public abstract class AbstractSystemInfoWriter implements SystemInfoWriter { .forEach(section -> writeSection(section, json)); } - private void writeSection(ProtobufSystemInfo.Section section, JsonWriter json) { + private static void writeSection(ProtobufSystemInfo.Section section, JsonWriter json) { json.name(section.getName()); json.beginObject(); for (ProtobufSystemInfo.Attribute attribute : section.getAttributesList()) { diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/qualitygate/ProjectsInWarningDaemon.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/qualitygate/ProjectsInWarningDaemon.java index 11cde567b82..2751a07efe3 100644 --- a/server/sonar-webserver-core/src/main/java/org/sonar/server/qualitygate/ProjectsInWarningDaemon.java +++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/qualitygate/ProjectsInWarningDaemon.java @@ -39,13 +39,14 @@ import org.sonar.server.util.GlobalLockManager; import static org.sonar.api.measures.Metric.Level.WARN; /** - * This class is regularly checking the number of projects in warning state, in order to not return the "Warning" value in the quality gate facet of the Projects page when there are no more projects in warning. + * This class is regularly checking the number of projects in warning state, in order to not return the "Warning" value + * in the quality gate facet of the Projects page when there are no more projects in warning. * * @see <a href="https://jira.sonarsource.com/browse/SONAR-12140">SONAR-12140</a> for more information */ public class ProjectsInWarningDaemon implements Startable { - final static String PROJECTS_IN_WARNING_INTERNAL_PROPERTY = "projectsInWarning"; + static final String PROJECTS_IN_WARNING_INTERNAL_PROPERTY = "projectsInWarning"; private static final Logger LOG = Loggers.get(ProjectsInWarningDaemon.class); diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/es/IndexerStartupTaskAsyncTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/es/IndexerStartupTaskAsyncTest.java index 961b562ef43..82d3af617e7 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/es/IndexerStartupTaskAsyncTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/es/IndexerStartupTaskAsyncTest.java @@ -28,9 +28,7 @@ import org.sonar.server.es.metadata.MetadataIndex; import org.sonar.server.es.metadata.MetadataIndexImpl; import org.sonar.server.es.newindex.FakeIndexDefinition; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anySet; -import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; @@ -70,7 +68,7 @@ public class IndexerStartupTaskAsyncTest { underTest.execute(); - verify(metadataIndex).setInitialized(eq(TYPE_FAKE), eq(true)); + verify(metadataIndex).setInitialized(TYPE_FAKE, true); } @Test 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 3639129a8c2..c4a99ac8ec9 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 @@ -67,7 +67,7 @@ public class SourceServiceTest { public void get_range_of_lines() { Set<Integer> lineNumbers = new HashSet<>(Arrays.asList(1, 5, 6)); Optional<Iterable<DbFileSources.Line>> linesOpt = underTest.getLines(dbTester.getSession(), FILE_UUID, lineNumbers); - 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(1); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/SkipOnboardingTutorialActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/SkipOnboardingTutorialActionTest.java index 7f5b563040e..de111e62272 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/SkipOnboardingTutorialActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/SkipOnboardingTutorialActionTest.java @@ -54,7 +54,7 @@ public class SkipOnboardingTutorialActionTest { call(); UserDto userDto = selectUser(user.getLogin()); - assertThat(userDto.isOnboarded()).isEqualTo(true); + assertThat(userDto.isOnboarded()).isTrue(); } @Test @@ -66,7 +66,7 @@ public class SkipOnboardingTutorialActionTest { call(); UserDto userDto = selectUser(user.getLogin()); - assertThat(userDto.isOnboarded()).isEqualTo(true); + assertThat(userDto.isOnboarded()).isTrue(); assertThat(userDto.getUpdatedAt()).isEqualTo(user.getUpdatedAt()); } diff --git a/server/sonar-webserver/src/test/java/org/sonar/server/app/TomcatContextsTest.java b/server/sonar-webserver/src/test/java/org/sonar/server/app/TomcatContextsTest.java index 8da153a75ad..07255ec9c55 100644 --- a/server/sonar-webserver/src/test/java/org/sonar/server/app/TomcatContextsTest.java +++ b/server/sonar-webserver/src/test/java/org/sonar/server/app/TomcatContextsTest.java @@ -126,12 +126,12 @@ public class TomcatContextsTest { public void root_context_path_must_be_blank() { props.setProperty("sonar.web.context", "/"); - assertThat(TomcatContexts.getContextPath(new Props(props))).isEqualTo(""); + assertThat(TomcatContexts.getContextPath(new Props(props))).isEmpty(); } @Test public void default_context_path_is_root() { String context = TomcatContexts.getContextPath(new Props(new Properties())); - assertThat(context).isEqualTo(""); + assertThat(context).isEmpty(); } } |