Skip to content

Commit

Permalink
test: Prefer the more speaking shouldHaveSize over asserting the size
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Schuberth <[email protected]>
  • Loading branch information
sschuberth committed Oct 19, 2023
1 parent 0c92be6 commit 2b4f3ab
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 25 deletions.
4 changes: 2 additions & 2 deletions analyzer/src/funTest/kotlin/PackageManagerFunTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -150,7 +150,7 @@ class PackageManagerFunTest : WordSpec({
)
)

managedFiles.size shouldBe 3
managedFiles shouldHaveSize 3

val managedFilesByName = managedFiles.groupByName(projectDir)

Expand Down
3 changes: 2 additions & 1 deletion analyzer/src/funTest/kotlin/managers/GoDepFunTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
}
}
Expand Down
4 changes: 2 additions & 2 deletions analyzer/src/funTest/kotlin/managers/GoModFunTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -99,6 +99,6 @@ class GoModFunTest : StringSpec({

val result = create("GoMod").resolveSingleProject(definitionFile)

result.issues.size shouldBe 1
result.issues shouldHaveSize 1
}
})
3 changes: 2 additions & 1 deletion downloader/src/funTest/kotlin/DownloaderFunTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
13 changes: 7 additions & 6 deletions model/src/test/kotlin/PackageCurationTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
}
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/package-managers/pub/src/funTest/kotlin/PubFunTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -150,7 +151,7 @@ class OpossumReporterTest : WordSpec({
val signals = opossumInput.getSignalsForFile(
"/pom.xml/compile/first-package-group/[email protected]/LICENSE"
)
signals.size shouldBe 2
signals shouldHaveSize 2
signals.find { it.source == "[email protected]" } shouldNotBeNull {
license.toString() shouldBe "Apache-2.0"
}
Expand All @@ -161,7 +162,7 @@ class OpossumReporterTest : WordSpec({
"/pom.xml/compile/first-package-group/[email protected]/project-path/some/file"
)

signals.size shouldBe 2
signals shouldHaveSize 2
signals.find { it.source == "[email protected]" } shouldNotBeNull {
copyright shouldContain "Copyright 2020 Some copyright holder in source artifact"
copyright shouldContain "Copyright 2020 Some other copyright holder in source artifact"
Expand Down Expand Up @@ -212,14 +213,14 @@ class OpossumReporterTest : WordSpec({
val issuesFromFirstPackage =
opossumInput.getSignalsForFile("/pom.xml/compile/first-package-group/[email protected]")
.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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
}
}
Expand Down Expand Up @@ -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()
}

Expand Down

0 comments on commit 2b4f3ab

Please sign in to comment.