/
DatesTest.kt
67 lines (54 loc) · 1.81 KB
/
DatesTest.kt
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
package khronos
import org.junit.Test
import java.util.*
/**
* Unit test for [Dates].
*/
class DatesTest {
@Test fun now() {
assertVeryClose(from = Date(), to = Dates.today)
}
@Test fun today() {
assertVeryClose(from = Date(), to = Dates.today)
}
@Test fun tomorrow() {
val calendar = Calendar.getInstance()
calendar.add(Calendar.DAY_OF_MONTH, 1)
assertVeryClose(from = calendar.time, to = Dates.tomorrow)
}
@Test fun yesterday() {
val calendar = Calendar.getInstance()
calendar.add(Calendar.DAY_OF_MONTH, -1)
assertVeryClose(from = calendar.time, to = Dates.yesterday)
}
@Test fun dateYear() {
val calendar = Calendar.getInstance()
calendar.set(Calendar.YEAR, 1990)
assertVeryClose(from = calendar.time, to = Dates.of(year = 1990))
}
@Test fun dateMonth() {
val calendar = Calendar.getInstance()
calendar.set(Calendar.MONTH, 0)
assertVeryClose(from = calendar.time, to = Dates.of(month = 1))
}
@Test fun dateDay() {
val calendar = Calendar.getInstance()
calendar.set(Calendar.DATE, 21)
assertVeryClose(from = calendar.time, to = Dates.of(day = 21))
}
@Test fun dateHour() {
val calendar = Calendar.getInstance()
calendar.set(Calendar.HOUR_OF_DAY, 4)
assertVeryClose(from = calendar.time, to = Dates.of(hour = 4))
}
@Test fun dateMinute() {
val calendar = Calendar.getInstance()
calendar.set(Calendar.MINUTE, 30)
assertVeryClose(from = calendar.time, to = Dates.of(minute = 30))
}
@Test fun dateSecond() {
val calendar = Calendar.getInstance()
calendar.set(Calendar.SECOND, 10)
assertVeryClose(from = calendar.time, to = Dates.of(second = 10))
}
}