|
| 1 | +package com.codacy.parsers |
| 2 | + |
| 3 | +import java.io.File |
| 4 | + |
| 5 | +import com.codacy.api.{CoverageFileReport, CoverageReport, Language} |
| 6 | +import com.codacy.parsers.implementation.{CoberturaParser, JacocoParser} |
| 7 | +import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpec} |
| 8 | + |
| 9 | +class CoverageParserFactoryTest extends WordSpec with BeforeAndAfterAll with Matchers { |
| 10 | + "CoverageParserFactory" should { |
| 11 | + "get report with unspecified parser" in { |
| 12 | + val expectedReport = CoverageReport(87, List( |
| 13 | + CoverageFileReport("src/test/resources/TestSourceFile.scala", 87, |
| 14 | + Map(5 -> 1, 10 -> 1, 6 -> 2, 9 -> 1, 3 -> 0, 4 -> 1)), |
| 15 | + CoverageFileReport("src/test/resources/TestSourceFile2.scala", 87, |
| 16 | + Map(1 -> 1, 2 -> 1, 3 -> 1)))) |
| 17 | + |
| 18 | + runForFile("src/test/resources/test_cobertura.xml", None) shouldEqual Right(expectedReport) |
| 19 | + } |
| 20 | + |
| 21 | + "get report with jacoco parser" in { |
| 22 | + val expectedReport = CoverageReport(73, List( |
| 23 | + CoverageFileReport("org/eluder/coverage/sample/InnerClassCoverage.java", 81, |
| 24 | + Map(10 -> 1, 6 -> 1, 9 -> 1, 13 -> 1, 22 -> 1, 27 -> 0, 12 -> 1, 3 -> 1, 16 -> 1, 26 -> 0, 19 -> 1)), |
| 25 | + CoverageFileReport("org/eluder/coverage/sample/SimpleCoverage.java", 50, |
| 26 | + Map(3 -> 1, 6 -> 1, 10 -> 0, 11 -> 0)))) |
| 27 | + |
| 28 | + runForFile("src/test/resources/test_jacoco.xml", Some(JacocoParser)) shouldEqual Right(expectedReport) |
| 29 | + } |
| 30 | + |
| 31 | + |
| 32 | + "fail to get report with wrong parser" in { |
| 33 | + runForFile("src/test/resources/test_jacoco.xml", Some(CoberturaParser)) shouldEqual |
| 34 | + Left("could not parse report with the provided parser") |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + private def runForFile(file: String, parser: Option[CoverageParserFactory]) = { |
| 39 | + CoverageParserFactory.withCoverageReport( |
| 40 | + Language.Scala, |
| 41 | + new File("."), |
| 42 | + new File(file), |
| 43 | + parser |
| 44 | + )(identity) |
| 45 | + } |
| 46 | +} |
0 commit comments