@@ -36,6 +36,8 @@ import io.kotest.matchers.shouldNotBe
3636import  org.cyclonedx.parsers.JsonParser 
3737import  org.cyclonedx.parsers.XmlParser 
3838
39+ import  org.ossreviewtoolkit.model.Identifier 
40+ import  org.ossreviewtoolkit.model.OrtResult 
3941import  org.ossreviewtoolkit.plugins.reporters.cyclonedx.CycloneDxReporter.Companion.REPORT_BASE_FILENAME 
4042import  org.ossreviewtoolkit.reporter.ORT_RESULT 
4143import  org.ossreviewtoolkit.reporter.ORT_RESULT_WITH_ILLEGAL_COPYRIGHTS 
@@ -94,6 +96,30 @@ class CycloneDxReporterFunTest : WordSpec({
9496            }
9597        }
9698
99+         " create the expected XML file with authors" 
100+             val  expectedBom = readResource("/cyclonedx-reporter-expected-result-with-authors.xml")
101+ 
102+             val  ortResult = ORT_RESULT .withAuthors(
103+                 packageId = Identifier ("NPM :@ort:license-file:1.0"),
104+                 authors = setOf("Author  One ", "Author  Two ")
105+             )
106+ 
107+             val  bomFileResults = CycloneDxReporterFactory .create(
108+                 singleBom = true,
109+                 outputFileFormats = listOf("xml")
110+             ).generateReport(ReporterInput (ortResult), outputDir)
111+ 
112+             bomFileResults.shouldBeSingleton {
113+                 it shouldBeSuccess { bomFile -> 
114+                     bomFile shouldBe aFile()
115+                     bomFile shouldNotBe emptyFile()
116+ 
117+                     val  actualBom = bomFile.readText().patchCycloneDxResult().normalizeLineBreaks()
118+                     actualBom shouldBe expectedBom
119+                 }
120+             }
121+         }
122+ 
97123        " the expected XML file even if some copyrights contain non printable characters" 
98124            val  bomFileResults = CycloneDxReporterFactory .create(
99125                singleBom = true,
@@ -224,6 +250,26 @@ class CycloneDxReporterFunTest : WordSpec({
224250    }
225251})
226252
253+ /* *
254+  * Add [authors] to the [package][packageId]. 
255+  */  
256+ private  fun  OrtResult.withAuthors (packageId :  Identifier , authors :  Set <String >): OrtResult  = 
257+     analyzer?.let  { analyzer -> 
258+         copy(
259+             analyzer =  analyzer.copy(
260+                 result =  analyzer.result.copy(
261+                     packages =  analyzer.result.packages.map { pkg -> 
262+                         if  (pkg.id ==  packageId) {
263+                             pkg.copy(authors =  authors)
264+                         } else  {
265+                             pkg
266+                         }
267+                     }.toSet()
268+                 )
269+             )
270+         )
271+     } ? :  this 
272+ 
227273private  fun  String.patchCycloneDxResult (): String  = 
228274    replaceFirst(
229275        """ urn:uuid:[a-f0-9]{8}(?:-[a-f0-9]{4}){4}[a-f0-9]{8}""" 
0 commit comments