From 788eff46829b46896af39c23e16c6d00b60c354f Mon Sep 17 00:00:00 2001 From: Ryan Haining Date: Fri, 8 Sep 2023 19:21:52 -0700 Subject: [PATCH] Rewrites TTest with matchers Issue #2745 --- .../java/info/nightscout/core/utils/TTest.kt | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/core/main/src/test/java/info/nightscout/core/utils/TTest.kt b/core/main/src/test/java/info/nightscout/core/utils/TTest.kt index fd35265c9c..bf067c9c21 100644 --- a/core/main/src/test/java/info/nightscout/core/utils/TTest.kt +++ b/core/main/src/test/java/info/nightscout/core/utils/TTest.kt @@ -1,7 +1,7 @@ package info.nightscout.core.utils +import com.google.common.truth.Truth.assertThat import info.nightscout.shared.utils.T -import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Test import kotlin.math.abs @@ -9,33 +9,33 @@ import kotlin.math.abs class TTest { @Test fun toUnits() { - Assertions.assertEquals(1, T.msecs(1000).secs()) - Assertions.assertEquals(1, T.secs(60).mins()) - Assertions.assertEquals(1, T.mins(60).hours()) - Assertions.assertEquals(1, T.hours(24).days()) - Assertions.assertEquals(24, T.days(1).hours()) - Assertions.assertEquals(60000, T.mins(1).msecs()) + assertThat(T.msecs(1000).secs()).isEqualTo(1) + assertThat(T.secs(60).mins()).isEqualTo(1) + assertThat(T.mins(60).hours()).isEqualTo(1) + assertThat(T.hours(24).days()).isEqualTo(1) + assertThat(T.days(1).hours()).isEqualTo(24) + assertThat(T.mins(1).msecs()).isEqualTo(60000) } @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() { val nowMsecs = System.currentTimeMillis() val now = T.msecs(nowMsecs) - Assertions.assertEquals(now.plus(T.secs(5)).msecs(), nowMsecs + 5 * 1000) - Assertions.assertEquals(now.plus(T.mins(5)).msecs(), nowMsecs + 5 * 60 * 1000) - Assertions.assertEquals(now.plus(T.hours(5)).msecs(), nowMsecs + 5 * 60 * 60 * 1000) - Assertions.assertEquals(now.plus(T.days(5)).msecs(), nowMsecs + 5 * 24 * 60 * 60 * 1000) + assertThat(nowMsecs + 5 * 1000).isEqualTo(now.plus(T.secs(5)).msecs()) + assertThat(nowMsecs + 5 * 60 * 1000).isEqualTo(now.plus(T.mins(5)).msecs()) + assertThat(nowMsecs + 5 * 60 * 60 * 1000).isEqualTo(now.plus(T.hours(5)).msecs()) + assertThat(nowMsecs + 5 * 24 * 60 * 60 * 1000).isEqualTo(now.plus(T.days(5)).msecs()) } @Test fun subtractions() { val nowMsecs = System.currentTimeMillis() val now = T.msecs(nowMsecs) - Assertions.assertEquals(now.minus(T.secs(5)).msecs(), nowMsecs - 5 * 1000) - Assertions.assertEquals(now.minus(T.mins(5)).msecs(), nowMsecs - 5 * 60 * 1000) - Assertions.assertEquals(now.minus(T.hours(5)).msecs(), nowMsecs - 5 * 60 * 60 * 1000) - Assertions.assertEquals(now.minus(T.days(5)).msecs(), nowMsecs - 5 * 24 * 60 * 60 * 1000) + assertThat(nowMsecs - 5 * 1000).isEqualTo(now.minus(T.secs(5)).msecs()) + assertThat(nowMsecs - 5 * 60 * 1000).isEqualTo(now.minus(T.mins(5)).msecs()) + assertThat(nowMsecs - 5 * 60 * 60 * 1000).isEqualTo(now.minus(T.hours(5)).msecs()) + assertThat(nowMsecs - 5 * 24 * 60 * 60 * 1000).isEqualTo(now.minus(T.days(5)).msecs()) } -} \ No newline at end of file +}