Skip to content

Commit

Permalink
reporter: Get rid of the simple-excel and hamcrest test dependencies
Browse files Browse the repository at this point in the history
The simple-excel project has not been updated for about a year despite
having issues [1] [2], so get rid of it in favor of using kotest matchers
directly on the sheet properties.

[1] tobyweston/simple-excel#14
[2] tobyweston/simple-excel#19

Signed-off-by: Sebastian Schuberth <sebastian.schuberth@bosch.io>
  • Loading branch information
sschuberth committed Oct 10, 2020
1 parent 5e1008e commit 0ab3465
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 22 deletions.
13 changes: 0 additions & 13 deletions reporter/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,6 @@ sourceSets.named("main") {
}

repositories {
exclusiveContent {
forRepository {
maven("http://www.robotooling.com/maven/")
}

filter {
includeGroup("bad.robot")
}
}

exclusiveContent {
forRepository {
maven("https://download.eclipse.org/antenna/releases/")
Expand Down Expand Up @@ -120,7 +110,4 @@ dependencies {
// This is required to not depend on the version of Apache Xalan bundled with the JDK. Otherwise the formatting of
// the HTML generated in StaticHtmlReporter is slightly different with different Java versions.
implementation("xalan:xalan:$xalanVersion")

funTestImplementation("bad.robot:simple-excel:$simpleExcelVersion")
funTestImplementation("org.hamcrest:hamcrest-core:$hamcrestCoreVersion")
}
47 changes: 38 additions & 9 deletions reporter/src/funTest/kotlin/reporters/ExcelReporterFunTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@

package org.ossreviewtoolkit.reporter.reporters

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

import io.kotest.core.spec.style.WordSpec
import io.kotest.inspectors.forAll
import io.kotest.matchers.collections.shouldContainExactly
import io.kotest.matchers.shouldBe

import java.io.File

import org.apache.poi.ss.usermodel.WorkbookFactory

import org.hamcrest.MatcherAssert.assertThat

import org.ossreviewtoolkit.reporter.ReporterInput
import org.ossreviewtoolkit.utils.ORT_NAME
import org.ossreviewtoolkit.utils.test.readOrtResult
Expand All @@ -40,13 +39,43 @@ class ExcelReporterFunTest : WordSpec({
val ortResult = readOrtResult(
"../scanner/src/funTest/assets/file-counter-expected-output-for-analyzer-result.yml"
)
val sheet = ExcelReporter().generateReport(ReporterInput(ortResult), outputDir).single()
val actualWorkbook = WorkbookFactory.create(sheet)

val expectedFile = File("src/funTest/assets/file-counter-expected-scan-report.xlsx")
val expectedWorkbook = WorkbookFactory.create(expectedFile)
val report = ExcelReporter().generateReport(ReporterInput(ortResult), outputDir).single()
val actualWorkbook = WorkbookFactory.create(report)
val actualSheetNames = actualWorkbook.sheetIterator().asSequence().map { it.sheetName }.toList()

val asset = File("src/funTest/assets/file-counter-expected-scan-report.xlsx")
val expectedWorkbook = WorkbookFactory.create(asset)
val expectedSheetNames = expectedWorkbook.sheetIterator().asSequence().map { it.sheetName }.toList()

actualSheetNames shouldContainExactly expectedSheetNames
actualSheetNames.forAll { sheetName ->
val actualSheet = actualWorkbook.getSheet(sheetName)
val actualRowNums = actualSheet.rowIterator().asSequence().map { it.rowNum }.toList()

val expectedSheet = expectedWorkbook.getSheet(sheetName)
val expectedRowNums = expectedSheet.rowIterator().asSequence().map { it.rowNum }.toList()

actualRowNums shouldContainExactly expectedRowNums
actualRowNums.forAll { rowNum ->
val actualRow = actualSheet.getRow(rowNum)
val actualColumnIndices = actualRow.cellIterator().asSequence().map { it.columnIndex }.toList()

val expectedRow = expectedSheet.getRow(rowNum)
val expectedColumnIndices = expectedRow.cellIterator().asSequence().map { it.columnIndex }.toList()

actualColumnIndices shouldContainExactly expectedColumnIndices
actualColumnIndices.forAll { columnIndex ->
val actualCell = actualRow.getCell(columnIndex)
val expectedCell = expectedRow.getCell(columnIndex)

assertThat(actualWorkbook, sameWorkbook(expectedWorkbook))
actualCell.cellTypeEnum shouldBe expectedCell.cellTypeEnum
actualCell.stringCellValue shouldBe expectedCell.stringCellValue
actualCell.cellStyle.fontIndex shouldBe expectedCell.cellStyle.fontIndex
actualCell.cellStyle.fillBackgroundColor shouldBe expectedCell.cellStyle.fillBackgroundColor
}
}
}
}
}
})

0 comments on commit 0ab3465

Please sign in to comment.