diff options
author | Pierre <pierre.guillot@sonarsource.com> | 2020-12-11 17:20:41 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2020-12-14 20:07:14 +0000 |
commit | ffcea568c79640227b2fd9c562f642b9d087ea10 (patch) | |
tree | 6b0c16201bdc6308048744fea48f4e4a9667fd5d /sonar-scanner-engine/src | |
parent | 4e07979ccca556d5f05a1be05b88f0bd85ff3f66 (diff) | |
download | sonarqube-ffcea568c79640227b2fd9c562f642b9d087ea10.tar.gz sonarqube-ffcea568c79640227b2fd9c562f642b9d087ea10.zip |
fix code smells
Diffstat (limited to 'sonar-scanner-engine/src')
12 files changed, 62 insertions, 50 deletions
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/bootstrapper/LoggingConfiguratorTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/bootstrapper/LoggingConfiguratorTest.java index 0b69d4917d4..ac2b3ea5cc2 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/batch/bootstrapper/LoggingConfiguratorTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/bootstrapper/LoggingConfiguratorTest.java @@ -107,7 +107,7 @@ public class LoggingConfiguratorTest { logger.error(TEST_STR); logger.info(TEST_STR); logger.debug(TEST_STR); - assertThat(out.size()).isEqualTo(0); + assertThat(out.size()).isZero(); } @Test diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/PluginFilesTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/PluginFilesTest.java index 2878464e325..dd6d43348bd 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/PluginFilesTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/PluginFilesTest.java @@ -91,7 +91,7 @@ public class PluginFilesTest { verifySameContent(result, jar); // no requests to server - assertThat(server.getRequestCount()).isEqualTo(0); + assertThat(server.getRequestCount()).isZero(); } @Test diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/CpdExecutorTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/CpdExecutorTest.java index f8614ce4fcc..88c0f065dfd 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/CpdExecutorTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/CpdExecutorTest.java @@ -275,7 +275,7 @@ public class CpdExecutorTest { if (otherFileRef != null) { assertThat(d.getDuplicate(0).getOtherFileRef()).isEqualTo(otherFileRef); } else { - assertThat(d.getDuplicate(0).getOtherFileRef()).isEqualTo(0); + assertThat(d.getDuplicate(0).getOtherFileRef()).isZero(); } assertThat(d.getDuplicate(0).getRange().getStartLine()).isEqualTo(rangeStartLine); assertThat(d.getDuplicate(0).getRange().getEndLine()).isEqualTo(rangeEndLine); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/externalissue/ExternalIssueImporterTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/externalissue/ExternalIssueImporterTest.java index 3d845f72376..46ec1f34b40 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/externalissue/ExternalIssueImporterTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/externalissue/ExternalIssueImporterTest.java @@ -132,7 +132,7 @@ public class ExternalIssueImporterTest { assertThat(context.allExternalIssues()).hasSize(1); TextRange got = context.allExternalIssues().iterator().next().primaryLocation().textRange(); assertThat(got.start().line()).isEqualTo(input.startLine); - assertThat(got.start().lineOffset()).isEqualTo(0); + assertThat(got.start().lineOffset()).isZero(); assertThat(got.end().line()).isEqualTo(input.startLine); assertThat(got.end().lineOffset()).isEqualTo(sourceFile.selectLine(input.startLine).end().lineOffset()); } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/genericcoverage/GenericCoverageReportParserTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/genericcoverage/GenericCoverageReportParserTest.java index 2737c635d61..20d679705c1 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/genericcoverage/GenericCoverageReportParserTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/genericcoverage/GenericCoverageReportParserTest.java @@ -69,11 +69,11 @@ public class GenericCoverageReportParserTest { parser.parse(new File(this.getClass().getResource("coverage.xml").toURI()), context); assertThat(parser.numberOfMatchedFiles()).isEqualTo(1); - assertThat(context.lineHits(fileWithoutBranch.key(), 2)).isEqualTo(0); + assertThat(context.lineHits(fileWithoutBranch.key(), 2)).isZero(); assertThat(context.lineHits(fileWithoutBranch.key(), 3)).isEqualTo(1); assertThat(context.lineHits(fileWithoutBranch.key(), 4)).isNull(); assertThat(context.lineHits(fileWithoutBranch.key(), 5)).isEqualTo(1); - assertThat(context.lineHits(fileWithoutBranch.key(), 6)).isEqualTo(0); + assertThat(context.lineHits(fileWithoutBranch.key(), 6)).isZero(); } @Test @@ -90,7 +90,7 @@ public class GenericCoverageReportParserTest { assertThat(context.conditions(fileWithBranches.key(), 4)).isEqualTo(2); assertThat(context.coveredConditions(fileWithBranches.key(), 3)).isEqualTo(5); - assertThat(context.coveredConditions(fileWithBranches.key(), 4)).isEqualTo(0); + assertThat(context.coveredConditions(fileWithBranches.key(), 4)).isZero(); } @Test(expected = MessageException.class) diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/pattern/IssueExclusionPatternInitializerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/pattern/IssueExclusionPatternInitializerTest.java index cbb6acfb109..c1f58c9cb85 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/pattern/IssueExclusionPatternInitializerTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/pattern/IssueExclusionPatternInitializerTest.java @@ -42,7 +42,7 @@ public class IssueExclusionPatternInitializerTest { public void testNoConfiguration() { patternsInitializer = new IssueExclusionPatternInitializer(settings.asConfig()); assertThat(patternsInitializer.hasConfiguredPatterns()).isFalse(); - assertThat(patternsInitializer.getMulticriteriaPatterns().size()).isEqualTo(0); + assertThat(patternsInitializer.getMulticriteriaPatterns().size()).isZero(); } @Test(expected = MessageException.class) @@ -75,9 +75,9 @@ public class IssueExclusionPatternInitializerTest { assertThat(patternsInitializer.hasConfiguredPatterns()).isTrue(); assertThat(patternsInitializer.hasFileContentPattern()).isTrue(); assertThat(patternsInitializer.hasMulticriteriaPatterns()).isFalse(); - assertThat(patternsInitializer.getMulticriteriaPatterns().size()).isEqualTo(0); + assertThat(patternsInitializer.getMulticriteriaPatterns().size()).isZero(); assertThat(patternsInitializer.getBlockPatterns().size()).isEqualTo(3); - assertThat(patternsInitializer.getAllFilePatterns().size()).isEqualTo(0); + assertThat(patternsInitializer.getAllFilePatterns().size()).isZero(); } @Test(expected = MessageException.class) @@ -98,8 +98,8 @@ public class IssueExclusionPatternInitializerTest { assertThat(patternsInitializer.hasConfiguredPatterns()).isTrue(); assertThat(patternsInitializer.hasFileContentPattern()).isTrue(); assertThat(patternsInitializer.hasMulticriteriaPatterns()).isFalse(); - assertThat(patternsInitializer.getMulticriteriaPatterns().size()).isEqualTo(0); - assertThat(patternsInitializer.getBlockPatterns().size()).isEqualTo(0); + assertThat(patternsInitializer.getMulticriteriaPatterns().size()).isZero(); + assertThat(patternsInitializer.getBlockPatterns().size()).isZero(); assertThat(patternsInitializer.getAllFilePatterns().size()).isEqualTo(2); } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/coverage/CoverageMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/coverage/CoverageMediumTest.java index df1a9f9f14b..7c8f2eabaf1 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/coverage/CoverageMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/coverage/CoverageMediumTest.java @@ -277,8 +277,8 @@ public class CoverageMediumTest { assertThat(result.coverageFor(file, 1)).isNull(); assertThat(result.coverageFor(file, 2).getHits()).isFalse(); - assertThat(result.coverageFor(file, 2).getConditions()).isEqualTo(0); - assertThat(result.coverageFor(file, 2).getCoveredConditions()).isEqualTo(0); + assertThat(result.coverageFor(file, 2).getConditions()).isZero(); + assertThat(result.coverageFor(file, 2).getCoveredConditions()).isZero(); assertThat(result.coverageFor(file, 3).getHits()).isFalse(); assertThat(result.coverageFor(file, 4)).isNull(); @@ -351,8 +351,8 @@ public class CoverageMediumTest { assertThat(result.coverageFor(file1, 1)).isNull(); assertThat(result.coverageFor(file1, 2).getHits()).isFalse(); - assertThat(result.coverageFor(file1, 2).getConditions()).isEqualTo(0); - assertThat(result.coverageFor(file1, 2).getCoveredConditions()).isEqualTo(0); + assertThat(result.coverageFor(file1, 2).getConditions()).isZero(); + assertThat(result.coverageFor(file1, 2).getCoveredConditions()).isZero(); assertThat(result.coverageFor(file1, 3).getHits()).isFalse(); assertThat(result.coverageFor(file1, 4)).isNull(); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/coverage/GenericCoverageMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/coverage/GenericCoverageMediumTest.java index bd2e1f3cdd7..2400a31d898 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/coverage/GenericCoverageMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/coverage/GenericCoverageMediumTest.java @@ -52,8 +52,8 @@ public class GenericCoverageMediumTest { InputFile noConditions = result.inputFile("xources/hello/NoConditions.xoo"); assertThat(result.coverageFor(noConditions, 6).getHits()).isTrue(); - assertThat(result.coverageFor(noConditions, 6).getConditions()).isEqualTo(0); - assertThat(result.coverageFor(noConditions, 6).getCoveredConditions()).isEqualTo(0); + assertThat(result.coverageFor(noConditions, 6).getConditions()).isZero(); + assertThat(result.coverageFor(noConditions, 6).getCoveredConditions()).isZero(); assertThat(result.coverageFor(noConditions, 7).getHits()).isFalse(); @@ -79,8 +79,8 @@ public class GenericCoverageMediumTest { InputFile noConditions = result.inputFile("xources/hello/NoConditions.xoo"); assertThat(result.coverageFor(noConditions, 6).getHits()).isTrue(); - assertThat(result.coverageFor(noConditions, 6).getConditions()).isEqualTo(0); - assertThat(result.coverageFor(noConditions, 6).getCoveredConditions()).isEqualTo(0); + assertThat(result.coverageFor(noConditions, 6).getConditions()).isZero(); + assertThat(result.coverageFor(noConditions, 6).getCoveredConditions()).isZero(); assertThat(result.coverageFor(noConditions, 7).getHits()).isTrue(); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/ExternalIssuesMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/ExternalIssuesMediumTest.java index b30f7455091..2ecec04dea2 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/ExternalIssuesMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/ExternalIssuesMediumTest.java @@ -122,37 +122,25 @@ public class ExternalIssuesMediumTest { // precise issue location ExternalIssue issue = externalIssues.get(0); - assertThat(issue.getFlowCount()).isZero(); - assertThat(issue.getMsg()).isEqualTo("fix the issue here"); - assertThat(issue.getEngineId()).isEqualTo("externalXoo"); - assertThat(issue.getRuleId()).isEqualTo("rule1"); - assertThat(issue.getSeverity()).isEqualTo(Severity.MAJOR); - assertThat(issue.getEffort()).isEqualTo(50l); - assertThat(issue.getType()).isEqualTo(IssueType.CODE_SMELL); - assertThat(issue.getTextRange().getStartLine()).isEqualTo(5); - assertThat(issue.getTextRange().getEndLine()).isEqualTo(5); - assertThat(issue.getTextRange().getStartOffset()).isEqualTo(3); - assertThat(issue.getTextRange().getEndOffset()).isEqualTo(41); + assertPreciseIssueLocation(issue); // location on a line issue = externalIssues.get(1); - assertThat(issue.getFlowCount()).isZero(); - assertThat(issue.getMsg()).isEqualTo("fix the bug here"); - assertThat(issue.getEngineId()).isEqualTo("externalXoo"); - assertThat(issue.getRuleId()).isEqualTo("rule2"); - assertThat(issue.getSeverity()).isEqualTo(Severity.CRITICAL); - assertThat(issue.getType()).isEqualTo(IssueType.BUG); - assertThat(issue.getEffort()).isZero(); - assertThat(issue.getTextRange().getStartLine()).isEqualTo(3); - assertThat(issue.getTextRange().getEndLine()).isEqualTo(3); - assertThat(issue.getTextRange().getStartOffset()).isEqualTo(0); - assertThat(issue.getTextRange().getEndOffset()).isEqualTo(24); + assertIssueLocationLine(issue); // One file-level issue in helloscala, with secondary location List<ExternalIssue> externalIssues2 = result.externalIssuesFor(result.inputFile("xources/hello/helloscala.xoo")); assertThat(externalIssues2).hasSize(1); issue = externalIssues2.iterator().next(); + assertSecondaryLocation(issue); + + // one issue is located in a non-existing file + assertThat(logs.logs()).contains("External issues ignored for 1 unknown files, including: invalidFile"); + + } + + private void assertSecondaryLocation(ExternalIssue issue) { assertThat(issue.getFlowCount()).isEqualTo(2); assertThat(issue.getMsg()).isEqualTo("fix the bug here"); assertThat(issue.getEngineId()).isEqualTo("externalXoo"); @@ -164,9 +152,33 @@ public class ExternalIssuesMediumTest { assertThat(issue.getFlow(0).getLocation(0).getTextRange().getStartLine()).isOne(); assertThat(issue.getFlow(1).getLocationCount()).isOne(); assertThat(issue.getFlow(1).getLocation(0).getTextRange().getStartLine()).isEqualTo(3); + } - // one issue is located in a non-existing file - assertThat(logs.logs()).contains("External issues ignored for 1 unknown files, including: invalidFile"); + private void assertIssueLocationLine(ExternalIssue issue) { + assertThat(issue.getFlowCount()).isZero(); + assertThat(issue.getMsg()).isEqualTo("fix the bug here"); + assertThat(issue.getEngineId()).isEqualTo("externalXoo"); + assertThat(issue.getRuleId()).isEqualTo("rule2"); + assertThat(issue.getSeverity()).isEqualTo(Severity.CRITICAL); + assertThat(issue.getType()).isEqualTo(IssueType.BUG); + assertThat(issue.getEffort()).isZero(); + assertThat(issue.getTextRange().getStartLine()).isEqualTo(3); + assertThat(issue.getTextRange().getEndLine()).isEqualTo(3); + assertThat(issue.getTextRange().getStartOffset()).isZero(); + assertThat(issue.getTextRange().getEndOffset()).isEqualTo(24); + } + private void assertPreciseIssueLocation(ExternalIssue issue) { + assertThat(issue.getFlowCount()).isZero(); + assertThat(issue.getMsg()).isEqualTo("fix the issue here"); + assertThat(issue.getEngineId()).isEqualTo("externalXoo"); + assertThat(issue.getRuleId()).isEqualTo("rule1"); + assertThat(issue.getSeverity()).isEqualTo(Severity.MAJOR); + assertThat(issue.getEffort()).isEqualTo(50l); + assertThat(issue.getType()).isEqualTo(IssueType.CODE_SMELL); + assertThat(issue.getTextRange().getStartLine()).isEqualTo(5); + assertThat(issue.getTextRange().getEndLine()).isEqualTo(5); + assertThat(issue.getTextRange().getStartOffset()).isEqualTo(3); + assertThat(issue.getTextRange().getEndOffset()).isEqualTo(41); } } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/IssuesMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/IssuesMediumTest.java index 64f99bb2ac9..c444ce342bd 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/IssuesMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/IssuesMediumTest.java @@ -229,7 +229,7 @@ public class IssuesMediumTest { assertThat(logTester.logs(LoggerLevel.WARN)).contains("Specifying module-relative paths at project level in property 'sonar.issue.ignore.multicriteria' is deprecated. To continue matching files like 'moduleA/src/sampleA.xoo', update this property so that patterns refer to project-relative paths."); List<Issue> issues = result.issuesFor(result.inputFile("moduleA/src/sampleA.xoo")); - assertThat(issues).hasSize(0); + assertThat(issues).isEmpty(); issues = result.issuesFor(result.inputFile("moduleB/src/sampleB.xoo")); assertThat(issues).hasSize(10); @@ -376,7 +376,7 @@ public class IssuesMediumTest { assertThat(issues).hasSize(10); issues = result.issuesFor(result.inputFile("moduleB/src/sampleB.xoo")); - assertThat(issues).hasSize(0); + assertThat(issues).isEmpty(); } private void activateTODORule() { diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ComponentsPublisherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ComponentsPublisherTest.java index 74bc606295f..58d31feebf6 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ComponentsPublisherTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ComponentsPublisherTest.java @@ -124,7 +124,7 @@ public class ComponentsPublisherTest { Component rootProtobuf = reader.readComponent(1); assertThat(rootProtobuf.getKey()).isEqualTo("foo"); assertThat(rootProtobuf.getDescription()).isEqualTo("Root description"); - assertThat(rootProtobuf.getLinkCount()).isEqualTo(0); + assertThat(rootProtobuf.getLinkCount()).isZero(); assertThat(reader.readComponent(4).getStatus()).isEqualTo(FileStatus.SAME); assertThat(reader.readComponent(6).getStatus()).isEqualTo(FileStatus.CHANGED); @@ -195,7 +195,7 @@ public class ComponentsPublisherTest { assertThat(rootProtobuf.getKey()).isEqualTo("foo"); assertThat(rootProtobuf.getName()).isEqualTo(""); assertThat(rootProtobuf.getDescription()).isEqualTo("Root description"); - assertThat(rootProtobuf.getLinkCount()).isEqualTo(0); + assertThat(rootProtobuf.getLinkCount()).isZero(); } @Test diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/ByteCharsetDetectorTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/ByteCharsetDetectorTest.java index 86942280267..a123b6656ed 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/ByteCharsetDetectorTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/ByteCharsetDetectorTest.java @@ -87,7 +87,7 @@ public class ByteCharsetDetectorTest { when(validation.isUTF16(any(byte[].class), anyBoolean())).thenReturn(new Result(Validation.MAYBE, null)); when(validation.isValidWindows1252(any(byte[].class))).thenReturn(Result.INVALID); - assertThat(charsets.detect(new byte[1])).isEqualTo(null); + assertThat(charsets.detect(new byte[1])).isNull(); } @Test @@ -96,7 +96,7 @@ public class ByteCharsetDetectorTest { when(validation.isUTF16(any(byte[].class), anyBoolean())).thenReturn(Result.newValid(StandardCharsets.UTF_16)); when(validation.isValidUTF16(any(byte[].class), anyBoolean())).thenReturn(true); - assertThat(charsets.detect(new byte[1])).isEqualTo(null); + assertThat(charsets.detect(new byte[1])).isNull(); } @Test |