-
Notifications
You must be signed in to change notification settings - Fork 568
Expand file tree
/
Copy pathFootballTest.scala
More file actions
70 lines (52 loc) · 2.51 KB
/
FootballTest.scala
File metadata and controls
70 lines (52 loc) · 2.51 KB
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
package football.implicits
import test.FootballTestData.{fixture, liveMatch, result}
import org.scalatest.featurespec.AnyFeatureSpec
import org.scalatest.matchers.should.Matchers
import org.scalatest.GivenWhenThen
import java.time.{ZoneId, ZonedDateTime}
class FootballTest extends AnyFeatureSpec with GivenWhenThen with Matchers with implicits.Football {
private val zone = ZoneId.of("Europe/London")
private val today = ZonedDateTime.now().withZoneSameInstant(zone)
Feature("FootballMatch") {
Scenario("isOn returns false if match date is before the given date") {
Given("a match which happened yesterday")
val yesterdayMatch =
result("Aston Villa", "Cardiff", 1, 0, today.minusDays(1), None)
Then("calling isOn with today's date should return false")
val isMatchOnToday = yesterdayMatch.isOn(today.toLocalDate)
isMatchOnToday shouldBe (false)
}
Scenario("isOn returns false if match date is after the given date") {
Given("a match which will happen tomorrow")
val tomorrowMatch =
fixture("Aston Villa", "Cardiff", today.plusDays(1))
Then("calling isOn with today's date should return false")
val isMatchOnToday = tomorrowMatch.isOn(today.toLocalDate)
isMatchOnToday shouldBe (false)
}
Scenario("isOn returns true if match date is same as the given date") {
Given("a match which happens today")
val todayMatch =
liveMatch("Aston Villa", "Cardiff", 1, 0, today, isLive = true)
Then("calling isOn with today's date should return true")
val isMatchOnToday = todayMatch.isOn(today.toLocalDate)
isMatchOnToday shouldBe (true)
}
Scenario("isAboutToStart returns true if match start time is within the next 5 minutes") {
Given("a match which happens in 5 minutes")
val fiveMinutesFromNow = ZonedDateTime.now().plusMinutes(5)
val theMatch =
liveMatch("Aston Villa", "Cardiff", 1, 0, fiveMinutesFromNow, isLive = true)
Then("calling isAboutToStart should return true")
theMatch.isAboutToStart shouldBe (true)
}
Scenario("isAboutToStart returns false if match start time is more than 5 minutes from now") {
Given("a match starting in more than 5 minutes")
val fiveMinutesFromNow = ZonedDateTime.now().plusMinutes(5).plusSeconds(1)
val theMatch =
liveMatch("Aston Villa", "Cardiff", 1, 0, fiveMinutesFromNow, isLive = true)
Then("calling isAboutToStart should return fals")
theMatch.isAboutToStart shouldBe (false)
}
}
}