Skip to content
Permalink
Browse files

evaluator: Add a LicenseView for concluded or detected licenses

Signed-off-by: Thomas Steenbergen <thomas.steenbergen@here.com>
  • Loading branch information...
tsteenbe committed Aug 12, 2019
1 parent eab191d commit 5ddc0a99c5ec03def94ec432d92406ccf9b28ee6
Showing with 75 additions and 0 deletions.
  1. +13 −0 evaluator/src/main/kotlin/LicenseView.kt
  2. +62 −0 evaluator/src/test/kotlin/LicenseViewTest.kt
@@ -85,6 +85,19 @@ sealed class LicenseView {
}
}

/**
* Return only the concluded licenses if they exist, otherwise return detected licenses.
*/
object ConcludedOrDetected : LicenseView() {
override fun licenses(pkg: Package, detectedLicenses: List<String>): List<Pair<String, LicenseSource>> {
pkg.concludedLicense?.licenses()?.let {
return it.map { license -> Pair(license, LicenseSource.CONCLUDED) }
}

return detectedLicenses.map { Pair(it, LicenseSource.DETECTED) }
}
}

/**
* Return only the concluded licenses.
*/
@@ -208,6 +208,68 @@ class LicenseViewTest : WordSpec({
}
}

"ConcludedOrDetected" should {
"return the correct licenses" {
LicenseView.ConcludedOrDetected.licenses(
packageWithoutLicense,
emptyList()
) shouldBe emptyList()

LicenseView.ConcludedOrDetected.licenses(
packageWithoutLicense,
detectedLicenses
) shouldBe listOf(
Pair("LicenseRef-a", LicenseSource.DETECTED),
Pair("LicenseRef-b", LicenseSource.DETECTED)
)

LicenseView.ConcludedOrDetected.licenses(
packageWithOnlyConcludedLicense,
emptyList()
) shouldBe listOf(
Pair("LicenseRef-a", LicenseSource.CONCLUDED),
Pair("LicenseRef-b", LicenseSource.CONCLUDED)
)

LicenseView.ConcludedOrDetected.licenses(
packageWithOnlyConcludedLicense,
detectedLicenses
) shouldBe listOf(
Pair("LicenseRef-a", LicenseSource.CONCLUDED),
Pair("LicenseRef-b", LicenseSource.CONCLUDED)
)

LicenseView.ConcludedOrDetected.licenses(
packageWithOnlyDeclaredLicense,
emptyList()
) shouldBe emptyList()

LicenseView.ConcludedOrDetected.licenses(
packageWithOnlyDeclaredLicense,
detectedLicenses
) shouldBe listOf(
Pair("LicenseRef-a", LicenseSource.DETECTED),
Pair("LicenseRef-b", LicenseSource.DETECTED)
)

LicenseView.ConcludedOrDetected.licenses(
packageWithConcludedAndDeclaredLicense,
emptyList()
) shouldBe listOf(
Pair("LicenseRef-a", LicenseSource.CONCLUDED),
Pair("LicenseRef-b", LicenseSource.CONCLUDED)
)

LicenseView.ConcludedOrDetected.licenses(
packageWithConcludedAndDeclaredLicense,
detectedLicenses
) shouldBe listOf(
Pair("LicenseRef-a", LicenseSource.CONCLUDED),
Pair("LicenseRef-b", LicenseSource.CONCLUDED)
)
}
}

"OnlyConcluded" should {
"return only the concluded licenses" {
LicenseView.OnlyConcluded.licenses(

0 comments on commit 5ddc0a9

Please sign in to comment.
You can’t perform that action at this time.