Rewrites DateUtilTest with matchers

Issue #2745
This commit is contained in:
Ryan Haining 2023-09-20 22:55:46 -07:00
parent 8819aed6e1
commit 107f6d05dd

View file

@ -7,7 +7,6 @@ import info.nightscout.shared.utils.DateUtilImpl
import info.nightscout.shared.utils.T import info.nightscout.shared.utils.T
import info.nightscout.sharedtests.TestBase import info.nightscout.sharedtests.TestBase
import org.junit.jupiter.api.AfterAll import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeAll import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.mockito.Mock import org.mockito.Mock
@ -41,25 +40,25 @@ class DateUtilTest : TestBase() {
@Test @Test
fun fromISODateStringTest() { fun fromISODateStringTest() {
Assertions.assertEquals(1511124634417L, DateUtilImpl(context).fromISODateString("2017-11-19T22:50:34.417+0200")) assertThat(DateUtilImpl(context).fromISODateString("2017-11-19T22:50:34.417+0200")).isEqualTo(1511124634417L)
Assertions.assertEquals(1511124634000L, DateUtilImpl(context).fromISODateString("2017-11-19T22:50:34+0200")) assertThat(DateUtilImpl(context).fromISODateString("2017-11-19T22:50:34+0200")).isEqualTo(1511124634000L)
Assertions.assertEquals(1512317365000L, DateUtilImpl(context).fromISODateString("2017-12-03T16:09:25.000Z")) assertThat(DateUtilImpl(context).fromISODateString("2017-12-03T16:09:25.000Z")).isEqualTo(1512317365000L)
Assertions.assertEquals(1513902750000L, DateUtilImpl(context).fromISODateString("2017-12-22T00:32:30Z")) assertThat(DateUtilImpl(context).fromISODateString("2017-12-22T00:32:30Z")).isEqualTo(1513902750000L)
} }
@Test @Test
fun toISOStringTest() { fun toISOStringTest() {
Assertions.assertEquals("2017-12-22T00:32:30.000Z", DateUtilImpl(context).toISOString(1513902750000L)) assertThat(DateUtilImpl(context).toISOString(1513902750000L)).isEqualTo("2017-12-22T00:32:30.000Z")
} }
@Test fun secondsOfTheDayToMillisecondsTest() { @Test fun secondsOfTheDayToMillisecondsTest() {
Assertions.assertTrue(Date(DateUtilImpl(context).secondsOfTheDayToMilliseconds((T.hours(1).secs() + T.mins(1).secs() + 1).toInt())).toString().contains("01:01:00")) assertThat(Date(DateUtilImpl(context).secondsOfTheDayToMilliseconds((T.hours(1).secs() + T.mins(1).secs() + 1).toInt())).toString()).contains("01:01:00")
} }
@Test fun toSecondsTest() { @Test fun toSecondsTest() {
Assertions.assertEquals(3600, DateUtilImpl(context).toSeconds("01:00").toLong()) assertThat(DateUtilImpl(context).toSeconds("01:00").toLong()).isEqualTo(3600)
Assertions.assertEquals(3600, DateUtilImpl(context).toSeconds("01:00 a.m.").toLong()) assertThat(DateUtilImpl(context).toSeconds("01:00 a.m.").toLong()).isEqualTo(3600)
Assertions.assertEquals(3600, DateUtilImpl(context).toSeconds("01:00 AM").toLong()) assertThat(DateUtilImpl(context).toSeconds("01:00 AM").toLong()).isEqualTo(3600)
} }
@Test fun dateStringTest() { @Test fun dateStringTest() {
@ -67,7 +66,7 @@ class DateUtilTest : TestBase() {
} }
@Test fun timeStringTest() { @Test fun timeStringTest() {
Assertions.assertTrue(DateUtilImpl(context).timeString(1513902750000L).contains("32")) assertThat(DateUtilImpl(context).timeString(1513902750000L)).contains("32")
} }
@Test fun dateAndTimeStringTest() { @Test fun dateAndTimeStringTest() {
@ -85,11 +84,11 @@ class DateUtilTest : TestBase() {
/* /*
@Test @Test
public void timeStringFromSecondsTest() { public void timeStringFromSecondsTest() {
Assertions.assertEquals("1:00 AM", DateUtil.timeStringFromSeconds((int) T.hours(1).secs())); assertThat(DateUtil.timeStringFromSeconds((int) T.hours(1).secs()));.isEqualTo("1:00 AM")
} }
*/ */
@Test fun timeFrameStringTest() { @Test fun timeFrameStringTest() {
`when`(rh.gs(info.nightscout.interfaces.R.string.shorthour)).thenReturn("h") `when`(rh.gs(info.nightscout.interfaces.R.string.shorthour)).thenReturn("h")
Assertions.assertEquals("(1h 1')", DateUtilImpl(context).timeFrameString(T.hours(1).msecs() + T.mins(1).msecs(), rh)) assertThat(DateUtilImpl(context).timeFrameString(T.hours(1).msecs() + T.mins(1).msecs(), rh)).isEqualTo("(1h 1')")
} }
} }