Skip to content
Permalink
Browse files

Move the trivial readOrtResult() test helper to test-utils

To share its use across reporter tests.

Signed-off-by: Sebastian Schuberth <sebastian.schuberth@bosch-si.com>
  • Loading branch information...
sschuberth committed Sep 2, 2019
1 parent 66d0f5e commit 959b888afe1c29eb0c59c6bc50287cab8e1620ce
@@ -21,10 +21,9 @@ package com.here.ort.reporter.reporters

import bad.robot.excel.matchers.WorkbookMatcher.sameWorkbook

import com.here.ort.model.OrtResult
import com.here.ort.model.config.CopyrightGarbage
import com.here.ort.model.readValue
import com.here.ort.reporter.DefaultResolutionProvider
import com.here.ort.utils.test.readOrtResult

import io.kotlintest.specs.WordSpec

@@ -36,14 +35,11 @@ import org.apache.poi.ss.usermodel.WorkbookFactory
import org.hamcrest.MatcherAssert.assertThat

class ExcelReporterTest : WordSpec({
val ortResult = File("../scanner/src/funTest/assets/file-counter-expected-output-for-analyzer-result.yml")
.readValue<OrtResult>()

"ExcelReporter" should {
"successfully export to an Excel sheet".config(enabled = false) {
val outputStream = ByteArrayOutputStream()
ExcelReporter().generateReport(
ortResult,
readOrtResult("../scanner/src/funTest/assets/file-counter-expected-output-for-analyzer-result.yml"),
DefaultResolutionProvider(),
DefaultLicenseTextProvider(),
CopyrightGarbage(),
@@ -21,8 +21,8 @@ package com.here.ort.reporter.reporters

import com.here.ort.model.OrtResult
import com.here.ort.model.config.CopyrightGarbage
import com.here.ort.model.readValue
import com.here.ort.reporter.DefaultResolutionProvider
import com.here.ort.utils.test.readOrtResult

import io.kotlintest.matchers.string.shouldContain
import io.kotlintest.matchers.string.shouldNotContain
@@ -33,10 +33,6 @@ import java.io.ByteArrayOutputStream
import java.io.File

class NoticeReporterTest : WordSpec() {
companion object {
private fun readOrtResult(file: String) = File(file).readValue<OrtResult>()
}

init {
"NoticeReporter" should {
"generate the correct license notes" {
@@ -22,9 +22,9 @@ package com.here.ort.reporter.reporters
import com.here.ort.model.Environment
import com.here.ort.model.OrtResult
import com.here.ort.model.config.CopyrightGarbage
import com.here.ort.model.readValue
import com.here.ort.reporter.DefaultResolutionProvider
import com.here.ort.utils.test.patchExpectedResult
import com.here.ort.utils.test.readOrtResult

import io.kotlintest.shouldBe
import io.kotlintest.specs.WordSpec
@@ -35,8 +35,6 @@ import java.io.File
import javax.xml.transform.TransformerFactory

class StaticHtmlReporterTest : WordSpec() {
private val ortResult = File("src/funTest/assets/static-html-reporter-test-input.yml").readValue<OrtResult>()

init {
"StaticHtmlReporter" should {
"use the Apache Xalan TransformerFactory" {
@@ -47,6 +45,7 @@ class StaticHtmlReporterTest : WordSpec() {

"successfully export to a static HTML page" {
val timeStampPattern = Regex("\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z")
val ortResult = readOrtResult("src/funTest/assets/static-html-reporter-test-input.yml")
val actualReport = generateReport(ortResult).replace(timeStampPattern, "<REPLACE_TIMESTAMP>")

val expectedReport = patchExpectedResult(
@@ -19,26 +19,21 @@

package com.here.ort.reporter.reporters

import com.here.ort.model.OrtResult
import com.here.ort.model.config.CopyrightGarbage
import com.here.ort.model.readValue
import com.here.ort.reporter.DefaultResolutionProvider
import com.here.ort.utils.test.readOrtResult

import io.kotlintest.shouldNotBe
import io.kotlintest.specs.WordSpec

import java.io.ByteArrayOutputStream
import java.io.File

class WebAppReporterTest : WordSpec({
val ortResult = File("../scanner/src/funTest/assets/file-counter-expected-output-for-analyzer-result.yml")
.readValue<OrtResult>()

"WebAppReporter" should {
"successfully export to a web application" {
val outputStream = ByteArrayOutputStream()
WebAppReporter().generateReport(
ortResult,
readOrtResult("../scanner/src/funTest/assets/file-counter-expected-output-for-analyzer-result.yml"),
DefaultResolutionProvider(),
DefaultLicenseTextProvider(),
CopyrightGarbage(),
@@ -19,8 +19,10 @@

package com.here.ort.utils.test

import com.here.ort.model.OrtResult
import com.here.ort.model.config.AnalyzerConfiguration
import com.here.ort.model.config.RepositoryConfiguration
import com.here.ort.model.readValue

import java.io.File
import java.time.Instant
@@ -75,3 +77,5 @@ fun patchActualResult(result: String, patchDownloadTime: Boolean = false, patchS
.replaceIf(patchDownloadTime, DOWNLOAD_TIME_REGEX) { "${it.groupValues[1]}: \"${Instant.EPOCH}\"" }
.replaceIf(patchStartAndEndTime, START_AND_END_TIME_REGEX) { "${it.groupValues[1]}: \"${Instant.EPOCH}\"" }
}

fun readOrtResult(file: String) = File(file).readValue<OrtResult>()

0 comments on commit 959b888

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