From 2b4f3ab1686a5768d69ac4e1c5ffcf6de1f2971a Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Thu, 19 Oct 2023 16:43:41 +0200 Subject: [PATCH] test: Prefer the more speaking `shouldHaveSize` over asserting the size Signed-off-by: Sebastian Schuberth --- .../src/funTest/kotlin/PackageManagerFunTest.kt | 4 ++-- .../src/funTest/kotlin/managers/GoDepFunTest.kt | 3 ++- .../src/funTest/kotlin/managers/GoModFunTest.kt | 4 ++-- downloader/src/funTest/kotlin/DownloaderFunTest.kt | 3 ++- model/src/test/kotlin/PackageCurationTest.kt | 13 +++++++------ .../bundler/src/funTest/kotlin/BundlerFunTest.kt | 3 ++- .../composer/src/funTest/kotlin/ComposerFunTest.kt | 3 ++- .../pub/src/funTest/kotlin/PubFunTest.kt | 4 ++-- .../opossum/src/test/kotlin/OpossumReporterTest.kt | 9 +++++---- .../src/test/kotlin/ScanCodeResultParserTest.kt | 10 +++++----- 10 files changed, 31 insertions(+), 25 deletions(-) diff --git a/analyzer/src/funTest/kotlin/PackageManagerFunTest.kt b/analyzer/src/funTest/kotlin/PackageManagerFunTest.kt index 62c7e9e6cc838..d3f11b92849c5 100644 --- a/analyzer/src/funTest/kotlin/PackageManagerFunTest.kt +++ b/analyzer/src/funTest/kotlin/PackageManagerFunTest.kt @@ -27,8 +27,8 @@ import io.kotest.matchers.collections.containExactly import io.kotest.matchers.collections.containExactlyInAnyOrder import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder import io.kotest.matchers.maps.beEmpty +import io.kotest.matchers.maps.shouldHaveSize import io.kotest.matchers.should -import io.kotest.matchers.shouldBe import java.io.File @@ -150,7 +150,7 @@ class PackageManagerFunTest : WordSpec({ ) ) - managedFiles.size shouldBe 3 + managedFiles shouldHaveSize 3 val managedFilesByName = managedFiles.groupByName(projectDir) diff --git a/analyzer/src/funTest/kotlin/managers/GoDepFunTest.kt b/analyzer/src/funTest/kotlin/managers/GoDepFunTest.kt index 4abecb3e3694c..76b4d8b5aeaea 100644 --- a/analyzer/src/funTest/kotlin/managers/GoDepFunTest.kt +++ b/analyzer/src/funTest/kotlin/managers/GoDepFunTest.kt @@ -21,6 +21,7 @@ package org.ossreviewtoolkit.analyzer.managers import io.kotest.core.spec.style.WordSpec import io.kotest.matchers.collections.beEmpty +import io.kotest.matchers.collections.shouldHaveSize import io.kotest.matchers.should import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldNotBe @@ -57,7 +58,7 @@ class GoDepFunTest : WordSpec({ project.definitionFilePath shouldBe "analyzer/src/funTest/assets/projects/synthetic/godep/no-lockfile/Gopkg.toml" packages should beEmpty() - issues.size shouldBe 1 + issues shouldHaveSize 1 issues.first().message should haveSubstring("IllegalArgumentException: No lockfile found in") } } diff --git a/analyzer/src/funTest/kotlin/managers/GoModFunTest.kt b/analyzer/src/funTest/kotlin/managers/GoModFunTest.kt index e79e598c49a81..fc980cbcb083a 100644 --- a/analyzer/src/funTest/kotlin/managers/GoModFunTest.kt +++ b/analyzer/src/funTest/kotlin/managers/GoModFunTest.kt @@ -20,8 +20,8 @@ package org.ossreviewtoolkit.analyzer.managers import io.kotest.core.spec.style.StringSpec +import io.kotest.matchers.collections.shouldHaveSize import io.kotest.matchers.should -import io.kotest.matchers.shouldBe import org.ossreviewtoolkit.model.toYaml import org.ossreviewtoolkit.utils.test.getAssetFile @@ -99,6 +99,6 @@ class GoModFunTest : StringSpec({ val result = create("GoMod").resolveSingleProject(definitionFile) - result.issues.size shouldBe 1 + result.issues shouldHaveSize 1 } }) diff --git a/downloader/src/funTest/kotlin/DownloaderFunTest.kt b/downloader/src/funTest/kotlin/DownloaderFunTest.kt index 3f0cb245240fa..4f19197e6e009 100644 --- a/downloader/src/funTest/kotlin/DownloaderFunTest.kt +++ b/downloader/src/funTest/kotlin/DownloaderFunTest.kt @@ -22,6 +22,7 @@ package org.ossreviewtoolkit.downloader import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.WordSpec import io.kotest.engine.spec.tempdir +import io.kotest.matchers.collections.shouldHaveSize import io.kotest.matchers.file.aFile import io.kotest.matchers.should import io.kotest.matchers.shouldBe @@ -177,7 +178,7 @@ class DownloaderFunTest : WordSpec({ Downloader(DownloaderConfiguration()).download(pkg, outputDir) } - exception.suppressed.size shouldBe 2 + exception.suppressed shouldHaveSize 2 exception.suppressed[0]!!.message shouldBe "No VCS URL provided for 'Maven:junit:junit:4.12'. " + "Please define the \"connection\" tag within the \"scm\" tag in the POM file, " + "see: https://maven.apache.org/pom.html#SCM" diff --git a/model/src/test/kotlin/PackageCurationTest.kt b/model/src/test/kotlin/PackageCurationTest.kt index 8edc4142727d2..70e7883c99258 100644 --- a/model/src/test/kotlin/PackageCurationTest.kt +++ b/model/src/test/kotlin/PackageCurationTest.kt @@ -23,6 +23,7 @@ import io.kotest.assertions.assertSoftly import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.WordSpec import io.kotest.matchers.collections.containExactly +import io.kotest.matchers.collections.shouldHaveSize import io.kotest.matchers.maps.beEmpty import io.kotest.matchers.maps.shouldContainExactly import io.kotest.matchers.should @@ -101,7 +102,7 @@ class PackageCurationTest : WordSpec({ isModified shouldBe true } - curatedPkg.curations.size shouldBe 1 + curatedPkg.curations shouldHaveSize 1 curatedPkg.curations.first().base shouldBe pkg.diff(curatedPkg.metadata) curatedPkg.curations.first().curation shouldBe curation.data } @@ -164,7 +165,7 @@ class PackageCurationTest : WordSpec({ isModified shouldBe false } - curatedPkg.curations.size shouldBe 1 + curatedPkg.curations shouldHaveSize 1 curatedPkg.curations.first().base shouldBe pkg.diff(curatedPkg.metadata) curatedPkg.curations.first().curation shouldBe curation.data } @@ -205,7 +206,7 @@ class PackageCurationTest : WordSpec({ val curatedPkg = curation.apply(pkg.toCuratedPackage()) - curatedPkg.curations.size shouldBe 1 + curatedPkg.curations shouldHaveSize 1 curatedPkg.metadata.vcsProcessed shouldBe VcsInfo.EMPTY } @@ -350,19 +351,19 @@ class PackageCurationTest : WordSpec({ val result3 = curation3.apply(result2) result1.metadata.description shouldBe "description 1" - result1.curations.size shouldBe 1 + result1.curations shouldHaveSize 1 result1.curations[0].base shouldBe PackageCurationData(description = "") result1.curations[0].curation shouldBe curation1.data result2.metadata.description shouldBe "description 2" - result2.curations.size shouldBe 2 + result2.curations shouldHaveSize 2 result2.curations[0].base shouldBe PackageCurationData(description = "") result2.curations[0].curation shouldBe curation1.data result2.curations[1].base shouldBe PackageCurationData(description = "description 1") result2.curations[1].curation shouldBe curation2.data result3.metadata.description shouldBe "description 3" - result3.curations.size shouldBe 3 + result3.curations shouldHaveSize 3 result3.curations[0].base shouldBe PackageCurationData(description = "") result3.curations[0].curation shouldBe curation1.data result3.curations[1].base shouldBe PackageCurationData(description = "description 1") diff --git a/plugins/package-managers/bundler/src/funTest/kotlin/BundlerFunTest.kt b/plugins/package-managers/bundler/src/funTest/kotlin/BundlerFunTest.kt index 5b99588ea6723..ac24c337dd661 100644 --- a/plugins/package-managers/bundler/src/funTest/kotlin/BundlerFunTest.kt +++ b/plugins/package-managers/bundler/src/funTest/kotlin/BundlerFunTest.kt @@ -21,6 +21,7 @@ package org.ossreviewtoolkit.plugins.packagemanagers.bundler import io.kotest.core.spec.style.WordSpec import io.kotest.matchers.collections.beEmpty +import io.kotest.matchers.collections.shouldHaveSize import io.kotest.matchers.should import io.kotest.matchers.shouldBe import io.kotest.matchers.string.haveSubstring @@ -53,7 +54,7 @@ class BundlerFunTest : WordSpec({ project.definitionFilePath shouldBe "plugins/package-managers/bundler/src/funTest/assets/projects/synthetic/no-lockfile/Gemfile" packages should beEmpty() - issues.size shouldBe 1 + issues shouldHaveSize 1 issues.first().message should haveSubstring("IllegalArgumentException: No lockfile found in") } } diff --git a/plugins/package-managers/composer/src/funTest/kotlin/ComposerFunTest.kt b/plugins/package-managers/composer/src/funTest/kotlin/ComposerFunTest.kt index ab231aae7ba6b..69010df7c31d9 100644 --- a/plugins/package-managers/composer/src/funTest/kotlin/ComposerFunTest.kt +++ b/plugins/package-managers/composer/src/funTest/kotlin/ComposerFunTest.kt @@ -21,6 +21,7 @@ package org.ossreviewtoolkit.plugins.packagemanagers.composer import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.collections.beEmpty +import io.kotest.matchers.collections.shouldHaveSize import io.kotest.matchers.should import io.kotest.matchers.shouldBe import io.kotest.matchers.string.haveSubstring @@ -53,7 +54,7 @@ class ComposerFunTest : StringSpec({ project.definitionFilePath shouldBe "plugins/package-managers/composer/src/funTest/assets/projects/" + "synthetic/no-lockfile/composer.json" packages should beEmpty() - issues.size shouldBe 1 + issues shouldHaveSize 1 issues.first().message should haveSubstring("IllegalArgumentException: No lockfile found in") } } diff --git a/plugins/package-managers/pub/src/funTest/kotlin/PubFunTest.kt b/plugins/package-managers/pub/src/funTest/kotlin/PubFunTest.kt index 5792b7f70e603..487eb6a802fa7 100644 --- a/plugins/package-managers/pub/src/funTest/kotlin/PubFunTest.kt +++ b/plugins/package-managers/pub/src/funTest/kotlin/PubFunTest.kt @@ -21,8 +21,8 @@ package org.ossreviewtoolkit.plugins.packagemanagers.pub import io.kotest.core.spec.style.WordSpec import io.kotest.matchers.collections.beEmpty +import io.kotest.matchers.collections.shouldHaveSize import io.kotest.matchers.should -import io.kotest.matchers.shouldBe import io.kotest.matchers.string.haveSubstring import org.ossreviewtoolkit.analyzer.managers.analyze @@ -99,7 +99,7 @@ class PubFunTest : WordSpec({ with(result) { packages should beEmpty() - issues.size shouldBe 1 + issues shouldHaveSize 1 issues.first().message should haveSubstring("IllegalArgumentException: No lockfile found in") } } diff --git a/plugins/reporters/opossum/src/test/kotlin/OpossumReporterTest.kt b/plugins/reporters/opossum/src/test/kotlin/OpossumReporterTest.kt index 495edb5f03c5a..f7cfdfb3e5cd7 100644 --- a/plugins/reporters/opossum/src/test/kotlin/OpossumReporterTest.kt +++ b/plugins/reporters/opossum/src/test/kotlin/OpossumReporterTest.kt @@ -23,6 +23,7 @@ import io.kotest.core.spec.style.WordSpec import io.kotest.inspectors.forAll import io.kotest.matchers.collections.containExactlyInAnyOrder import io.kotest.matchers.collections.shouldContain +import io.kotest.matchers.collections.shouldHaveSize import io.kotest.matchers.collections.shouldNotContain import io.kotest.matchers.nulls.beNull import io.kotest.matchers.should @@ -150,7 +151,7 @@ class OpossumReporterTest : WordSpec({ val signals = opossumInput.getSignalsForFile( "/pom.xml/compile/first-package-group/first-package@0.0.1/LICENSE" ) - signals.size shouldBe 2 + signals shouldHaveSize 2 signals.find { it.source == "ORT-Scanner-SCANNER@1.2.3" } shouldNotBeNull { license.toString() shouldBe "Apache-2.0" } @@ -161,7 +162,7 @@ class OpossumReporterTest : WordSpec({ "/pom.xml/compile/first-package-group/first-package@0.0.1/project-path/some/file" ) - signals.size shouldBe 2 + signals shouldHaveSize 2 signals.find { it.source == "ORT-Scanner-SCANNER@1.2.3" } shouldNotBeNull { copyright shouldContain "Copyright 2020 Some copyright holder in source artifact" copyright shouldContain "Copyright 2020 Some other copyright holder in source artifact" @@ -212,14 +213,14 @@ class OpossumReporterTest : WordSpec({ val issuesFromFirstPackage = opossumInput.getSignalsForFile("/pom.xml/compile/first-package-group/first-package@0.0.1") .filter { it.comment?.contains(Regex("Source-.*Message-")) == true } - issuesFromFirstPackage.size shouldBe 4 + issuesFromFirstPackage shouldHaveSize 4 issuesFromFirstPackage.forAll { it.followUp shouldBe true it.excludeFromNotice shouldBe true } val issuesAttachedToFallbackPath = opossumInput.getSignalsForFile("/") - issuesAttachedToFallbackPath.size shouldBe 1 + issuesAttachedToFallbackPath shouldHaveSize 1 issuesAttachedToFallbackPath.forAll { it.followUp shouldBe true it.excludeFromNotice shouldBe true diff --git a/plugins/scanners/scancode/src/test/kotlin/ScanCodeResultParserTest.kt b/plugins/scanners/scancode/src/test/kotlin/ScanCodeResultParserTest.kt index 1aa4bce24cc29..8da9d5436c442 100644 --- a/plugins/scanners/scancode/src/test/kotlin/ScanCodeResultParserTest.kt +++ b/plugins/scanners/scancode/src/test/kotlin/ScanCodeResultParserTest.kt @@ -24,8 +24,8 @@ import io.kotest.matchers.Matcher import io.kotest.matchers.collections.beEmpty import io.kotest.matchers.collections.containExactlyInAnyOrder import io.kotest.matchers.collections.shouldHaveSingleElement +import io.kotest.matchers.collections.shouldHaveSize import io.kotest.matchers.should -import io.kotest.matchers.shouldBe import java.io.File import java.time.Instant @@ -45,8 +45,8 @@ class ScanCodeResultParserTest : FreeSpec({ val summary = parseResult(resultFile).toScanSummary() - summary.licenseFindings.size shouldBe 4 - summary.copyrightFindings.size shouldBe 4 + summary.licenseFindings shouldHaveSize 4 + summary.copyrightFindings shouldHaveSize 4 summary.issues should beEmpty() } } @@ -80,8 +80,8 @@ class ScanCodeResultParserTest : FreeSpec({ val summary = parseResult(resultFile).toScanSummary() - summary.licenseFindings.size shouldBe 5 - summary.copyrightFindings.size shouldBe 4 + summary.licenseFindings shouldHaveSize 5 + summary.copyrightFindings shouldHaveSize 4 summary.issues should beEmpty() }