Skip to content

Commit

Permalink
LicenseInfoResolverTest: Rewrite code to get rid of an extension func…
Browse files Browse the repository at this point in the history
…tion

SimpleLicenseInfoProvider is only ever used with a List of LicenseInfo,
so simply create the map internally to get rid of the private extension
function.

Signed-off-by: Sebastian Schuberth <sebastian.schuberth@bosch.io>
  • Loading branch information
sschuberth committed Nov 24, 2020
1 parent 8b0f23f commit 5b61274
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions model/src/test/kotlin/licenses/LicenseInfoResolverTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ class LicenseInfoResolverTest : WordSpec() {
copyrightGarbage: Set<String> = emptySet(),
archiver: FileArchiver = FileArchiver.DEFAULT
) = LicenseInfoResolver(
data.toProvider(),
SimpleLicenseInfoProvider(data),
CopyrightGarbage(copyrightGarbage.toSortedSet()),
archiver
)
Expand Down Expand Up @@ -549,13 +549,13 @@ class LicenseInfoResolverTest : WordSpec() {
)
}

private class SimpleLicenseInfoProvider(val licenseInfo: Map<Identifier, LicenseInfo>) : LicenseInfoProvider {
private class SimpleLicenseInfoProvider(licenseInfo: List<LicenseInfo>) : LicenseInfoProvider {
private val licenseInfoById = licenseInfo.associateBy { it.id }

override fun get(id: Identifier) =
licenseInfo[id] ?: throw IllegalArgumentException("No license info for '${id.toCoordinates()}' available.")
licenseInfoById[id] ?: throw IllegalArgumentException("No license info for '${id.toCoordinates()}' available.")
}

private fun List<LicenseInfo>.toProvider() = SimpleLicenseInfoProvider(associateBy { it.id })

private fun Map<String, List<TextLocation>>.toFindingsSet(): Set<LicenseFinding> =
flatMap { (license, locations) ->
locations.map { LicenseFinding(license, it) }
Expand Down

0 comments on commit 5b61274

Please sign in to comment.