Skip to content

Commit 65c7148

Browse files
committed
test: Use infix matchers for collections to avoid explicit list creation
Make some related changes for sets / maps along the way. Signed-off-by: Sebastian Schuberth <[email protected]>
1 parent 643bfd8 commit 65c7148

File tree

31 files changed

+133
-133
lines changed

31 files changed

+133
-133
lines changed

analyzer/src/test/kotlin/PackageManagerTest.kt

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

2222
import io.kotest.core.spec.style.WordSpec
23+
import io.kotest.matchers.collections.containExactlyInAnyOrder
2324
import io.kotest.matchers.collections.shouldBeSingleton
24-
import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder
25+
import io.kotest.matchers.should
2526
import io.kotest.matchers.shouldBe
2627

2728
import org.ossreviewtoolkit.model.VcsInfo
@@ -64,7 +65,7 @@ class PackageManagerTest : WordSpec({
6465
}
6566

6667
"handle multiple authors per string" {
67-
parseAuthorString("Paul Miller (http://paulmillr.com), Elan Shanker").shouldContainExactlyInAnyOrder(
68+
parseAuthorString("Paul Miller (http://paulmillr.com), Elan Shanker") should containExactlyInAnyOrder(
6869
AuthorInfo("Paul Miller", null, "http://paulmillr.com"),
6970
AuthorInfo("Elan Shanker", null, null)
7071
)

cli/src/funTest/kotlin/ExamplesFunTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ import io.kotest.assertions.withClue
2828
import io.kotest.core.spec.style.StringSpec
2929
import io.kotest.engine.spec.tempdir
3030
import io.kotest.matchers.collections.beEmpty
31+
import io.kotest.matchers.collections.containExactlyInAnyOrder
3132
import io.kotest.matchers.collections.shouldContain
32-
import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder
3333
import io.kotest.matchers.collections.shouldHaveSize
3434
import io.kotest.matchers.nulls.shouldNotBeNull
3535
import io.kotest.matchers.should
@@ -157,7 +157,7 @@ class ExamplesFunTest : StringSpec({
157157

158158
val result = evaluator.run(script)
159159

160-
result.violations.map { it.rule } shouldContainExactlyInAnyOrder listOf(
160+
result.violations.map { it.rule } should containExactlyInAnyOrder(
161161
"COPYLEFT_LIMITED_IN_SOURCE",
162162
"DEPRECATED_SCOPE_EXCLUDE_REASON_IN_ORT_YML",
163163
"HIGH_SEVERITY_VULNERABILITY_IN_PACKAGE",

evaluator/src/test/kotlin/EvaluatorTest.kt

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

2222
import io.kotest.core.spec.style.WordSpec
2323
import io.kotest.matchers.collections.beEmpty
24+
import io.kotest.matchers.collections.containExactlyInAnyOrder
2425
import io.kotest.matchers.collections.haveSize
25-
import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder
2626
import io.kotest.matchers.should
2727
import io.kotest.matchers.shouldBe
2828

@@ -185,7 +185,7 @@ class EvaluatorTest : WordSpec({
185185

186186
val result = Evaluator(incompatibleOrtResult).run(script)
187187

188-
result.violations.map { it.message } shouldContainExactlyInAnyOrder listOf(
188+
result.violations.map { it.message } should containExactlyInAnyOrder(
189189
"The outbound license AGPL-3.0-or-later of project 'Maven:group:project-foo:1' is incompatible " +
190190
"with the inbound license AGPL-3.0-only of its dependency " +
191191
"'Maven:group:package-foo-transitive:1'. Software under a copyleft license such as the " +

model/src/test/kotlin/AbstractDependencyNavigatorTest.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import io.kotest.matchers.collections.containAll
2626
import io.kotest.matchers.collections.containExactly
2727
import io.kotest.matchers.collections.containExactlyInAnyOrder
2828
import io.kotest.matchers.collections.haveSize
29-
import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder
3029
import io.kotest.matchers.collections.shouldNotContain
3130
import io.kotest.matchers.maps.containExactly as containExactlyEntries
3231
import io.kotest.matchers.nulls.shouldNotBeNull
@@ -193,7 +192,7 @@ abstract class AbstractDependencyNavigatorTest : WordSpec() {
193192
"akka" in node.id.namespace
194193
}
195194

196-
akkaDependencies.shouldContainExactlyInAnyOrder(
195+
akkaDependencies should containExactlyInAnyOrder(
197196
Identifier("Maven:com.typesafe.akka:akka-actor_2.12:2.5.6"),
198197
Identifier("Maven:com.typesafe.akka:akka-stream_2.12:2.5.6")
199198
)

model/src/test/kotlin/OrtResultTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ package org.ossreviewtoolkit.model
2222
import io.kotest.assertions.throwables.shouldThrow
2323
import io.kotest.core.spec.style.WordSpec
2424
import io.kotest.matchers.collections.beEmpty
25+
import io.kotest.matchers.collections.containExactly
2526
import io.kotest.matchers.collections.containExactlyInAnyOrder
2627
import io.kotest.matchers.collections.haveSize
2728
import io.kotest.matchers.collections.shouldContain
28-
import io.kotest.matchers.collections.shouldContainExactly
2929
import io.kotest.matchers.collections.shouldHaveSingleElement
3030
import io.kotest.matchers.collections.shouldNotContain
3131
import io.kotest.matchers.should
@@ -368,7 +368,7 @@ class OrtResultTest : WordSpec({
368368

369369
val ruleViolations = ortResult.getRuleViolations(omitResolved = false, minSeverity = Severity.entries.min())
370370

371-
ruleViolations.map { it.rule }.shouldContainExactly("rule id")
371+
ruleViolations.map { it.rule } should containExactly("rule id")
372372
}
373373

374374
"drop violations which are resolved or below minSeverity if omitResolved is true and minSeverity is WARNING" {
@@ -419,7 +419,7 @@ class OrtResultTest : WordSpec({
419419

420420
val ruleViolations = ortResult.getRuleViolations(omitResolved = true, minSeverity = Severity.WARNING)
421421

422-
ruleViolations.map { it.rule }.shouldContainExactly("Rule violation without resolution")
422+
ruleViolations.map { it.rule } should containExactly("Rule violation without resolution")
423423
}
424424
}
425425
})

model/src/test/kotlin/ScannerRunTest.kt

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

2222
import io.kotest.core.spec.style.WordSpec
23-
import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder
23+
import io.kotest.matchers.collections.containExactlyInAnyOrder
2424
import io.kotest.matchers.nulls.shouldNotBeNull
25+
import io.kotest.matchers.should
2526

2627
import org.ossreviewtoolkit.model.FileList.Entry
2728
import org.ossreviewtoolkit.model.utils.alignRevisions
@@ -90,7 +91,7 @@ class ScannerRunTest : WordSpec({
9091
)
9192

9293
run.getFileList(id) shouldNotBeNull {
93-
files shouldContainExactlyInAnyOrder listOf(
94+
files should containExactlyInAnyOrder(
9495
Entry("vcs/path/file1.txt", "1111111111111111111111111111111111111111"),
9596
Entry("vcs/path/sub/repository/some/dir/file4.txt", "4444444444444444444444444444444444444444")
9697
)

model/src/test/kotlin/config/OrtConfigurationTest.kt

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,8 @@ import io.kotest.engine.spec.tempfile
2828
import io.kotest.extensions.system.withEnvironment
2929
import io.kotest.matchers.collections.containExactly
3030
import io.kotest.matchers.collections.containExactlyInAnyOrder
31-
import io.kotest.matchers.collections.shouldContainExactly
32-
import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder
3331
import io.kotest.matchers.maps.beEmpty
3432
import io.kotest.matchers.maps.containExactly as containExactlyEntries
35-
import io.kotest.matchers.maps.shouldContainExactly
3633
import io.kotest.matchers.nulls.beNull
3734
import io.kotest.matchers.nulls.shouldNotBeNull
3835
import io.kotest.matchers.should
@@ -63,9 +60,9 @@ class OrtConfigurationTest : WordSpec({
6360
ortConfig.forceOverwrite shouldBe true
6461

6562
with(ortConfig.licenseFilePatterns) {
66-
licenseFilenames shouldContainExactly listOf("license*")
67-
patentFilenames shouldContainExactly listOf("patents")
68-
otherLicenseFilenames shouldContainExactly listOf("readme*")
63+
licenseFilenames should containExactly("license*")
64+
patentFilenames should containExactly("patents")
65+
otherLicenseFilenames should containExactly("readme*")
6966
}
7067

7168
ortConfig.packageCurationProviders should containExactly(
@@ -109,8 +106,8 @@ class OrtConfigurationTest : WordSpec({
109106
allowDynamicVersions shouldBe true
110107
skipExcluded shouldBe true
111108

112-
enabledPackageManagers shouldContainExactlyInAnyOrder listOf("Gradle")
113-
disabledPackageManagers shouldContainExactlyInAnyOrder listOf("Maven", "NPM")
109+
enabledPackageManagers should containExactlyInAnyOrder("Gradle")
110+
disabledPackageManagers should containExactlyInAnyOrder("Maven", "NPM")
114111

115112
packageManagers shouldNotBeNull {
116113
get("Gradle") shouldNotBeNull {
@@ -119,7 +116,7 @@ class OrtConfigurationTest : WordSpec({
119116

120117
get("Yarn2") shouldNotBeNull {
121118
options shouldNotBeNull {
122-
this shouldContainExactly mapOf("disableRegistryCertificateVerification" to "false")
119+
this should containExactlyEntries("disableRegistryCertificateVerification" to "false")
123120
}
124121
}
125122

@@ -132,42 +129,42 @@ class OrtConfigurationTest : WordSpec({
132129
with(ortConfig.advisor) {
133130
config shouldNotBeNull {
134131
get("GitHubDefects") shouldNotBeNull {
135-
options shouldContainExactly mapOf(
132+
options should containExactlyEntries(
136133
"endpointUrl" to "https://api.github.com/graphql",
137134
"labelFilter" to "!duplicate, !enhancement, !invalid, !question, !documentation, *",
138135
"maxNumberOfIssuesPerRepository" to "50",
139136
"parallelRequests" to "5"
140137
)
141138

142-
secrets shouldContainExactly mapOf(
139+
secrets should containExactlyEntries(
143140
"token" to "githubAccessToken"
144141
)
145142
}
146143

147144
get("OssIndex") shouldNotBeNull {
148-
options shouldContainExactly mapOf(
145+
options should containExactlyEntries(
149146
"serverUrl" to "https://ossindex.sonatype.org/"
150147
)
151148

152-
secrets shouldContainExactly mapOf(
149+
secrets should containExactlyEntries(
153150
"username" to "username",
154151
"password" to "password"
155152
)
156153
}
157154

158155
get("OSV") shouldNotBeNull {
159-
options shouldContainExactly mapOf(
156+
options should containExactlyEntries(
160157
"serverUrl" to "https://api.osv.dev"
161158
)
162159
}
163160

164161
get("VulnerableCode") shouldNotBeNull {
165-
options shouldContainExactly mapOf(
162+
options should containExactlyEntries(
166163
"serverUrl" to "http://localhost:8000",
167164
"readTimeout" to "40"
168165
)
169166

170-
secrets shouldContainExactly mapOf(
167+
secrets should containExactlyEntries(
171168
"apiKey" to "0123456789012345678901234567890123456789"
172169
)
173170
}
@@ -210,7 +207,7 @@ class OrtConfigurationTest : WordSpec({
210207
}
211208
}
212209

213-
detectedLicenseMapping shouldContainExactly mapOf(
210+
detectedLicenseMapping should containExactlyEntries(
214211
"BSD (Three Clause License)" to "BSD-3-clause",
215212
"LicenseRef-scancode-generic-cla" to "NOASSERTION"
216213
)
@@ -242,7 +239,7 @@ class OrtConfigurationTest : WordSpec({
242239

243240
config shouldNotBeNull {
244241
get("ScanCode") shouldNotBeNull {
245-
options shouldContainExactly mapOf(
242+
options should containExactlyEntries(
246243
"commandLine" to "--copyright,--license,--info,--strip-root,--timeout,300",
247244
"commandLineNonConfig" to "--processes,4",
248245
"preferFileLicense" to "false",
@@ -255,7 +252,7 @@ class OrtConfigurationTest : WordSpec({
255252
val urlMapping = "https://my-repo.example.org(?<repoPath>.*) -> " +
256253
"ssh://my-mapped-repo.example.org\${repoPath}"
257254

258-
options shouldContainExactly mapOf(
255+
options should containExactlyEntries(
259256
"serverUrl" to "https://fossid.example.com/instance/",
260257
"projectName" to "My Project",
261258
"namingScanPattern" to "#projectName_#repositoryName_#currentTimestamp_#deltaTag_#branch",
@@ -270,20 +267,20 @@ class OrtConfigurationTest : WordSpec({
270267
"sensitivity" to "10"
271268
)
272269

273-
secrets shouldContainExactly mapOf(
270+
secrets should containExactlyEntries(
274271
"user" to "user",
275272
"apiKey" to "XYZ"
276273
)
277274
}
278275

279276
get("SCANOSS") shouldNotBeNull {
280-
options shouldContainExactly mapOf("apiUrl" to "https://api.osskb.org/")
281-
secrets shouldContainExactly mapOf("apiKey" to "your API key")
277+
options should containExactlyEntries("apiUrl" to "https://api.osskb.org/")
278+
secrets should containExactlyEntries("apiKey" to "your API key")
282279
}
283280
}
284281

285282
storages shouldNotBeNull {
286-
keys shouldContainExactlyInAnyOrder setOf(
283+
keys should containExactlyInAnyOrder(
287284
"local", "http", "aws", "clearlyDefined", "postgres", "sw360Configuration"
288285
)
289286

@@ -342,10 +339,10 @@ class OrtConfigurationTest : WordSpec({
342339
sw360Storage.token shouldBe "token"
343340
}
344341

345-
storageReaders shouldContainExactly listOf("local", "postgres", "http", "aws", "clearlyDefined")
346-
storageWriters shouldContainExactly listOf("postgres")
342+
storageReaders should containExactly("local", "postgres", "http", "aws", "clearlyDefined")
343+
storageWriters should containExactly("postgres")
347344

348-
ignorePatterns shouldContainExactly listOf("**/META-INF/DEPENDENCIES")
345+
ignorePatterns should containExactly("**/META-INF/DEPENDENCIES")
349346

350347
provenanceStorage shouldNotBeNull {
351348
fileStorage shouldNotBeNull {
@@ -374,27 +371,27 @@ class OrtConfigurationTest : WordSpec({
374371

375372
with(ortConfig.reporter) {
376373
config shouldNotBeNull {
377-
keys shouldContainExactlyInAnyOrder setOf("CycloneDx", "FossId", "CtrlXAutomation")
374+
keys should containExactlyInAnyOrder("CycloneDx", "FossId", "CtrlXAutomation")
378375

379376
get("CycloneDx") shouldNotBeNull {
380-
options shouldContainExactly mapOf(
377+
options should containExactlyEntries(
381378
"schema.version" to "1.6"
382379
)
383380
secrets should beEmpty()
384381
}
385382

386383
get("FossId") shouldNotBeNull {
387-
options shouldContainExactly mapOf(
384+
options should containExactlyEntries(
388385
"serverUrl" to "https://fossid.example.com/instance/"
389386
)
390-
secrets shouldContainExactly mapOf(
387+
secrets should containExactlyEntries(
391388
"user" to "user",
392389
"apiKey" to "XYZ"
393390
)
394391
}
395392

396393
get("CtrlXAutomation") shouldNotBeNull {
397-
options shouldContainExactly mapOf(
394+
options should containExactlyEntries(
398395
"licenseCategoriesToInclude" to "include-in-disclosure-document"
399396
)
400397
secrets should beEmpty()

model/src/test/kotlin/licenses/LicenseInfoResolverTest.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import io.kotest.matchers.collections.contain
2828
import io.kotest.matchers.collections.containExactly
2929
import io.kotest.matchers.collections.containExactlyInAnyOrder
3030
import io.kotest.matchers.collections.haveSize
31-
import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder
3231
import io.kotest.matchers.neverNullMatcher
3332
import io.kotest.matchers.nulls.shouldNotBeNull
3433
import io.kotest.matchers.should
@@ -175,7 +174,7 @@ class LicenseInfoResolverTest : WordSpec({
175174
result.licenses.find { it.license == "Apache-2.0 WITH LLVM-exception".toSpdx() } shouldNotBeNull {
176175
originalExpressions.filter {
177176
it.source == LicenseSource.DETECTED
178-
}.map { it.expression } shouldContainExactlyInAnyOrder listOf(
177+
}.map { it.expression } should containExactlyInAnyOrder(
179178
"Apache-2.0 WITH LLVM-exception".toSpdx()
180179
)
181180
}
@@ -426,7 +425,7 @@ class LicenseInfoResolverTest : WordSpec({
426425

427426
result.licenses.flatMap { resolvedLicense ->
428427
resolvedLicense.originalExpressions.filter { it.source == LicenseSource.DETECTED }
429-
} shouldContainExactlyInAnyOrder listOf(
428+
} should containExactlyInAnyOrder(
430429
ResolvedOriginalExpression("Apache-2.0".toSpdx(), LicenseSource.DETECTED, false),
431430
ResolvedOriginalExpression("MIT".toSpdx(), LicenseSource.DETECTED, true)
432431
)
@@ -482,7 +481,7 @@ class LicenseInfoResolverTest : WordSpec({
482481
)
483482
result.licenses.flatMap { resolvedLicense ->
484483
resolvedLicense.originalExpressions.map { it.expression }
485-
} shouldContainExactlyInAnyOrder listOf("MIT".toSpdx())
484+
} should containExactlyInAnyOrder("MIT".toSpdx())
486485
}
487486

488487
"contain a list of the original license expressions" {

model/src/test/kotlin/licenses/ResolvedLicenseTest.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
package org.ossreviewtoolkit.model.licenses
2121

2222
import io.kotest.core.spec.style.WordSpec
23-
import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder
23+
import io.kotest.matchers.collections.containExactlyInAnyOrder
2424
import io.kotest.matchers.collections.shouldHaveSize
25+
import io.kotest.matchers.should
2526
import io.kotest.matchers.shouldBe
2627

2728
import org.ossreviewtoolkit.model.TextLocation
@@ -53,7 +54,7 @@ class ResolvedLicenseTest : WordSpec({
5354
resolvedCopyrights shouldHaveSize 1
5455
with(resolvedCopyrights.first()) {
5556
statement shouldBe "Copyright (C) 2022 The ORT Project Authors"
56-
findings.map { it.location.path }.shouldContainExactlyInAnyOrder("/path/to/file/A", "/path/to/file/B")
57+
findings.map { it.location.path } should containExactlyInAnyOrder("/path/to/file/A", "/path/to/file/B")
5758
}
5859
}
5960

@@ -83,7 +84,7 @@ class ResolvedLicenseTest : WordSpec({
8384
resolvedCopyrights shouldHaveSize 1
8485
with(resolvedCopyrights.first()) {
8586
statement shouldBe "Copyright (C) 2022 The ORT Project Authors"
86-
findings.map { it.location.path }.shouldContainExactlyInAnyOrder("/path/to/file/A", "/path/to/file/B")
87+
findings.map { it.location.path } should containExactlyInAnyOrder("/path/to/file/A", "/path/to/file/B")
8788
}
8889
}
8990
}

model/src/test/kotlin/utils/DependencyGraphBuilderTest.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import io.kotest.core.spec.style.WordSpec
2424
import io.kotest.matchers.collections.beEmpty
2525
import io.kotest.matchers.collections.containExactly
2626
import io.kotest.matchers.collections.containExactlyInAnyOrder
27-
import io.kotest.matchers.collections.shouldContainExactly
2827
import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder
2928
import io.kotest.matchers.collections.shouldHaveSize
3029
import io.kotest.matchers.should
@@ -207,7 +206,7 @@ class DependencyGraphBuilderTest : WordSpec({
207206
.build()
208207
val scopes = graph.createScopes()
209208

210-
scopeDependencies(scopes, scope) shouldContainExactly listOf(depCyc2)
209+
scopeDependencies(scopes, scope) should containExactly(depCyc2)
211210

212211
graph.nodes shouldHaveSize 3
213212
}

0 commit comments

Comments
 (0)