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