@@ -9,18 +9,23 @@ import org.junit.Test
9
9
import org.junit.runner.RunWith
10
10
import org.robolectric.RobolectricTestRunner
11
11
import org.robolectric.annotation.Config
12
- import java.util.*
12
+ import java.time.OffsetDateTime
13
+ import java.time.ZoneOffset
14
+ import java.time.format.DateTimeFormatter
13
15
14
16
@RunWith(RobolectricTestRunner ::class )
15
17
@Config(sdk = [Build .VERSION_CODES .P ])
16
18
class StudyRecordUnitTest {
17
19
20
+ private val date = OffsetDateTime .of(2019 , 6 , 1 , 1 , 2 , 3 , 0 , ZoneOffset .UTC )
21
+ private val dateStr = date.format(DateTimeFormatter .ISO_OFFSET_DATE_TIME )
22
+
18
23
@Test
19
24
fun toJsonTest_littleParams () {
20
25
val studyRecord = StudyRecord (2 * 60 )
21
26
22
27
assertEquals(
23
- " {\" recorded_at \" :\" ${StudyRecord .formatTime( studyRecord.recordedTime)} \" ,\" duration\" :120}" ,
28
+ " {\" record_datetime \" :\" ${studyRecord.recordedTime.format( DateTimeFormatter . ISO_OFFSET_DATE_TIME )} \" ,\" duration\" :120}" ,
24
29
studyRecord.toJson()
25
30
)
26
31
}
@@ -31,11 +36,11 @@ class StudyRecordUnitTest {
31
36
duration = 2 * 60 ,
32
37
amount = StudyRecordAmountTotal (30 ),
33
38
comment = " perfect!" ,
34
- recordedTime = Calendar .getInstance(). apply { set( 2019 , 5 , 1 , 1 , 2 , 3 ) }
39
+ recordedTime = date
35
40
)
36
41
37
42
assertEquals(
38
- " {\" recorded_at \" :\" 2019-06-01 01:02:03 \" ,\" duration\" :120,\" comment\" :\" perfect!\" ,\" amount\" :30}" ,
43
+ " {\" record_datetime \" :\" $dateStr \" ,\" duration\" :120,\" comment\" :\" perfect!\" ,\" amount\" :30}" ,
39
44
studyRecord.toJson()
40
45
)
41
46
}
@@ -46,11 +51,11 @@ class StudyRecordUnitTest {
46
51
duration = 2 * 60 ,
47
52
amount = StudyRecordAmountRange (5 , 12 ),
48
53
comment = " perfect!" ,
49
- recordedTime = Calendar .getInstance(). apply { set( 2019 , 5 , 1 , 1 , 2 , 3 ) }
54
+ recordedTime = date
50
55
)
51
56
52
57
assertEquals(
53
- " {\" recorded_at \" :\" 2019-06-01 01:02:03 \" ,\" duration\" :120,\" comment\" :\" perfect!\" ,\" start_position\" :5,\" end_position\" :12}" ,
58
+ " {\" record_datetime \" :\" $dateStr \" ,\" duration\" :120,\" comment\" :\" perfect!\" ,\" start_position\" :5,\" end_position\" :12}" ,
54
59
studyRecord.toJson()
55
60
)
56
61
}
0 commit comments