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 /sonar-scanner-engine/src/test/java | |
parent | aa640be9e2b9cfa2c027ef0768940b31ebb5536c (diff) | |
download | sonarqube-3f9445c25962f914ccdd889c002ddd8e19b0cf89.tar.gz sonarqube-3f9445c25962f914ccdd889c002ddd8e19b0cf89.zip |
Improve code quality
Diffstat (limited to 'sonar-scanner-engine/src/test/java')
27 files changed, 79 insertions, 77 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 c88a8865ff0..a834106711b 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 @@ -148,7 +148,7 @@ public class LoggingConfiguratorTest { Logger logger = LoggerFactory.getLogger(this.getClass()); logger.info("info"); - assertThat(new String(out.toByteArray(), StandardCharsets.UTF_8)).contains("info"); + assertThat(out.toString(StandardCharsets.UTF_8)).contains("info"); } } 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 ae65480b996..404d42faf78 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 @@ -107,7 +107,7 @@ public class PluginFilesTest { // get from cache on second call result = underTest.get(plugin).get(); verifySameContent(result, tempJar); - assertThat(server.getRequestCount()).isEqualTo(1); + assertThat(server.getRequestCount()).isOne(); } @Test @@ -125,7 +125,7 @@ public class PluginFilesTest { // get from cache on second call result = underTest.get(plugin).get(); verifySameContentAfterCompression(jar.file, result); - assertThat(server.getRequestCount()).isEqualTo(1); + assertThat(server.getRequestCount()).isOne(); } @Test @@ -203,7 +203,7 @@ public class PluginFilesTest { InstalledPlugin pluginV2 = newInstalledPlugin("foo", tempJar.md5); result = underTest.get(pluginV2).get(); verifySameContent(result, tempJar); - assertThat(server.getRequestCount()).isEqualTo(1); + assertThat(server.getRequestCount()).isOne(); // v1 still requests server and downloads v2 enqueueDownload(tempJar); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/externalissue/ReportParserTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/externalissue/ReportParserTest.java index d30cac61351..8f045fdb1c5 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/externalissue/ReportParserTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/externalissue/ReportParserTest.java @@ -44,7 +44,7 @@ public class ReportParserTest { assertThat(report.issues[0].primaryLocation.filePath).isEqualTo("file1.js"); assertThat(report.issues[0].primaryLocation.message).isEqualTo("fix the issue here"); assertThat(report.issues[0].primaryLocation.textRange.startColumn).isEqualTo(2); - assertThat(report.issues[0].primaryLocation.textRange.startLine).isEqualTo(1); + assertThat(report.issues[0].primaryLocation.textRange.startLine).isOne(); assertThat(report.issues[0].primaryLocation.textRange.endColumn).isEqualTo(4); assertThat(report.issues[0].primaryLocation.textRange.endLine).isEqualTo(3); assertThat(report.issues[0].secondaryLocations).isNull(); @@ -57,7 +57,7 @@ public class ReportParserTest { assertThat(report.issues[3].secondaryLocations).hasSize(2); assertThat(report.issues[3].secondaryLocations[0].filePath).isEqualTo("file1.js"); assertThat(report.issues[3].secondaryLocations[0].message).isEqualTo("fix the bug here"); - assertThat(report.issues[3].secondaryLocations[0].textRange.startLine).isEqualTo(1); + assertThat(report.issues[3].secondaryLocations[0].textRange.startLine).isOne(); assertThat(report.issues[3].secondaryLocations[1].filePath).isEqualTo("file2.js"); assertThat(report.issues[3].secondaryLocations[1].message).isNull(); assertThat(report.issues[3].secondaryLocations[1].textRange.startLine).isEqualTo(2); 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 03e5590e1ba..6c18c951989 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 @@ -59,7 +59,7 @@ public class GenericCoverageReportParserTest { addFileToFs(emptyFile); GenericCoverageReportParser parser = new GenericCoverageReportParser(); parser.parse(new File(this.getClass().getResource("coverage.xml").toURI()), context); - assertThat(parser.numberOfMatchedFiles()).isEqualTo(1); + assertThat(parser.numberOfMatchedFiles()).isOne(); assertThat(parser.numberOfUnknownFiles()).isEqualTo(3); assertThat(parser.firstUnknownFiles()).hasSize(3); } @@ -87,12 +87,12 @@ public class GenericCoverageReportParserTest { addFileToFs(fileWithoutBranch); GenericCoverageReportParser parser = new GenericCoverageReportParser(); parser.parse(new File(this.getClass().getResource("coverage.xml").toURI()), context); - assertThat(parser.numberOfMatchedFiles()).isEqualTo(1); + assertThat(parser.numberOfMatchedFiles()).isOne(); assertThat(context.lineHits(fileWithoutBranch.key(), 2)).isZero(); - assertThat(context.lineHits(fileWithoutBranch.key(), 3)).isEqualTo(1); + assertThat(context.lineHits(fileWithoutBranch.key(), 3)).isOne(); assertThat(context.lineHits(fileWithoutBranch.key(), 4)).isNull(); - assertThat(context.lineHits(fileWithoutBranch.key(), 5)).isEqualTo(1); + assertThat(context.lineHits(fileWithoutBranch.key(), 5)).isOne(); assertThat(context.lineHits(fileWithoutBranch.key(), 6)).isZero(); } @@ -101,10 +101,10 @@ public class GenericCoverageReportParserTest { addFileToFs(fileWithBranches); GenericCoverageReportParser parser = new GenericCoverageReportParser(); parser.parse(new File(this.getClass().getResource("coverage.xml").toURI()), context); - assertThat(parser.numberOfMatchedFiles()).isEqualTo(1); + assertThat(parser.numberOfMatchedFiles()).isOne(); - assertThat(context.lineHits(fileWithBranches.key(), 3)).isEqualTo(1); - assertThat(context.lineHits(fileWithBranches.key(), 4)).isEqualTo(1); + assertThat(context.lineHits(fileWithBranches.key(), 3)).isOne(); + assertThat(context.lineHits(fileWithBranches.key(), 4)).isOne(); assertThat(context.conditions(fileWithBranches.key(), 3)).isEqualTo(8); assertThat(context.conditions(fileWithBranches.key(), 4)).isEqualTo(2); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/genericcoverage/GenericTestExecutionReportParserTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/genericcoverage/GenericTestExecutionReportParserTest.java index 81e38534878..c617537ddf0 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/genericcoverage/GenericTestExecutionReportParserTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/genericcoverage/GenericTestExecutionReportParserTest.java @@ -90,8 +90,8 @@ public class GenericTestExecutionReportParserTest { public void ut_empty_file() throws Exception { addFileToFs(emptyFile); GenericTestExecutionReportParser parser = parseReportFile("unittest.xml"); - assertThat(parser.numberOfMatchedFiles()).isEqualTo(1); - assertThat(parser.numberOfUnknownFiles()).isEqualTo(1); + assertThat(parser.numberOfMatchedFiles()).isOne(); + assertThat(parser.numberOfUnknownFiles()).isOne(); assertThat(parser.firstUnknownFiles()).hasSize(1); } @@ -99,7 +99,7 @@ public class GenericTestExecutionReportParserTest { public void file_with_unittests() throws Exception { addFileToFs(fileWithBranches); GenericTestExecutionReportParser parser = parseReportFile("unittest2.xml"); - assertThat(parser.numberOfMatchedFiles()).isEqualTo(1); + assertThat(parser.numberOfMatchedFiles()).isOne(); verify(testPlan).addTestCase("test1"); verify(testPlan).addTestCase("test2"); 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 8ad325527e6..a56c632b7c7 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 @@ -76,7 +76,7 @@ public class IssueExclusionPatternInitializerTest { assertThat(patternsInitializer.hasFileContentPattern()).isTrue(); assertThat(patternsInitializer.hasMulticriteriaPatterns()).isFalse(); assertThat(patternsInitializer.getMulticriteriaPatterns().size()).isZero(); - assertThat(patternsInitializer.getBlockPatterns().size()).isEqualTo(3); + assertThat(patternsInitializer.getBlockPatterns()).hasSize(3); assertThat(patternsInitializer.getAllFilePatterns().size()).isZero(); } @@ -100,7 +100,7 @@ public class IssueExclusionPatternInitializerTest { assertThat(patternsInitializer.hasMulticriteriaPatterns()).isFalse(); assertThat(patternsInitializer.getMulticriteriaPatterns().size()).isZero(); assertThat(patternsInitializer.getBlockPatterns().size()).isZero(); - assertThat(patternsInitializer.getAllFilePatterns().size()).isEqualTo(2); + assertThat(patternsInitializer.getAllFilePatterns()).hasSize(2); } @Test(expected = MessageException.class) diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/pattern/IssueInclusionPatternInitializerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/pattern/IssueInclusionPatternInitializerTest.java index 75f9f34c85c..89bb07f9bc4 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/pattern/IssueInclusionPatternInitializerTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/pattern/IssueInclusionPatternInitializerTest.java @@ -56,7 +56,7 @@ public class IssueInclusionPatternInitializerTest { assertThat(patternsInitializer.hasConfiguredPatterns()).isTrue(); assertThat(patternsInitializer.hasMulticriteriaPatterns()).isTrue(); - assertThat(patternsInitializer.getMulticriteriaPatterns().size()).isEqualTo(2); + assertThat(patternsInitializer.getMulticriteriaPatterns()).hasSize(2); } } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/pattern/LineRangeTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/pattern/LineRangeTest.java index 256f4b6dd75..bf69c73a6ab 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/pattern/LineRangeTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/pattern/LineRangeTest.java @@ -57,16 +57,17 @@ public class LineRangeTest { @Test public void testEquals() { LineRange range = new LineRange(12, 15); - assertThat(range).isEqualTo(range); - assertThat(range).isEqualTo(new LineRange(12, 15)); - assertThat(range).isNotEqualTo(new LineRange(12, 2000)); - assertThat(range).isNotEqualTo(new LineRange(1000, 2000)); - assertThat(range).isNotEqualTo(null); - assertThat(range).isNotEqualTo(new StringBuffer()); + assertThat(range) + .isEqualTo(range) + .isEqualTo(new LineRange(12, 15)) + .isNotEqualTo(new LineRange(12, 2000)) + .isNotEqualTo(new LineRange(1000, 2000)) + .isNotNull() + .isNotEqualTo(new StringBuffer()); } @Test public void testHashCode() { - assertThat(new LineRange(12, 15).hashCode()).isEqualTo(new LineRange(12, 15).hashCode()); + assertThat(new LineRange(12, 15)).hasSameHashCodeAs(new LineRange(12, 15)); } } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/scanner/IssueExclusionsLoaderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/scanner/IssueExclusionsLoaderTest.java index 6a51e1e7816..3a8634dda4a 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/scanner/IssueExclusionsLoaderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/scanner/IssueExclusionsLoaderTest.java @@ -73,7 +73,7 @@ public class IssueExclusionsLoaderTest { public void populateRuleExclusionPatterns() { IssuePattern pattern1 = new IssuePattern("org/foo/Bar*.java", "*"); IssuePattern pattern2 = new IssuePattern("org/foo/Hell?.java", "checkstyle:MagicNumber"); - when(exclusionPatternInitializer.getMulticriteriaPatterns()).thenReturn(Arrays.asList(new IssuePattern[] {pattern1, pattern2})); + when(exclusionPatternInitializer.getMulticriteriaPatterns()).thenReturn(Arrays.asList(pattern1, pattern2)); IssueExclusionsLoader loader = new IssueExclusionsLoader(exclusionPatternInitializer, ignoreIssuesFilter, mock(AnalysisWarnings.class)); DefaultInputFile file1 = TestInputFileBuilder.create("foo", "org/foo/Bar.java").build(); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/scanner/IssueExclusionsRegexpScannerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/scanner/IssueExclusionsRegexpScannerTest.java index 2fb1a6ad3c1..fd1d5689a45 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/scanner/IssueExclusionsRegexpScannerTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/scanner/IssueExclusionsRegexpScannerTest.java @@ -51,10 +51,9 @@ public class IssueExclusionsRegexpScannerTest { @Before public void init() { - blockPatterns = Arrays.asList(new DoubleRegexpMatcher[] { + blockPatterns = Arrays.asList( new DoubleRegexpMatcher(Pattern.compile("// SONAR-OFF"), Pattern.compile("// SONAR-ON")), - new DoubleRegexpMatcher(Pattern.compile("// FOO-OFF"), Pattern.compile("// FOO-ON")) - }); + new DoubleRegexpMatcher(Pattern.compile("// FOO-OFF"), Pattern.compile("// FOO-ON"))); allFilePatterns = Collections.singletonList(Pattern.compile("@SONAR-IGNORE-ALL")); javaFile = TestInputFileBuilder.create("foo", "src/Foo.java").build(); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/LogOutputRecorder.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/LogOutputRecorder.java index 3e800ab4cf7..edb245bab55 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/LogOutputRecorder.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/LogOutputRecorder.java @@ -45,7 +45,7 @@ public class LogOutputRecorder implements LogOutput { } public synchronized String getAllAsString() { - return recorded.stream().collect(Collectors.joining("\n")); + return String.join("\n", recorded); } public synchronized Collection<String> get(String level) { 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 e98f204f0d4..7531f4e93c3 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 @@ -74,7 +74,7 @@ public class CoverageMediumTest { InputFile file = result.inputFile("src/sample.xoo"); assertThat(result.coverageFor(file, 2).getHits()).isTrue(); assertThat(result.coverageFor(file, 2).getConditions()).isEqualTo(2); - assertThat(result.coverageFor(file, 2).getCoveredConditions()).isEqualTo(1); + assertThat(result.coverageFor(file, 2).getCoveredConditions()).isOne(); } @Test 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 8407a0a1ebd..ff938514e1d 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 @@ -60,7 +60,7 @@ public class GenericCoverageMediumTest { InputFile withConditions = result.inputFile("xources/hello/WithConditions.xoo"); assertThat(result.coverageFor(withConditions, 3).getHits()).isTrue(); assertThat(result.coverageFor(withConditions, 3).getConditions()).isEqualTo(2); - assertThat(result.coverageFor(withConditions, 3).getCoveredConditions()).isEqualTo(1); + assertThat(result.coverageFor(withConditions, 3).getCoveredConditions()).isOne(); assertThat(logs).noneMatch(l -> l.contains("Please use 'sonar.coverageReportPaths'")); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/cpd/CpdMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/cpd/CpdMediumTest.java index d0c29a346c3..8a0dfb0939a 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/cpd/CpdMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/cpd/CpdMediumTest.java @@ -119,7 +119,7 @@ public class CpdMediumTest { assertThat(duplicationGroupsFile1).hasSize(1); ScannerReport.Duplication cloneGroupFile1 = duplicationGroupsFile1.get(0); - assertThat(cloneGroupFile1.getOriginPosition().getStartLine()).isEqualTo(1); + assertThat(cloneGroupFile1.getOriginPosition().getStartLine()).isOne(); assertThat(cloneGroupFile1.getOriginPosition().getEndLine()).isEqualTo(17); assertThat(cloneGroupFile1.getDuplicateList()).hasSize(1); assertThat(cloneGroupFile1.getDuplicate(0).getOtherFileRef()).isEqualTo(result.getReportComponent(inputFile2).getRef()); @@ -128,7 +128,7 @@ public class CpdMediumTest { assertThat(duplicationGroupsFile2).hasSize(1); ScannerReport.Duplication cloneGroupFile2 = duplicationGroupsFile2.get(0); - assertThat(cloneGroupFile2.getOriginPosition().getStartLine()).isEqualTo(1); + assertThat(cloneGroupFile2.getOriginPosition().getStartLine()).isOne(); assertThat(cloneGroupFile2.getOriginPosition().getEndLine()).isEqualTo(17); assertThat(cloneGroupFile2.getDuplicateList()).hasSize(1); assertThat(cloneGroupFile2.getDuplicate(0).getOtherFileRef()).isEqualTo(result.getReportComponent(inputFile1).getRef()); @@ -171,7 +171,7 @@ public class CpdMediumTest { assertThat(duplicationGroupsFile1).hasSize(1); ScannerReport.Duplication cloneGroupFile1 = duplicationGroupsFile1.get(0); - assertThat(cloneGroupFile1.getOriginPosition().getStartLine()).isEqualTo(1); + assertThat(cloneGroupFile1.getOriginPosition().getStartLine()).isOne(); assertThat(cloneGroupFile1.getOriginPosition().getEndLine()).isEqualTo(17); assertThat(cloneGroupFile1.getDuplicateList()).hasSize(1); assertThat(cloneGroupFile1.getDuplicate(0).getOtherFileRef()).isEqualTo(result.getReportComponent(inputFile2).getRef()); @@ -180,7 +180,7 @@ public class CpdMediumTest { assertThat(duplicationGroupsFile2).hasSize(1); ScannerReport.Duplication cloneGroupFile2 = duplicationGroupsFile2.get(0); - assertThat(cloneGroupFile2.getOriginPosition().getStartLine()).isEqualTo(1); + assertThat(cloneGroupFile2.getOriginPosition().getStartLine()).isOne(); assertThat(cloneGroupFile2.getOriginPosition().getEndLine()).isEqualTo(17); assertThat(cloneGroupFile2.getDuplicateList()).hasSize(1); assertThat(cloneGroupFile2.getDuplicate(0).getOtherFileRef()).isEqualTo(result.getReportComponent(inputFile1).getRef()); @@ -419,9 +419,9 @@ public class CpdMediumTest { List<ScannerReport.CpdTextBlock> duplicationBlocks = result.duplicationBlocksFor(inputFile1); assertThat(duplicationBlocks).hasSize(3); - assertThat(duplicationBlocks.get(0).getStartLine()).isEqualTo(1); + assertThat(duplicationBlocks.get(0).getStartLine()).isOne(); assertThat(duplicationBlocks.get(0).getEndLine()).isEqualTo(5); - assertThat(duplicationBlocks.get(0).getStartTokenIndex()).isEqualTo(1); + assertThat(duplicationBlocks.get(0).getStartTokenIndex()).isOne(); assertThat(duplicationBlocks.get(0).getEndTokenIndex()).isEqualTo(6); assertThat(duplicationBlocks.get(0).getHash()).isNotEmpty(); @@ -463,7 +463,7 @@ public class CpdMediumTest { assertThat(duplicationGroups).hasSize(1); ScannerReport.Duplication cloneGroup = duplicationGroups.get(0); - assertThat(cloneGroup.getOriginPosition().getStartLine()).isEqualTo(1); + assertThat(cloneGroup.getOriginPosition().getStartLine()).isOne(); assertThat(cloneGroup.getOriginPosition().getEndLine()).isEqualTo(2); assertThat(cloneGroup.getDuplicateList()).hasSize(1); assertThat(cloneGroup.getDuplicate(0).getRange().getStartLine()).isEqualTo(5); 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 bfc2ad2c2ab..97f700374b3 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 @@ -174,7 +174,7 @@ public class ExternalIssuesMediumTest { assertThat(issue.getEngineId()).isEqualTo("externalXoo"); assertThat(issue.getRuleId()).isEqualTo("rule1"); assertThat(issue.getSeverity()).isEqualTo(Severity.MAJOR); - assertThat(issue.getEffort()).isEqualTo(50l); + assertThat(issue.getEffort()).isEqualTo(50L); assertThat(issue.getType()).isEqualTo(IssueType.CODE_SMELL); assertThat(issue.getTextRange().getStartLine()).isEqualTo(5); assertThat(issue.getTextRange().getEndLine()).isEqualTo(5); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/platform/DefaultServerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/platform/DefaultServerTest.java index 09c043d88d3..b6d24232ecd 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/platform/DefaultServerTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/platform/DefaultServerTest.java @@ -37,13 +37,13 @@ public class DefaultServerTest { @Test public void shouldLoadServerProperties() { - Settings settings = new MapSettings(); + MapSettings settings = new MapSettings(); settings.setProperty(CoreProperties.SERVER_ID, "123"); settings.setProperty(CoreProperties.SERVER_STARTTIME, "2010-05-18T17:59:00+0000"); DefaultScannerWsClient client = mock(DefaultScannerWsClient.class); when(client.baseUrl()).thenReturn("http://foo.com"); - DefaultServer metadata = new DefaultServer(((MapSettings) settings).asConfig(), client, + DefaultServer metadata = new DefaultServer((settings).asConfig(), client, SonarRuntimeImpl.forSonarQube(Version.parse("2.2"), SonarQubeSide.SCANNER, SonarEdition.COMMUNITY)); assertThat(metadata.getId()).isEqualTo("123"); @@ -58,10 +58,10 @@ public class DefaultServerTest { @Test public void publicRootUrl() { - Settings settings = new MapSettings(); + MapSettings settings = new MapSettings(); DefaultScannerWsClient client = mock(DefaultScannerWsClient.class); when(client.baseUrl()).thenReturn("http://foo.com/"); - DefaultServer metadata = new DefaultServer(((MapSettings) settings).asConfig(), client, null); + DefaultServer metadata = new DefaultServer(settings.asConfig(), client, null); settings.setProperty(CoreProperties.SERVER_BASE_URL, "http://server.com/"); assertThat(metadata.getPublicRootUrl()).isEqualTo("http://server.com"); @@ -72,10 +72,10 @@ public class DefaultServerTest { @Test(expected = RuntimeException.class) public void invalid_startup_date_throws_exception() { - Settings settings = new MapSettings(); + MapSettings settings = new MapSettings(); settings.setProperty(CoreProperties.SERVER_STARTTIME, "invalid"); DefaultScannerWsClient client = mock(DefaultScannerWsClient.class); - DefaultServer metadata = new DefaultServer(((MapSettings) settings).asConfig(), client, null); + DefaultServer metadata = new DefaultServer(settings.asConfig(), client, null); metadata.getStartedAt(); } } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/SourcePublisherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/SourcePublisherTest.java index d98906f463c..61a416788a7 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/SourcePublisherTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/SourcePublisherTest.java @@ -74,7 +74,7 @@ public class SourcePublisherTest { publisher.publish(writer); File out = writer.getSourceFile(inputFile.scannerId()); - assertThat(FileUtils.readFileToString(out, StandardCharsets.UTF_8)).isEqualTo(""); + assertThat(FileUtils.readFileToString(out, StandardCharsets.UTF_8)).isEmpty(); } @Test diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/DefaultProjectRepositoriesLoaderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/DefaultProjectRepositoriesLoaderTest.java index f0170b7c1a6..a8440f0b380 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/DefaultProjectRepositoriesLoaderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/DefaultProjectRepositoriesLoaderTest.java @@ -60,14 +60,14 @@ public class DefaultProjectRepositoriesLoaderTest { public void continueOnHttp404Exception() { when(wsClient.call(any(WsRequest.class))).thenThrow(new HttpException("/batch/project.protobuf?key=foo%3F", HttpURLConnection.HTTP_NOT_FOUND, "")); ProjectRepositories proj = loader.load(PROJECT_KEY, null); - assertThat(proj.exists()).isEqualTo(false); + assertThat(proj.exists()).isFalse(); } @Test(expected = IllegalStateException.class) public void failOnNonHttp404Exception() { when(wsClient.call(any(WsRequest.class))).thenThrow(IllegalStateException.class); ProjectRepositories proj = loader.load(PROJECT_KEY, null); - assertThat(proj.exists()).isEqualTo(false); + assertThat(proj.exists()).isFalse(); } @Test(expected = IllegalStateException.class) diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/ProjectRepositoriesSupplierTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/ProjectRepositoriesSupplierTest.java index b64b4099d2e..7b9085cb35e 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/ProjectRepositoriesSupplierTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/ProjectRepositoriesSupplierTest.java @@ -61,7 +61,7 @@ public class ProjectRepositoriesSupplierTest { when(loader.load(eq("key"), any())).thenReturn(project); ProjectRepositories repo = underTest.get(); - assertThat(repo.exists()).isEqualTo(true); + assertThat(repo.exists()).isTrue(); verify(props).getProjectKey(); verify(loader).load(eq("key"), eq(null)); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/settings/DefaultGlobalSettingsLoaderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/settings/DefaultGlobalSettingsLoaderTest.java index 1158cc1b802..89eec785dbc 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/settings/DefaultGlobalSettingsLoaderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/settings/DefaultGlobalSettingsLoaderTest.java @@ -65,9 +65,10 @@ public class DefaultGlobalSettingsLoaderTest { ArgumentCaptor<GetRequest> argumentCaptor = ArgumentCaptor.forClass(GetRequest.class); verify(wsClient, times(1)).call(argumentCaptor.capture()); assertThat(argumentCaptor.getValue().getPath()).isEqualTo("api/settings/values.protobuf"); - assertThat(result).isNotNull(); - assertThat(result).hasSize(2); - assertThat(result.get("abc")).isEqualTo("def"); - assertThat(result.get("123")).isEqualTo("456"); + assertThat(result) + .isNotNull() + .hasSize(2) + .containsEntry("abc", "def") + .containsEntry("123", "456"); } } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/settings/DefaultProjectSettingsLoaderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/settings/DefaultProjectSettingsLoaderTest.java index 55f9a2fae51..b50223274b1 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/settings/DefaultProjectSettingsLoaderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/settings/DefaultProjectSettingsLoaderTest.java @@ -68,9 +68,10 @@ public class DefaultProjectSettingsLoaderTest { ArgumentCaptor<GetRequest> argumentCaptor = ArgumentCaptor.forClass(GetRequest.class); verify(wsClient, times(1)).call(argumentCaptor.capture()); assertThat(argumentCaptor.getValue().getPath()).isEqualTo("api/settings/values.protobuf?component=project_key"); - assertThat(result).isNotNull(); - assertThat(result).hasSize(2); - assertThat(result.get("abc")).isEqualTo("def"); - assertThat(result.get("123")).isEqualTo("456"); + assertThat(result) + .isNotNull() + .hasSize(2) + .containsEntry("abc", "def") + .containsEntry("123", "456"); } } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/ActiveRulesProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/ActiveRulesProviderTest.java index e12a16279b1..2f82182bc34 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/ActiveRulesProviderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/ActiveRulesProviderTest.java @@ -35,7 +35,6 @@ import org.sonar.api.utils.DateUtils; import org.sonarqube.ws.Qualityprofiles.SearchWsResponse.QualityProfile; 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.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/QProfileTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/QProfileTest.java index 371f704a262..40906118d56 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/QProfileTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/QProfileTest.java @@ -33,7 +33,7 @@ public class QProfileTest { assertThat(q1) .isEqualTo(q2) .isNotEqualTo(q3) - .isNotEqualTo(null) + .isNotNull() .isNotEqualTo("str"); assertThat(q2).isNotEqualTo(q3); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorBuilderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorBuilderTest.java index 70b698132d0..24dd9983f82 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorBuilderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorBuilderTest.java @@ -97,7 +97,7 @@ public class ProjectReactorBuilderTest { ProjectDefinition rootProject = loadProjectDefinition("multi-module-repeated-id"); List<ProjectDefinition> modules = rootProject.getSubProjects(); - assertThat(modules.size()).isEqualTo(1); + assertThat(modules.size()).isOne(); // Module 1 ProjectDefinition module1 = modules.get(0); assertThat(module1.getKey()).isEqualTo("com.foo.project:module1"); @@ -231,7 +231,7 @@ public class ProjectReactorBuilderTest { public void shouldDefineMultiModuleProjectWithBaseDir() { ProjectDefinition rootProject = loadProjectDefinition("multi-module-with-basedir"); List<ProjectDefinition> modules = rootProject.getSubProjects(); - assertThat(modules.size()).isEqualTo(1); + assertThat(modules.size()).isOne(); assertThat(modules.get(0).getKey()).isEqualTo("com.foo.project:com.foo.project.module1"); } @@ -297,7 +297,7 @@ public class ProjectReactorBuilderTest { } assertThat(module11.properties().get("module1.module11.property")).isNull(); assertThat(module11.properties().get("module11.property")).isNull(); - assertThat(module11.properties().get("property")).isEqualTo("My module11 property"); + assertThat(module11.properties()).containsEntry("property", "My module11 property"); assertThat(module12.properties().get("module11.property")).isNull(); assertThat(module12.properties().get("property")).isNull(); } @@ -368,10 +368,11 @@ public class ProjectReactorBuilderTest { ProjectReactorBuilder.mergeParentProperties(childProps, parentProps); - assertThat(childProps).hasSize(4); - assertThat(childProps.get("toBeMergeProps")).isEqualTo("fooParent"); - assertThat(childProps.get("existingChildProp")).isEqualTo("barChild"); - assertThat(childProps.get("otherProp")).isEqualTo("tutuChild"); + assertThat(childProps) + .hasSize(4) + .containsEntry("toBeMergeProps", "fooParent") + .containsEntry("existingChildProp", "barChild") + .containsEntry("otherProp", "tutuChild"); assertThat(childProps.get("sonar.projectDescription")).isNull(); assertThat(childProps.get("duplicatedProp")).isSameAs(parentProps.get("duplicatedProp")); } @@ -446,13 +447,15 @@ public class ProjectReactorBuilderTest { // should be set ProjectReactorBuilder.setModuleKeyAndNameIfNotDefined(props, "foo", "parent"); - assertThat(props.get("sonar.moduleKey")).isEqualTo("parent:foo"); - assertThat(props.get("sonar.projectName")).isEqualTo("foo"); + assertThat(props) + .containsEntry("sonar.moduleKey", "parent:foo") + .containsEntry("sonar.projectName", "foo"); // but not this 2nd time ProjectReactorBuilder.setModuleKeyAndNameIfNotDefined(props, "bar", "parent"); - assertThat(props.get("sonar.moduleKey")).isEqualTo("parent:foo"); - assertThat(props.get("sonar.projectName")).isEqualTo("foo"); + assertThat(props) + .containsEntry("sonar.moduleKey", "parent:foo") + .containsEntry("sonar.projectName", "foo"); } private ProjectDefinition loadProjectDefinition(String projectFolder) { diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/InputComponentStoreTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/InputComponentStoreTest.java index ea7a911137c..341152c61c7 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/InputComponentStoreTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/InputComponentStoreTest.java @@ -20,7 +20,6 @@ package org.sonar.scanner.scan.filesystem; import java.io.File; -import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.LinkedList; import java.util.List; @@ -43,7 +42,6 @@ import org.sonar.scanner.scan.branch.BranchConfiguration; import static java.util.Optional.ofNullable; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.tuple; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/MetadataGeneratorTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/MetadataGeneratorTest.java index c25c6e40960..0f6b1216e98 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/MetadataGeneratorTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/MetadataGeneratorTest.java @@ -142,6 +142,6 @@ public class MetadataGeneratorTest { assertThat(inputFile.absolutePath()).isEqualTo(PathUtils.sanitize(srcFile.toAbsolutePath().toString())); assertThat(inputFile.key()).isEqualTo("struts:src/main/java/foo/Bar.java"); assertThat(inputFile.relativePath()).isEqualTo("src/main/java/foo/Bar.java"); - assertThat(inputFile.lines()).isEqualTo(1); + assertThat(inputFile.lines()).isOne(); } } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/util/ScannerUtilsTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/util/ScannerUtilsTest.java index 34e2309d3c6..ae494c08230 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/util/ScannerUtilsTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/util/ScannerUtilsTest.java @@ -28,8 +28,8 @@ public class ScannerUtilsTest { @Test public void encodeForUrl() { - assertThat(ScannerUtils.encodeForUrl(null)).isEqualTo(""); - assertThat(ScannerUtils.encodeForUrl("")).isEqualTo(""); + assertThat(ScannerUtils.encodeForUrl(null)).isEmpty(); + assertThat(ScannerUtils.encodeForUrl("")).isEmpty(); assertThat(ScannerUtils.encodeForUrl("foo")).isEqualTo("foo"); assertThat(ScannerUtils.encodeForUrl("foo&bar")).isEqualTo("foo%26bar"); } |