Rewrites TTest with matchers

Issue #2745
This commit is contained in:
Ryan Haining 2023-09-08 19:21:52 -07:00
parent ce5d2dfdbd
commit 788eff4682

View file

@ -1,7 +1,7 @@
package info.nightscout.core.utils package info.nightscout.core.utils
import com.google.common.truth.Truth.assertThat
import info.nightscout.shared.utils.T import info.nightscout.shared.utils.T
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import kotlin.math.abs import kotlin.math.abs
@ -9,33 +9,33 @@ import kotlin.math.abs
class TTest { class TTest {
@Test fun toUnits() { @Test fun toUnits() {
Assertions.assertEquals(1, T.msecs(1000).secs()) assertThat(T.msecs(1000).secs()).isEqualTo(1)
Assertions.assertEquals(1, T.secs(60).mins()) assertThat(T.secs(60).mins()).isEqualTo(1)
Assertions.assertEquals(1, T.mins(60).hours()) assertThat(T.mins(60).hours()).isEqualTo(1)
Assertions.assertEquals(1, T.hours(24).days()) assertThat(T.hours(24).days()).isEqualTo(1)
Assertions.assertEquals(24, T.days(1).hours()) assertThat(T.days(1).hours()).isEqualTo(24)
Assertions.assertEquals(60000, T.mins(1).msecs()) assertThat(T.mins(1).msecs()).isEqualTo(60000)
} }
@Test fun now() { @Test fun now() {
Assertions.assertTrue(abs(T.now().msecs() - System.currentTimeMillis()) < 5000) assertThat(abs(T.now().msecs() - System.currentTimeMillis())).isLessThan(5_000L)
} }
@Test fun additions() { @Test fun additions() {
val nowMsecs = System.currentTimeMillis() val nowMsecs = System.currentTimeMillis()
val now = T.msecs(nowMsecs) val now = T.msecs(nowMsecs)
Assertions.assertEquals(now.plus(T.secs(5)).msecs(), nowMsecs + 5 * 1000) assertThat(nowMsecs + 5 * 1000).isEqualTo(now.plus(T.secs(5)).msecs())
Assertions.assertEquals(now.plus(T.mins(5)).msecs(), nowMsecs + 5 * 60 * 1000) assertThat(nowMsecs + 5 * 60 * 1000).isEqualTo(now.plus(T.mins(5)).msecs())
Assertions.assertEquals(now.plus(T.hours(5)).msecs(), nowMsecs + 5 * 60 * 60 * 1000) assertThat(nowMsecs + 5 * 60 * 60 * 1000).isEqualTo(now.plus(T.hours(5)).msecs())
Assertions.assertEquals(now.plus(T.days(5)).msecs(), nowMsecs + 5 * 24 * 60 * 60 * 1000) assertThat(nowMsecs + 5 * 24 * 60 * 60 * 1000).isEqualTo(now.plus(T.days(5)).msecs())
} }
@Test fun subtractions() { @Test fun subtractions() {
val nowMsecs = System.currentTimeMillis() val nowMsecs = System.currentTimeMillis()
val now = T.msecs(nowMsecs) val now = T.msecs(nowMsecs)
Assertions.assertEquals(now.minus(T.secs(5)).msecs(), nowMsecs - 5 * 1000) assertThat(nowMsecs - 5 * 1000).isEqualTo(now.minus(T.secs(5)).msecs())
Assertions.assertEquals(now.minus(T.mins(5)).msecs(), nowMsecs - 5 * 60 * 1000) assertThat(nowMsecs - 5 * 60 * 1000).isEqualTo(now.minus(T.mins(5)).msecs())
Assertions.assertEquals(now.minus(T.hours(5)).msecs(), nowMsecs - 5 * 60 * 60 * 1000) assertThat(nowMsecs - 5 * 60 * 60 * 1000).isEqualTo(now.minus(T.hours(5)).msecs())
Assertions.assertEquals(now.minus(T.days(5)).msecs(), nowMsecs - 5 * 24 * 60 * 60 * 1000) assertThat(nowMsecs - 5 * 24 * 60 * 60 * 1000).isEqualTo(now.minus(T.days(5)).msecs())
} }
} }