Skip to content

Commit 7c0b17f

Browse files
committed
test: Prefer the more speaking shouldHaveSize over asserting the size
Signed-off-by: Sebastian Schuberth <[email protected]>
1 parent 0c92be6 commit 7c0b17f

File tree

10 files changed

+31
-25
lines changed

10 files changed

+31
-25
lines changed

analyzer/src/funTest/kotlin/PackageManagerFunTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ import io.kotest.matchers.collections.containExactly
2727
import io.kotest.matchers.collections.containExactlyInAnyOrder
2828
import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder
2929
import io.kotest.matchers.maps.beEmpty
30+
import io.kotest.matchers.maps.shouldHaveSize
3031
import io.kotest.matchers.should
31-
import io.kotest.matchers.shouldBe
3232

3333
import java.io.File
3434

@@ -150,7 +150,7 @@ class PackageManagerFunTest : WordSpec({
150150
)
151151
)
152152

153-
managedFiles.size shouldBe 3
153+
managedFiles shouldHaveSize 3
154154

155155
val managedFilesByName = managedFiles.groupByName(projectDir)
156156

analyzer/src/funTest/kotlin/managers/GoDepFunTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ package org.ossreviewtoolkit.analyzer.managers
2121

2222
import io.kotest.core.spec.style.WordSpec
2323
import io.kotest.matchers.collections.beEmpty
24+
import io.kotest.matchers.collections.shouldHaveSize
2425
import io.kotest.matchers.should
2526
import io.kotest.matchers.shouldBe
2627
import io.kotest.matchers.shouldNotBe
@@ -57,7 +58,7 @@ class GoDepFunTest : WordSpec({
5758
project.definitionFilePath shouldBe
5859
"analyzer/src/funTest/assets/projects/synthetic/godep/no-lockfile/Gopkg.toml"
5960
packages should beEmpty()
60-
issues.size shouldBe 1
61+
issues shouldHaveSize 1
6162
issues.first().message should haveSubstring("IllegalArgumentException: No lockfile found in")
6263
}
6364
}

analyzer/src/funTest/kotlin/managers/GoModFunTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
package org.ossreviewtoolkit.analyzer.managers
2121

2222
import io.kotest.core.spec.style.StringSpec
23+
import io.kotest.matchers.collections.shouldHaveSize
2324
import io.kotest.matchers.should
24-
import io.kotest.matchers.shouldBe
2525

2626
import org.ossreviewtoolkit.model.toYaml
2727
import org.ossreviewtoolkit.utils.test.getAssetFile
@@ -99,6 +99,6 @@ class GoModFunTest : StringSpec({
9999

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

102-
result.issues.size shouldBe 1
102+
result.issues shouldHaveSize 1
103103
}
104104
})

downloader/src/funTest/kotlin/DownloaderFunTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ package org.ossreviewtoolkit.downloader
2222
import io.kotest.assertions.throwables.shouldThrow
2323
import io.kotest.core.spec.style.WordSpec
2424
import io.kotest.engine.spec.tempdir
25+
import io.kotest.matchers.collections.shouldHaveSize
2526
import io.kotest.matchers.file.aFile
2627
import io.kotest.matchers.should
2728
import io.kotest.matchers.shouldBe
@@ -177,7 +178,7 @@ class DownloaderFunTest : WordSpec({
177178
Downloader(DownloaderConfiguration()).download(pkg, outputDir)
178179
}
179180

180-
exception.suppressed.size shouldBe 2
181+
exception.suppressed shouldHaveSize 2
181182
exception.suppressed[0]!!.message shouldBe "No VCS URL provided for 'Maven:junit:junit:4.12'. " +
182183
"Please define the \"connection\" tag within the \"scm\" tag in the POM file, " +
183184
"see: https://maven.apache.org/pom.html#SCM"

model/src/test/kotlin/PackageCurationTest.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import io.kotest.assertions.assertSoftly
2323
import io.kotest.assertions.throwables.shouldThrow
2424
import io.kotest.core.spec.style.WordSpec
2525
import io.kotest.matchers.collections.containExactly
26+
import io.kotest.matchers.collections.shouldHaveSize
2627
import io.kotest.matchers.maps.beEmpty
2728
import io.kotest.matchers.maps.shouldContainExactly
2829
import io.kotest.matchers.should
@@ -101,7 +102,7 @@ class PackageCurationTest : WordSpec({
101102
isModified shouldBe true
102103
}
103104

104-
curatedPkg.curations.size shouldBe 1
105+
curatedPkg.curations shouldHaveSize 1
105106
curatedPkg.curations.first().base shouldBe pkg.diff(curatedPkg.metadata)
106107
curatedPkg.curations.first().curation shouldBe curation.data
107108
}
@@ -164,7 +165,7 @@ class PackageCurationTest : WordSpec({
164165
isModified shouldBe false
165166
}
166167

167-
curatedPkg.curations.size shouldBe 1
168+
curatedPkg.curations shouldHaveSize 1
168169
curatedPkg.curations.first().base shouldBe pkg.diff(curatedPkg.metadata)
169170
curatedPkg.curations.first().curation shouldBe curation.data
170171
}
@@ -205,7 +206,7 @@ class PackageCurationTest : WordSpec({
205206

206207
val curatedPkg = curation.apply(pkg.toCuratedPackage())
207208

208-
curatedPkg.curations.size shouldBe 1
209+
curatedPkg.curations shouldHaveSize 1
209210
curatedPkg.metadata.vcsProcessed shouldBe VcsInfo.EMPTY
210211
}
211212

@@ -350,19 +351,19 @@ class PackageCurationTest : WordSpec({
350351
val result3 = curation3.apply(result2)
351352

352353
result1.metadata.description shouldBe "description 1"
353-
result1.curations.size shouldBe 1
354+
result1.curations shouldHaveSize 1
354355
result1.curations[0].base shouldBe PackageCurationData(description = "")
355356
result1.curations[0].curation shouldBe curation1.data
356357

357358
result2.metadata.description shouldBe "description 2"
358-
result2.curations.size shouldBe 2
359+
result2.curations shouldHaveSize 2
359360
result2.curations[0].base shouldBe PackageCurationData(description = "")
360361
result2.curations[0].curation shouldBe curation1.data
361362
result2.curations[1].base shouldBe PackageCurationData(description = "description 1")
362363
result2.curations[1].curation shouldBe curation2.data
363364

364365
result3.metadata.description shouldBe "description 3"
365-
result3.curations.size shouldBe 3
366+
result3.curations shouldHaveSize 3
366367
result3.curations[0].base shouldBe PackageCurationData(description = "")
367368
result3.curations[0].curation shouldBe curation1.data
368369
result3.curations[1].base shouldBe PackageCurationData(description = "description 1")

plugins/package-managers/bundler/src/funTest/kotlin/BundlerFunTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ package org.ossreviewtoolkit.plugins.packagemanagers.bundler
2121

2222
import io.kotest.core.spec.style.WordSpec
2323
import io.kotest.matchers.collections.beEmpty
24+
import io.kotest.matchers.collections.shouldHaveSize
2425
import io.kotest.matchers.should
2526
import io.kotest.matchers.shouldBe
2627
import io.kotest.matchers.string.haveSubstring
@@ -53,7 +54,7 @@ class BundlerFunTest : WordSpec({
5354
project.definitionFilePath shouldBe
5455
"plugins/package-managers/bundler/src/funTest/assets/projects/synthetic/no-lockfile/Gemfile"
5556
packages should beEmpty()
56-
issues.size shouldBe 1
57+
issues shouldHaveSize 1
5758
issues.first().message should haveSubstring("IllegalArgumentException: No lockfile found in")
5859
}
5960
}

plugins/package-managers/composer/src/funTest/kotlin/ComposerFunTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ package org.ossreviewtoolkit.plugins.packagemanagers.composer
2121

2222
import io.kotest.core.spec.style.StringSpec
2323
import io.kotest.matchers.collections.beEmpty
24+
import io.kotest.matchers.collections.shouldHaveSize
2425
import io.kotest.matchers.should
2526
import io.kotest.matchers.shouldBe
2627
import io.kotest.matchers.string.haveSubstring
@@ -53,7 +54,7 @@ class ComposerFunTest : StringSpec({
5354
project.definitionFilePath shouldBe "plugins/package-managers/composer/src/funTest/assets/projects/" +
5455
"synthetic/no-lockfile/composer.json"
5556
packages should beEmpty()
56-
issues.size shouldBe 1
57+
issues shouldHaveSize 1
5758
issues.first().message should haveSubstring("IllegalArgumentException: No lockfile found in")
5859
}
5960
}

plugins/package-managers/pub/src/funTest/kotlin/PubFunTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ package org.ossreviewtoolkit.plugins.packagemanagers.pub
2121

2222
import io.kotest.core.spec.style.WordSpec
2323
import io.kotest.matchers.collections.beEmpty
24+
import io.kotest.matchers.collections.shouldHaveSize
2425
import io.kotest.matchers.should
25-
import io.kotest.matchers.shouldBe
2626
import io.kotest.matchers.string.haveSubstring
2727

2828
import org.ossreviewtoolkit.analyzer.managers.analyze
@@ -99,7 +99,7 @@ class PubFunTest : WordSpec({
9999

100100
with(result) {
101101
packages should beEmpty()
102-
issues.size shouldBe 1
102+
issues shouldHaveSize 1
103103
issues.first().message should haveSubstring("IllegalArgumentException: No lockfile found in")
104104
}
105105
}

plugins/reporters/opossum/src/test/kotlin/OpossumReporterTest.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import io.kotest.core.spec.style.WordSpec
2323
import io.kotest.inspectors.forAll
2424
import io.kotest.matchers.collections.containExactlyInAnyOrder
2525
import io.kotest.matchers.collections.shouldContain
26+
import io.kotest.matchers.collections.shouldHaveSize
2627
import io.kotest.matchers.collections.shouldNotContain
2728
import io.kotest.matchers.nulls.beNull
2829
import io.kotest.matchers.should
@@ -150,7 +151,7 @@ class OpossumReporterTest : WordSpec({
150151
val signals = opossumInput.getSignalsForFile(
151152
"/pom.xml/compile/first-package-group/[email protected]/LICENSE"
152153
)
153-
signals.size shouldBe 2
154+
signals shouldHaveSize 2
154155
signals.find { it.source == "[email protected]" } shouldNotBeNull {
155156
license.toString() shouldBe "Apache-2.0"
156157
}
@@ -161,7 +162,7 @@ class OpossumReporterTest : WordSpec({
161162
"/pom.xml/compile/first-package-group/[email protected]/project-path/some/file"
162163
)
163164

164-
signals.size shouldBe 2
165+
signals shouldHaveSize 2
165166
signals.find { it.source == "[email protected]" } shouldNotBeNull {
166167
copyright shouldContain "Copyright 2020 Some copyright holder in source artifact"
167168
copyright shouldContain "Copyright 2020 Some other copyright holder in source artifact"
@@ -212,14 +213,14 @@ class OpossumReporterTest : WordSpec({
212213
val issuesFromFirstPackage =
213214
opossumInput.getSignalsForFile("/pom.xml/compile/first-package-group/[email protected]")
214215
.filter { it.comment?.contains(Regex("Source-.*Message-")) == true }
215-
issuesFromFirstPackage.size shouldBe 4
216+
issuesFromFirstPackage shouldHaveSize 4
216217
issuesFromFirstPackage.forAll {
217218
it.followUp shouldBe true
218219
it.excludeFromNotice shouldBe true
219220
}
220221

221222
val issuesAttachedToFallbackPath = opossumInput.getSignalsForFile("/")
222-
issuesAttachedToFallbackPath.size shouldBe 1
223+
issuesAttachedToFallbackPath shouldHaveSize 1
223224
issuesAttachedToFallbackPath.forAll {
224225
it.followUp shouldBe true
225226
it.excludeFromNotice shouldBe true

plugins/scanners/scancode/src/test/kotlin/ScanCodeResultParserTest.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import io.kotest.matchers.Matcher
2424
import io.kotest.matchers.collections.beEmpty
2525
import io.kotest.matchers.collections.containExactlyInAnyOrder
2626
import io.kotest.matchers.collections.shouldHaveSingleElement
27+
import io.kotest.matchers.collections.shouldHaveSize
2728
import io.kotest.matchers.should
28-
import io.kotest.matchers.shouldBe
2929

3030
import java.io.File
3131
import java.time.Instant
@@ -45,8 +45,8 @@ class ScanCodeResultParserTest : FreeSpec({
4545

4646
val summary = parseResult(resultFile).toScanSummary()
4747

48-
summary.licenseFindings.size shouldBe 4
49-
summary.copyrightFindings.size shouldBe 4
48+
summary.licenseFindings shouldHaveSize 4
49+
summary.copyrightFindings shouldHaveSize 4
5050
summary.issues should beEmpty()
5151
}
5252
}
@@ -80,8 +80,8 @@ class ScanCodeResultParserTest : FreeSpec({
8080

8181
val summary = parseResult(resultFile).toScanSummary()
8282

83-
summary.licenseFindings.size shouldBe 5
84-
summary.copyrightFindings.size shouldBe 4
83+
summary.licenseFindings shouldHaveSize 5
84+
summary.copyrightFindings shouldHaveSize 4
8585
summary.issues should beEmpty()
8686
}
8787

0 commit comments

Comments
 (0)