@@ -9,18 +9,23 @@ import org.junit.Test
99import org.junit.runner.RunWith
1010import org.robolectric.RobolectricTestRunner
1111import org.robolectric.annotation.Config
12- import java.util.*
12+ import java.time.OffsetDateTime
13+ import java.time.ZoneOffset
14+ import java.time.format.DateTimeFormatter
1315
1416@RunWith(RobolectricTestRunner ::class )
1517@Config(sdk = [Build .VERSION_CODES .P ])
1618class StudyRecordUnitTest {
1719
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+
1823 @Test
1924 fun toJsonTest_littleParams () {
2025 val studyRecord = StudyRecord (2 * 60 )
2126
2227 assertEquals(
23- " {\" recorded_at \" :\" ${StudyRecord .formatTime( studyRecord.recordedTime)} \" ,\" duration\" :120}" ,
28+ " {\" record_datetime \" :\" ${studyRecord.recordedTime.format( DateTimeFormatter . ISO_OFFSET_DATE_TIME )} \" ,\" duration\" :120}" ,
2429 studyRecord.toJson()
2530 )
2631 }
@@ -31,11 +36,11 @@ class StudyRecordUnitTest {
3136 duration = 2 * 60 ,
3237 amount = StudyRecordAmountTotal (30 ),
3338 comment = " perfect!" ,
34- recordedTime = Calendar .getInstance(). apply { set( 2019 , 5 , 1 , 1 , 2 , 3 ) }
39+ recordedTime = date
3540 )
3641
3742 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}" ,
3944 studyRecord.toJson()
4045 )
4146 }
@@ -46,11 +51,11 @@ class StudyRecordUnitTest {
4651 duration = 2 * 60 ,
4752 amount = StudyRecordAmountRange (5 , 12 ),
4853 comment = " perfect!" ,
49- recordedTime = Calendar .getInstance(). apply { set( 2019 , 5 , 1 , 1 , 2 , 3 ) }
54+ recordedTime = date
5055 )
5156
5257 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}" ,
5459 studyRecord.toJson()
5560 )
5661 }
0 commit comments