Rewrites SntpClientTest with matchers

Issue #2745
This commit is contained in:
Ryan Haining 2023-09-08 19:33:00 -07:00
parent 2d8b1ecd90
commit e83d83b350

View file

@ -1,8 +1,8 @@
package info.nightscout.plugins.constraints.objectives
import com.google.common.truth.Truth.assertThat
import info.nightscout.shared.utils.DateUtil
import info.nightscout.sharedtests.TestBase
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.mockito.Mock
import kotlin.math.abs
@ -16,17 +16,17 @@ class SntpClientTest : TestBase() {
// no internet
SntpClient(aapsLogger, dateUtil).ntpTime(object : SntpClient.Callback() {
override fun run() {
Assertions.assertFalse(networkConnected)
Assertions.assertFalse(success)
Assertions.assertEquals(0L, time)
assertThat(networkConnected).isFalse()
assertThat(success).isFalse()
assertThat(time).isEqualTo(0L)
}
}, false)
// internet
SntpClient(aapsLogger, dateUtil).doNtpTime(object : SntpClient.Callback() {
override fun run() {
Assertions.assertTrue(success)
Assertions.assertTrue(abs(time - System.currentTimeMillis()) < 60000)
assertThat(success).isTrue()
assertThat(abs(time - System.currentTimeMillis())).isLessThan(60_000L)
}
})
}
}
}