@@ -31,112 +31,110 @@ import org.ossreviewtoolkit.utils.spdx.SpdxLicenseChoice
31
31
import org.ossreviewtoolkit.utils.spdx.SpdxSingleLicenseExpression
32
32
import org.ossreviewtoolkit.utils.spdx.toSpdx
33
33
34
- class ResolvedLicenseInfoTest : WordSpec () {
35
- init {
36
- " effectiveLicense()" should {
37
- " apply choices for LicenseView.ALL on all resolved licenses" {
38
- // All: (Apache-2.0 WITH LLVM-exception OR MIT) AND (MIT OR GPL-2.0-only) AND (0BSD OR GPL-2.0-only)
39
- val choices = listOf (
40
- SpdxLicenseChoice (" $APACHE OR $MIT " .toSpdx(), MIT .toSpdx()),
41
- SpdxLicenseChoice (" $MIT OR $GPL " .toSpdx(), MIT .toSpdx()),
42
- SpdxLicenseChoice (" $BSD OR $GPL " .toSpdx(), BSD .toSpdx())
43
- )
44
-
45
- val effectiveLicense = RESOLVED_LICENSE_INFO .effectiveLicense(LicenseView .ALL , choices)
46
-
47
- effectiveLicense shouldBe " $MIT AND $BSD " .toSpdx()
48
- }
49
-
50
- " apply a choice for a sub-expression only" {
51
- // Declared: Apache-2.0 WITH LLVM-exception OR MIT OR GPL-2.0-only
52
- val resolvedLicenseInfo = ResolvedLicenseInfo (
53
- id = Identifier .EMPTY ,
54
- licenseInfo = mockk(),
55
- licenses = listOf (
56
- ResolvedLicense (
57
- license = APACHE .toSpdx() as SpdxSingleLicenseExpression ,
58
- originalDeclaredLicenses = setOf (" $APACHE OR $MIT " ),
59
- originalExpressions = setOf (
60
- ResolvedOriginalExpression (" $APACHE OR $MIT OR $GPL " .toSpdx(), LicenseSource .DECLARED )
61
- ),
62
- locations = emptySet()
63
- )
64
- ),
65
- copyrightGarbage = emptyMap(),
66
- unmatchedCopyrights = emptyMap()
67
- )
68
-
69
- val choices = listOf (
70
- SpdxLicenseChoice (" $APACHE OR $MIT " .toSpdx(), MIT .toSpdx())
71
- )
72
-
73
- val effectiveLicense = resolvedLicenseInfo.effectiveLicense(LicenseView .ONLY_DECLARED , choices)
74
-
75
- effectiveLicense shouldBe " $MIT OR $GPL " .toSpdx()
76
- }
77
-
78
- " apply choices for LicenseView.CONCLUDED_OR_DECLARED_AND_DETECTED" {
79
- // Concluded: 0BSD OR GPL-2.0-only
80
- val choices = listOf (
81
- SpdxLicenseChoice (" $BSD OR $GPL " .toSpdx(), BSD .toSpdx())
82
- )
83
-
84
- val effectiveLicense = RESOLVED_LICENSE_INFO .effectiveLicense(
85
- LicenseView .CONCLUDED_OR_DECLARED_AND_DETECTED ,
86
- choices
87
- )
88
-
89
- effectiveLicense shouldBe BSD .toSpdx()
90
- }
91
-
92
- " apply choices for LicenseView.ONLY_DECLARED" {
93
- // Declared: Apache-2.0 WITH LLVM-exception OR MIT
94
- val choices = listOf (
95
- SpdxLicenseChoice (" $APACHE OR $MIT " .toSpdx(), MIT .toSpdx())
96
- )
97
-
98
- val effectiveLicense = RESOLVED_LICENSE_INFO .effectiveLicense(
99
- LicenseView .ONLY_DECLARED ,
100
- choices
101
- )
102
-
103
- effectiveLicense shouldBe MIT .toSpdx()
104
- }
105
-
106
- " apply package and repository license choice for LicenseView.ONLY_CONCLUDED in the correct order" {
107
- val repositoryChoices = listOf (
108
- SpdxLicenseChoice (" $APACHE OR $MIT " .toSpdx(), MIT .toSpdx()),
109
- SpdxLicenseChoice (" $BSD OR $GPL " .toSpdx(), BSD .toSpdx())
110
- )
111
- val packageChoices = listOf (
112
- SpdxLicenseChoice (" $APACHE OR $MIT " .toSpdx(), APACHE .toSpdx())
113
- )
114
-
115
- val effectiveLicense = RESOLVED_LICENSE_INFO .effectiveLicense(
116
- LicenseView .ALL ,
117
- packageChoices,
118
- repositoryChoices
119
- )
120
-
121
- effectiveLicense shouldBe " $APACHE and ($MIT or $GPL ) and $BSD " .toSpdx()
122
- }
34
+ class ResolvedLicenseInfoTest : WordSpec ({
35
+ " effectiveLicense()" should {
36
+ " apply choices for LicenseView.ALL on all resolved licenses" {
37
+ // All: (Apache-2.0 WITH LLVM-exception OR MIT) AND (MIT OR GPL-2.0-only) AND (0BSD OR GPL-2.0-only)
38
+ val choices = listOf(
39
+ SpdxLicenseChoice ("$APACHE OR $MIT ".toSpdx(), MIT .toSpdx()),
40
+ SpdxLicenseChoice ("$MIT OR $GPL ".toSpdx(), MIT .toSpdx()),
41
+ SpdxLicenseChoice ("$BSD OR $GPL ".toSpdx(), BSD .toSpdx())
42
+ )
43
+
44
+ val effectiveLicense = RESOLVED_LICENSE_INFO .effectiveLicense(LicenseView .ALL , choices)
45
+
46
+ effectiveLicense shouldBe " $MIT AND $BSD " .toSpdx()
123
47
}
124
48
125
- " applyChoices(licenseChoices)" should {
126
- " apply license choices on all licenses" {
127
- val choices = listOf (
128
- SpdxLicenseChoice (" $APACHE OR $MIT " .toSpdx(), MIT .toSpdx()),
129
- SpdxLicenseChoice (" $MIT OR $GPL " .toSpdx(), MIT .toSpdx()),
130
- SpdxLicenseChoice (" $BSD OR $GPL " .toSpdx(), BSD .toSpdx())
131
- )
49
+ " apply a choice for a sub-expression only" {
50
+ // Declared: Apache-2.0 WITH LLVM-exception OR MIT OR GPL-2.0-only
51
+ val resolvedLicenseInfo = ResolvedLicenseInfo (
52
+ id = Identifier .EMPTY ,
53
+ licenseInfo = mockk(),
54
+ licenses = listOf(
55
+ ResolvedLicense (
56
+ license = APACHE .toSpdx() as SpdxSingleLicenseExpression ,
57
+ originalDeclaredLicenses = setOf("$APACHE OR $MIT "),
58
+ originalExpressions = setOf(
59
+ ResolvedOriginalExpression ("$APACHE OR $MIT OR $GPL ".toSpdx(), LicenseSource .DECLARED )
60
+ ),
61
+ locations = emptySet()
62
+ )
63
+ ),
64
+ copyrightGarbage = emptyMap(),
65
+ unmatchedCopyrights = emptyMap()
66
+ )
67
+
68
+ val choices = listOf(
69
+ SpdxLicenseChoice ("$APACHE OR $MIT ".toSpdx(), MIT .toSpdx())
70
+ )
71
+
72
+ val effectiveLicense = resolvedLicenseInfo.effectiveLicense(LicenseView .ONLY_DECLARED , choices)
73
+
74
+ effectiveLicense shouldBe " $MIT OR $GPL " .toSpdx()
75
+ }
76
+
77
+ " apply choices for LicenseView.CONCLUDED_OR_DECLARED_AND_DETECTED" {
78
+ // Concluded: 0BSD OR GPL-2.0-only
79
+ val choices = listOf(
80
+ SpdxLicenseChoice ("$BSD OR $GPL ".toSpdx(), BSD .toSpdx())
81
+ )
82
+
83
+ val effectiveLicense = RESOLVED_LICENSE_INFO .effectiveLicense(
84
+ LicenseView .CONCLUDED_OR_DECLARED_AND_DETECTED ,
85
+ choices
86
+ )
87
+
88
+ effectiveLicense shouldBe BSD .toSpdx()
89
+ }
90
+
91
+ " apply choices for LicenseView.ONLY_DECLARED" {
92
+ // Declared: Apache-2.0 WITH LLVM-exception OR MIT
93
+ val choices = listOf(
94
+ SpdxLicenseChoice ("$APACHE OR $MIT ".toSpdx(), MIT .toSpdx())
95
+ )
96
+
97
+ val effectiveLicense = RESOLVED_LICENSE_INFO .effectiveLicense(
98
+ LicenseView .ONLY_DECLARED ,
99
+ choices
100
+ )
132
101
133
- val filteredResolvedLicenseInfo = RESOLVED_LICENSE_INFO .applyChoices(choices)
102
+ effectiveLicense shouldBe MIT .toSpdx()
103
+ }
134
104
135
- filteredResolvedLicenseInfo.licenses should containLicensesExactly(MIT , BSD )
136
- }
105
+ " apply package and repository license choice for LicenseView.ONLY_CONCLUDED in the correct order" {
106
+ val repositoryChoices = listOf(
107
+ SpdxLicenseChoice ("$APACHE OR $MIT ".toSpdx(), MIT .toSpdx()),
108
+ SpdxLicenseChoice ("$BSD OR $GPL ".toSpdx(), BSD .toSpdx())
109
+ )
110
+ val packageChoices = listOf(
111
+ SpdxLicenseChoice ("$APACHE OR $MIT ".toSpdx(), APACHE .toSpdx())
112
+ )
113
+
114
+ val effectiveLicense = RESOLVED_LICENSE_INFO .effectiveLicense(
115
+ LicenseView .ALL ,
116
+ packageChoices,
117
+ repositoryChoices
118
+ )
119
+
120
+ effectiveLicense shouldBe " $APACHE and ($MIT or $GPL ) and $BSD " .toSpdx()
137
121
}
138
122
}
139
- }
123
+
124
+ " applyChoices(licenseChoices)" should {
125
+ " apply license choices on all licenses" {
126
+ val choices = listOf(
127
+ SpdxLicenseChoice ("$APACHE OR $MIT ".toSpdx(), MIT .toSpdx()),
128
+ SpdxLicenseChoice ("$MIT OR $GPL ".toSpdx(), MIT .toSpdx()),
129
+ SpdxLicenseChoice ("$BSD OR $GPL ".toSpdx(), BSD .toSpdx())
130
+ )
131
+
132
+ val filteredResolvedLicenseInfo = RESOLVED_LICENSE_INFO .applyChoices(choices)
133
+
134
+ filteredResolvedLicenseInfo.licenses should containLicensesExactly(MIT , BSD )
135
+ }
136
+ }
137
+ })
140
138
141
139
private const val MIT = " MIT"
142
140
private const val APACHE = " Apache-2.0 WITH LLVM-exception"
0 commit comments