-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGitLogServiceSpec.scala
73 lines (57 loc) · 2.4 KB
/
GitLogServiceSpec.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package gitlog
import gitlog.FrontEndJsonModel.Author
import gitlog.GitLogJsonModel.{GitLog, LogEntry}
import org.scalatest._
import play.api.libs.json.{JsError, JsNull, JsSuccess, Json}
class GitLogServiceSpec extends FlatSpec with Matchers {
class GitLogFixture {
// read gitlog json AST and try to convert into a GitLog instance
val maybeGitLog: Option[GitLog] =
GitLogReader.readLog("src/test/scala/gitlog/scala-gitlog.json")
.getOrElse(JsNull)
.validate[GitLog] match {
case error: JsError =>
println("Errors during Json deserialization " + error.errors)
None
case success: JsSuccess[GitLog] => success.asOpt
}
maybeGitLog shouldBe defined
val gitLog: GitLog = maybeGitLog.get
}
"Number of commits" should "be 307" in new GitLogFixture{
GitLogService.countCommits(gitLog) shouldBe 307
}
"Number of committers" should "be 36" in new GitLogFixture{
GitLogService.countOfContributer(gitLog) shouldBe 36
}
"Adriaan Moors" should "have made 40 commits" in new GitLogFixture {
GitLogService.countCommitsOfUser(gitLog, "Adriaan Moors <adriaan.moors@typesafe.com>") shouldBe 40
}
"Name and email of an author in LogEntry" should "be splitted into name and email of Author" in {
GitLogService.authorFromLogEntry(LogEntry(author = "Adriaan Moors <adriaan.moors@typesafe.com>")) shouldBe Author(name = "Adriaan Moors", email = "<adriaan.moors@typesafe.com>")
}
"Name and email of an author" should "serialize to Json" in {
val expectedJson =
"""
|{
| "name": "John Doe",
| "email": "<john.doe@email.com>"
|}
""".
stripMargin
val author: Author = Author(name = "John Doe", email = "<john.doe@email.com>")
val authorJson = Json.toJson(author)
authorJson shouldBe Json.parse(
expectedJson)
}
"Adriaan Moors email" should "be <adriaan.moors@typesafe.com>" in new GitLogFixture {
val users = GitLogService.authorFromLogEntries(gitLog.logEntries)
GitLogService.author(users, "Adriaan Moors").email shouldBe "<adriaan.moors@typesafe.com>"
}
"For Adriaan Moors" should "40 log entries be found" in new GitLogFixture {
GitLogService.logEntryByName(gitLog)("Adriaan Moors").size shouldBe 40
}
"4 commits" should "have been done on Wed Aug 5 2015" in new GitLogFixture{
GitLogService.logEntryPerDay(gitLog)("2015-08-05") shouldBe 4
}
}