-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLocalTimeSpec.scala
47 lines (36 loc) · 1.13 KB
/
LocalTimeSpec.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 LocalTimeSpec extends AnyFlatSpec with Matchers {
it should "fail if LocalTime value is not ISO8601 time formatted string" in {
//given
val isoString = "13:43:01.234Z"
//when
val e = the[IllegalArgumentException] thrownBy {
LocalTime(isoString)
}
//then
e.getMessage should include (
s"time string '$isoString' is not in ISO8601 format (HH:mm:ss.SSS)"
)
}
it should "create LocalTime with valid iso string" in {
def time(isoTime: String): Unit = {
LocalTime(isoTime).toString shouldBe isoTime
//check that it can also be parsed by javascript date
new js.Date(s"2019-03-12T${isoTime}Z").toISOString() shouldBe s"2019-03-12T${isoTime}Z"
}
//when & then
time("13:43:01.234")
}
it should "perform value equality" in {
//given
val d1 = LocalTime("13:43:01.234")
val d2 = LocalTime("13:43:01.234")
//when & then
d1 shouldBe d2
(d1 == d2) shouldBe true
d1 should not (be theSameInstanceAs d2)
}
}