-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLocalDateSpec.scala
47 lines (36 loc) · 1.13 KB
/
LocalDateSpec.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
package org.joda.time
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
import scala.scalajs.js
class LocalDateSpec extends AnyFlatSpec with Matchers {
it should "fail if LocalDate value is not ISO8601 time formatted string" in {
//given
val isoString = "12.03.2019"
//when
val e = the[IllegalArgumentException] thrownBy {
LocalDate(isoString)
}
//then
e.getMessage should include (
s"date string '$isoString' is not in ISO8601 format (yyyy-MM-dd)"
)
}
it should "create LocalDate with valid iso string" in {
def date(isoDate: String): Unit = {
LocalDate(isoDate).toString shouldBe isoDate
//check that it can also be parsed by javascript date
new js.Date(s"${isoDate}T13:43:01.234Z").toISOString() shouldBe s"${isoDate}T13:43:01.234Z"
}
//when & then
date("2019-03-12")
}
it should "perform value equality" in {
//given
val d1 = LocalDate("2019-03-12")
val d2 = LocalDate("2019-03-12")
//when & then
d1 shouldBe d2
(d1 == d2) shouldBe true
d1 should not (be theSameInstanceAs d2)
}
}