@@ -32,24 +32,19 @@ import org.ossreviewtoolkit.utils.spdx.SpdxSingleLicenseExpression
32
32
import org.ossreviewtoolkit.utils.spdx.toSpdx
33
33
34
34
class ResolvedLicenseInfoTest : WordSpec () {
35
- private val mit = " MIT"
36
- private val apache = " Apache-2.0 WITH LLVM-exception"
37
- private val gpl = " GPL-2.0-only"
38
- private val bsd = " 0BSD"
39
-
40
35
init {
41
36
" effectiveLicense()" should {
42
37
" apply choices for LicenseView.ALL on all resolved licenses" {
43
38
// All: (Apache-2.0 WITH LLVM-exception OR MIT) AND (MIT OR GPL-2.0-only) AND (0BSD OR GPL-2.0-only)
44
39
val choices = listOf (
45
- SpdxLicenseChoice (" $apache OR $mit " .toSpdx(), mit .toSpdx()),
46
- SpdxLicenseChoice (" $mit OR $gpl " .toSpdx(), mit .toSpdx()),
47
- SpdxLicenseChoice (" $bsd OR $gpl " .toSpdx(), bsd .toSpdx())
40
+ SpdxLicenseChoice (" $APACHE OR $MIT " .toSpdx(), MIT .toSpdx()),
41
+ SpdxLicenseChoice (" $MIT OR $GPL " .toSpdx(), MIT .toSpdx()),
42
+ SpdxLicenseChoice (" $BSD OR $GPL " .toSpdx(), BSD .toSpdx())
48
43
)
49
44
50
- val effectiveLicense = createResolvedLicenseInfo() .effectiveLicense(LicenseView .ALL , choices)
45
+ val effectiveLicense = RESOLVED_LICENSE_INFO .effectiveLicense(LicenseView .ALL , choices)
51
46
52
- effectiveLicense shouldBe " $mit AND $bsd " .toSpdx()
47
+ effectiveLicense shouldBe " $MIT AND $BSD " .toSpdx()
53
48
}
54
49
55
50
" apply a choice for a sub-expression only" {
@@ -59,10 +54,10 @@ class ResolvedLicenseInfoTest : WordSpec() {
59
54
licenseInfo = mockk(),
60
55
licenses = listOf (
61
56
ResolvedLicense (
62
- license = apache .toSpdx() as SpdxSingleLicenseExpression ,
63
- originalDeclaredLicenses = setOf (" $apache OR $mit " ),
57
+ license = APACHE .toSpdx() as SpdxSingleLicenseExpression ,
58
+ originalDeclaredLicenses = setOf (" $APACHE OR $MIT " ),
64
59
originalExpressions = setOf (
65
- ResolvedOriginalExpression (" $apache OR $mit OR $gpl " .toSpdx(), LicenseSource .DECLARED )
60
+ ResolvedOriginalExpression (" $APACHE OR $MIT OR $GPL " .toSpdx(), LicenseSource .DECLARED )
66
61
),
67
62
locations = emptySet()
68
63
)
@@ -72,122 +67,125 @@ class ResolvedLicenseInfoTest : WordSpec() {
72
67
)
73
68
74
69
val choices = listOf (
75
- SpdxLicenseChoice (" $apache OR $mit " .toSpdx(), mit .toSpdx())
70
+ SpdxLicenseChoice (" $APACHE OR $MIT " .toSpdx(), MIT .toSpdx())
76
71
)
77
72
78
73
val effectiveLicense = resolvedLicenseInfo.effectiveLicense(LicenseView .ONLY_DECLARED , choices)
79
74
80
- effectiveLicense shouldBe " $mit OR $gpl " .toSpdx()
75
+ effectiveLicense shouldBe " $MIT OR $GPL " .toSpdx()
81
76
}
82
77
83
78
" apply choices for LicenseView.CONCLUDED_OR_DECLARED_AND_DETECTED" {
84
79
// Concluded: 0BSD OR GPL-2.0-only
85
80
val choices = listOf (
86
- SpdxLicenseChoice (" $bsd OR $gpl " .toSpdx(), bsd .toSpdx())
81
+ SpdxLicenseChoice (" $BSD OR $GPL " .toSpdx(), BSD .toSpdx())
87
82
)
88
83
89
- val effectiveLicense = createResolvedLicenseInfo() .effectiveLicense(
84
+ val effectiveLicense = RESOLVED_LICENSE_INFO .effectiveLicense(
90
85
LicenseView .CONCLUDED_OR_DECLARED_AND_DETECTED ,
91
86
choices
92
87
)
93
88
94
- effectiveLicense shouldBe bsd .toSpdx()
89
+ effectiveLicense shouldBe BSD .toSpdx()
95
90
}
96
91
97
92
" apply choices for LicenseView.ONLY_DECLARED" {
98
93
// Declared: Apache-2.0 WITH LLVM-exception OR MIT
99
94
val choices = listOf (
100
- SpdxLicenseChoice (" $apache OR $mit " .toSpdx(), mit .toSpdx())
95
+ SpdxLicenseChoice (" $APACHE OR $MIT " .toSpdx(), MIT .toSpdx())
101
96
)
102
97
103
- val effectiveLicense = createResolvedLicenseInfo() .effectiveLicense(
98
+ val effectiveLicense = RESOLVED_LICENSE_INFO .effectiveLicense(
104
99
LicenseView .ONLY_DECLARED ,
105
100
choices
106
101
)
107
102
108
- effectiveLicense shouldBe mit .toSpdx()
103
+ effectiveLicense shouldBe MIT .toSpdx()
109
104
}
110
105
111
106
" apply package and repository license choice for LicenseView.ONLY_CONCLUDED in the correct order" {
112
107
val repositoryChoices = listOf (
113
- SpdxLicenseChoice (" $apache OR $mit " .toSpdx(), mit .toSpdx()),
114
- SpdxLicenseChoice (" $bsd OR $gpl " .toSpdx(), bsd .toSpdx())
108
+ SpdxLicenseChoice (" $APACHE OR $MIT " .toSpdx(), MIT .toSpdx()),
109
+ SpdxLicenseChoice (" $BSD OR $GPL " .toSpdx(), BSD .toSpdx())
115
110
)
116
111
val packageChoices = listOf (
117
- SpdxLicenseChoice (" $apache OR $mit " .toSpdx(), apache .toSpdx())
112
+ SpdxLicenseChoice (" $APACHE OR $MIT " .toSpdx(), APACHE .toSpdx())
118
113
)
119
114
120
- val effectiveLicense = createResolvedLicenseInfo() .effectiveLicense(
115
+ val effectiveLicense = RESOLVED_LICENSE_INFO .effectiveLicense(
121
116
LicenseView .ALL ,
122
117
packageChoices,
123
118
repositoryChoices
124
119
)
125
120
126
- effectiveLicense shouldBe " $apache and ($mit or $gpl ) and $bsd " .toSpdx()
121
+ effectiveLicense shouldBe " $APACHE and ($MIT or $GPL ) and $BSD " .toSpdx()
127
122
}
128
123
}
129
124
130
125
" applyChoices(licenseChoices)" should {
131
126
" apply license choices on all licenses" {
132
- val resolvedLicenseInfo = createResolvedLicenseInfo()
133
-
134
127
val choices = listOf (
135
- SpdxLicenseChoice (" $apache OR $mit " .toSpdx(), mit .toSpdx()),
136
- SpdxLicenseChoice (" $mit OR $gpl " .toSpdx(), mit .toSpdx()),
137
- SpdxLicenseChoice (" $bsd OR $gpl " .toSpdx(), bsd .toSpdx())
128
+ SpdxLicenseChoice (" $APACHE OR $MIT " .toSpdx(), MIT .toSpdx()),
129
+ SpdxLicenseChoice (" $MIT OR $GPL " .toSpdx(), MIT .toSpdx()),
130
+ SpdxLicenseChoice (" $BSD OR $GPL " .toSpdx(), BSD .toSpdx())
138
131
)
139
132
140
- val filteredResolvedLicenseInfo = resolvedLicenseInfo .applyChoices(choices)
133
+ val filteredResolvedLicenseInfo = RESOLVED_LICENSE_INFO .applyChoices(choices)
141
134
142
- filteredResolvedLicenseInfo.licenses should containLicensesExactly(mit, bsd )
135
+ filteredResolvedLicenseInfo.licenses should containLicensesExactly(MIT , BSD )
143
136
}
144
137
}
145
138
}
139
+ }
146
140
147
- private fun createResolvedLicenseInfo (): ResolvedLicenseInfo {
148
- val resolvedLicenses = listOf (
149
- ResolvedLicense (
150
- license = apache.toSpdx() as SpdxSingleLicenseExpression ,
151
- originalDeclaredLicenses = setOf (" $apache OR $mit " ),
152
- originalExpressions = setOf (
153
- ResolvedOriginalExpression (" $apache OR $mit " .toSpdx(), LicenseSource .DECLARED )
154
- ),
155
- locations = emptySet()
141
+ private const val MIT = " MIT"
142
+ private const val APACHE = " Apache-2.0 WITH LLVM-exception"
143
+ private const val GPL = " GPL-2.0-only"
144
+ private const val BSD = " 0BSD"
145
+
146
+ private val RESOLVED_LICENSE_INFO : ResolvedLicenseInfo by lazy {
147
+ val resolvedLicenses = listOf (
148
+ ResolvedLicense (
149
+ license = APACHE .toSpdx() as SpdxSingleLicenseExpression ,
150
+ originalDeclaredLicenses = setOf (" $APACHE OR $MIT " ),
151
+ originalExpressions = setOf (
152
+ ResolvedOriginalExpression (" $APACHE OR $MIT " .toSpdx(), LicenseSource .DECLARED )
156
153
),
157
- ResolvedLicense (
158
- license = mit.toSpdx() as SpdxSingleLicenseExpression ,
159
- originalDeclaredLicenses = setOf ( " $apache OR $mit " ),
160
- originalExpressions = setOf (
161
- ResolvedOriginalExpression (" $apache OR $mit " .toSpdx(), LicenseSource . DECLARED ),
162
- ResolvedOriginalExpression ( " $mit OR $gpl " .toSpdx(), LicenseSource . DETECTED )
163
- ),
164
- locations = emptySet( )
154
+ locations = emptySet()
155
+ ) ,
156
+ ResolvedLicense (
157
+ license = MIT .toSpdx() as SpdxSingleLicenseExpression ,
158
+ originalDeclaredLicenses = setOf (" $APACHE OR $MIT " ),
159
+ originalExpressions = setOf (
160
+ ResolvedOriginalExpression ( " $APACHE OR $MIT " .toSpdx(), LicenseSource . DECLARED ),
161
+ ResolvedOriginalExpression ( " $MIT OR $GPL " .toSpdx(), LicenseSource . DETECTED )
165
162
),
166
- ResolvedLicense (
167
- license = gpl.toSpdx() as SpdxSingleLicenseExpression ,
168
- originalDeclaredLicenses = emptySet(),
169
- originalExpressions = setOf (
170
- ResolvedOriginalExpression ( " $mit OR $gpl " .toSpdx(), LicenseSource . DETECTED ),
171
- ResolvedOriginalExpression ( " $bsd OR $gpl " .toSpdx(), LicenseSource . CONCLUDED )
172
- ),
173
- locations = emptySet( )
163
+ locations = emptySet()
164
+ ) ,
165
+ ResolvedLicense (
166
+ license = GPL .toSpdx() as SpdxSingleLicenseExpression ,
167
+ originalDeclaredLicenses = emptySet( ),
168
+ originalExpressions = setOf (
169
+ ResolvedOriginalExpression ( " $MIT OR $GPL " .toSpdx(), LicenseSource . DETECTED ),
170
+ ResolvedOriginalExpression ( " $BSD OR $GPL " .toSpdx(), LicenseSource . CONCLUDED )
174
171
),
175
- ResolvedLicense (
176
- license = bsd.toSpdx() as SpdxSingleLicenseExpression ,
177
- originalDeclaredLicenses = emptySet(),
178
- originalExpressions = setOf (
179
- ResolvedOriginalExpression (" $bsd OR $gpl " .toSpdx(), LicenseSource .CONCLUDED )
180
- ),
181
- locations = emptySet()
182
- )
183
- )
184
-
185
- return ResolvedLicenseInfo (
186
- id = Identifier .EMPTY ,
187
- licenseInfo = mockk(),
188
- licenses = resolvedLicenses,
189
- copyrightGarbage = emptyMap(),
190
- unmatchedCopyrights = emptyMap()
172
+ locations = emptySet()
173
+ ),
174
+ ResolvedLicense (
175
+ license = BSD .toSpdx() as SpdxSingleLicenseExpression ,
176
+ originalDeclaredLicenses = emptySet(),
177
+ originalExpressions = setOf (
178
+ ResolvedOriginalExpression (" $BSD OR $GPL " .toSpdx(), LicenseSource .CONCLUDED )
179
+ ),
180
+ locations = emptySet()
191
181
)
192
- }
182
+ )
183
+
184
+ ResolvedLicenseInfo (
185
+ id = Identifier .EMPTY ,
186
+ licenseInfo = mockk(),
187
+ licenses = resolvedLicenses,
188
+ copyrightGarbage = emptyMap(),
189
+ unmatchedCopyrights = emptyMap()
190
+ )
193
191
}
0 commit comments