Skip to content
This repository was archived by the owner on Dec 3, 2020. It is now read-only.

Commit e784fc1

Browse files
author
Daniel Reigada
committed
Add tests
1 parent 8a46d1d commit e784fc1

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

src/main/scala/com/codacy/parsers/CoverageParser.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ object CoverageParserFactory {
4848
} else {
4949
parserFactory.fold[Either[String, A]] {
5050
val parsers = allParsers(language, rootProject, reportFile)
51-
withReport(parsers)(s"could not parse report with any parser")(block)
51+
withReport(parsers)(s"could not parse report, unrecognized report format")(block)
5252
} { parserFactory =>
5353
val parser = parserFactory(language, rootProject, reportFile)
5454
withReport(Seq(parser))("could not parse report with the provided parser")(block)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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

Comments
 (0)