From a9abfbe3cfd4b43c3c4a87587201c45cc9ce0064 Mon Sep 17 00:00:00 2001 From: Ryan Haining Date: Mon, 18 Sep 2023 19:59:05 -0700 Subject: [PATCH 1/3] Rewrites HeartRateListenerTest with matchers Issue #2745 --- .../heartrate/HeartRateListenerTest.kt | 67 ++++++++++--------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/wear/src/test/java/info/nightscout/androidaps/heartrate/HeartRateListenerTest.kt b/wear/src/test/java/info/nightscout/androidaps/heartrate/HeartRateListenerTest.kt index 7b542b1afc..7daf20917e 100644 --- a/wear/src/test/java/info/nightscout/androidaps/heartrate/HeartRateListenerTest.kt +++ b/wear/src/test/java/info/nightscout/androidaps/heartrate/HeartRateListenerTest.kt @@ -3,14 +3,13 @@ package info.nightscout.androidaps.heartrate import android.content.Context import android.hardware.Sensor import android.hardware.SensorManager +import com.google.common.truth.Truth.assertThat import info.nightscout.rx.AapsSchedulers import info.nightscout.rx.logging.AAPSLoggerTest import info.nightscout.rx.weardata.EventData.ActionHeartRate import io.reactivex.rxjava3.core.Scheduler import io.reactivex.rxjava3.disposables.Disposable import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Assertions.assertNull import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.mockito.ArgumentMatchers.any @@ -22,8 +21,9 @@ import org.mockito.Mockito.`when` import java.util.concurrent.TimeUnit internal class HeartRateListenerTest { + private val aapsLogger = AAPSLoggerTest() - private val aapsSchedulers = object: AapsSchedulers { + private val aapsSchedulers = object : AapsSchedulers { override val main: Scheduler = mock(Scheduler::class.java) override val io: Scheduler = mock(Scheduler::class.java) override val cpu: Scheduler = mock(Scheduler::class.java) @@ -35,11 +35,15 @@ internal class HeartRateListenerTest { private fun create(timestampMillis: Long): HeartRateListener { val ctx = mock(Context::class.java) - `when`(aapsSchedulers.io.schedulePeriodicallyDirect( - any(), eq(60_000L), eq(60_000L), eq(TimeUnit.MILLISECONDS))).thenReturn(schedule) + `when`( + aapsSchedulers.io.schedulePeriodicallyDirect( + any(), eq(60_000L), eq(60_000L), eq(TimeUnit.MILLISECONDS) + ) + ).thenReturn(schedule) val listener = HeartRateListener(ctx, aapsLogger, aapsSchedulers, timestampMillis) verify(aapsSchedulers.io).schedulePeriodicallyDirect( - any(), eq(60_000L), eq(60_000L), eq(TimeUnit.MILLISECONDS)) + any(), eq(60_000L), eq(60_000L), eq(TimeUnit.MILLISECONDS) + ) listener.sendHeartRate = { hr -> heartRates.add(hr) } return listener } @@ -49,10 +53,11 @@ internal class HeartRateListenerTest { timestamp: Long, heartRate: Int, sensorType: Int? = Sensor.TYPE_HEART_RATE, - accuracy: Int = SensorManager.SENSOR_STATUS_ACCURACY_HIGH) { + accuracy: Int = SensorManager.SENSOR_STATUS_ACCURACY_HIGH + ) { listener.onSensorChanged(sensorType, accuracy, timestamp, floatArrayOf(heartRate.toFloat())) } - + @BeforeEach fun before() { heartRates.clear() @@ -66,7 +71,7 @@ internal class HeartRateListenerTest { Mockito.verifyNoInteractions(aapsSchedulers.newThread) verify(schedule).dispose() } - + @Test fun onSensorChanged() { val start = System.currentTimeMillis() @@ -74,14 +79,13 @@ internal class HeartRateListenerTest { val d2 = 20_000L val listener = create(start) - assertNull(listener.currentHeartRateBpm) + assertThat(listener.currentHeartRateBpm).isNull() sendSensorEvent(listener, start + d1, 80) - assertEquals(0, heartRates.size) - assertEquals(80, listener.currentHeartRateBpm) + assertThat(heartRates).isEmpty() + assertThat(listener.currentHeartRateBpm).isEqualTo(80) listener.send(start + d2) - assertEquals(1, heartRates.size) - assertEquals(ActionHeartRate(d2, start + d2, 80.0, device), heartRates.first()) + assertThat(heartRates).containsExactly(ActionHeartRate(d2, start + d2, 80.0, device)) listener.dispose() } @@ -93,16 +97,15 @@ internal class HeartRateListenerTest { val listener = create(start) sendSensorEvent(listener, start, 80) - assertEquals(0, heartRates.size) - assertEquals(80, listener.currentHeartRateBpm) - sendSensorEvent(listener, start + d1,100) - assertEquals(0, heartRates.size) - assertEquals(100, listener.currentHeartRateBpm) + assertThat(heartRates).isEmpty() + assertThat(listener.currentHeartRateBpm).isEqualTo(80) + sendSensorEvent(listener, start + d1, 100) + assertThat(heartRates).isEmpty() + assertThat(listener.currentHeartRateBpm).isEqualTo(100) listener.send(start + d2) - assertEquals(1, heartRates.size) - assertEquals(ActionHeartRate(d2, start + d2, 95.0, device), heartRates.first()) + assertThat(heartRates).containsExactly(ActionHeartRate(d2, start + d2, 95.0, device)) listener.dispose() } @@ -115,15 +118,15 @@ internal class HeartRateListenerTest { sendSensorEvent(listener, start, 80) listener.send(start + d1) - assertEquals(1, heartRates.size) + assertThat(heartRates).hasSize(1) - sendSensorEvent(listener, start + d1,100) - assertEquals(1, heartRates.size) + sendSensorEvent(listener, start + d1, 100) + assertThat(heartRates).hasSize(1) listener.send(start + d2) - assertEquals(2, heartRates.size) - - assertEquals(ActionHeartRate(d1, start + d1, 80.0, device), heartRates[0]) - assertEquals(ActionHeartRate(d2 - d1, start + d2, 100.0, device), heartRates[1]) + assertThat(heartRates).containsExactly( + ActionHeartRate(d1, start + d1, 80.0, device), + ActionHeartRate(d2 - d1, start + d2, 100.0, device), + ).inOrder() listener.dispose() } @@ -136,11 +139,10 @@ internal class HeartRateListenerTest { sendSensorEvent(listener, start, 80) sendSensorEvent(listener, start + d1, 100, accuracy = SensorManager.SENSOR_STATUS_NO_CONTACT) - assertNull(listener.currentHeartRateBpm) + assertThat(listener.currentHeartRateBpm).isNull() listener.send(start + d2) - assertEquals(1, heartRates.size) - assertEquals(ActionHeartRate(d2, start + d2, 80.0, device), heartRates.first()) + assertThat(heartRates).containsExactly(ActionHeartRate(d2, start + d2, 80.0, device)) listener.dispose() } @@ -157,8 +159,7 @@ internal class HeartRateListenerTest { sendSensorEvent(listener, start + d2, 100) listener.send(start + d3) - assertEquals(1, heartRates.size) - assertEquals(ActionHeartRate(d3, start + d3, 95.0, device), heartRates.first()) + assertThat(heartRates).containsExactly(ActionHeartRate(d3, start + d3, 95.0, device)) listener.dispose() } } From a42ef55cb037b113bc5a5480e752765442c415d7 Mon Sep 17 00:00:00 2001 From: Ryan Haining Date: Mon, 18 Sep 2023 20:16:58 -0700 Subject: [PATCH 2/3] Rewrites DisplayFormatTest with matchers Issue #2745 --- .../interaction/utils/DisplayFormatTest.kt | 222 +++++++++--------- 1 file changed, 111 insertions(+), 111 deletions(-) diff --git a/wear/src/test/java/info/nightscout/androidaps/interaction/utils/DisplayFormatTest.kt b/wear/src/test/java/info/nightscout/androidaps/interaction/utils/DisplayFormatTest.kt index e2a0934f21..e6dbf02680 100644 --- a/wear/src/test/java/info/nightscout/androidaps/interaction/utils/DisplayFormatTest.kt +++ b/wear/src/test/java/info/nightscout/androidaps/interaction/utils/DisplayFormatTest.kt @@ -1,10 +1,10 @@ package info.nightscout.androidaps.interaction.utils +import com.google.common.truth.Truth.assertThat import info.nightscout.androidaps.R import info.nightscout.androidaps.WearTestBase import info.nightscout.androidaps.data.RawDisplayData import info.nightscout.androidaps.testing.mockers.RawDataMocker -import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.mockito.Mockito @@ -32,142 +32,142 @@ class DisplayFormatTest : WearTestBase() { } @Test fun shortTimeSinceTest() { - Assertions.assertEquals(displayFormat.shortTimeSince(backInTime(0, 0, 0, 0)), "0'") - Assertions.assertEquals(displayFormat.shortTimeSince(backInTime(0, 0, 0, 5)), "0'") - Assertions.assertEquals(displayFormat.shortTimeSince(backInTime(0, 0, 0, 55)), "0'") - Assertions.assertEquals(displayFormat.shortTimeSince(backInTime(0, 0, 1, 0)), "1'") - Assertions.assertEquals(displayFormat.shortTimeSince(backInTime(0, 0, 1, 59)), "1'") - Assertions.assertEquals(displayFormat.shortTimeSince(backInTime(0, 0, 2, 0)), "2'") - Assertions.assertEquals(displayFormat.shortTimeSince(backInTime(0, 0, 3, 0)), "3'") - Assertions.assertEquals(displayFormat.shortTimeSince(backInTime(0, 0, 4, 0)), "4'") - Assertions.assertEquals(displayFormat.shortTimeSince(backInTime(0, 0, 10, 0)), "10'") - Assertions.assertEquals(displayFormat.shortTimeSince(backInTime(0, 0, 30, 0)), "30'") - Assertions.assertEquals(displayFormat.shortTimeSince(backInTime(0, 0, 59, 0)), "59'") - Assertions.assertEquals(displayFormat.shortTimeSince(backInTime(0, 0, 59, 59)), "59'") - Assertions.assertEquals(displayFormat.shortTimeSince(backInTime(0, 1, 0, 0)), "1h") - Assertions.assertEquals(displayFormat.shortTimeSince(backInTime(0, 1, 30, 0)), "1h") - Assertions.assertEquals(displayFormat.shortTimeSince(backInTime(0, 1, 59, 59)), "1h") - Assertions.assertEquals(displayFormat.shortTimeSince(backInTime(0, 2, 0, 0)), "2h") - Assertions.assertEquals(displayFormat.shortTimeSince(backInTime(0, 3, 0, 0)), "3h") - Assertions.assertEquals(displayFormat.shortTimeSince(backInTime(0, 4, 0, 0)), "4h") - Assertions.assertEquals(displayFormat.shortTimeSince(backInTime(0, 5, 0, 0)), "5h") - Assertions.assertEquals(displayFormat.shortTimeSince(backInTime(0, 12, 0, 0)), "12h") - Assertions.assertEquals(displayFormat.shortTimeSince(backInTime(0, 18, 0, 0)), "18h") - Assertions.assertEquals(displayFormat.shortTimeSince(backInTime(0, 23, 59, 59)), "23h") - Assertions.assertEquals(displayFormat.shortTimeSince(backInTime(1, 0, 0, 0)), "1d") - Assertions.assertEquals(displayFormat.shortTimeSince(backInTime(1, 12, 0, 0)), "1d") - Assertions.assertEquals(displayFormat.shortTimeSince(backInTime(1, 23, 59, 59)), "1d") - Assertions.assertEquals(displayFormat.shortTimeSince(backInTime(2, 0, 0, 0)), "2d") - Assertions.assertEquals(displayFormat.shortTimeSince(backInTime(3, 0, 0, 0)), "3d") - Assertions.assertEquals(displayFormat.shortTimeSince(backInTime(4, 0, 0, 0)), "4d") - Assertions.assertEquals(displayFormat.shortTimeSince(backInTime(5, 0, 0, 0)), "5d") - Assertions.assertEquals(displayFormat.shortTimeSince(backInTime(6, 0, 0, 0)), "6d") - Assertions.assertEquals(displayFormat.shortTimeSince(backInTime(6, 23, 59, 59)), "6d") - Assertions.assertEquals(displayFormat.shortTimeSince(backInTime(7, 0, 0, 0)), "1w") - Assertions.assertEquals(displayFormat.shortTimeSince(backInTime(8, 0, 0, 0)), "1w") - Assertions.assertEquals(displayFormat.shortTimeSince(backInTime(9, 0, 0, 0)), "1w") - Assertions.assertEquals(displayFormat.shortTimeSince(backInTime(13, 23, 59, 59)), "1w") - Assertions.assertEquals(displayFormat.shortTimeSince(backInTime(14, 0, 0, 0)), "2w") - Assertions.assertEquals(displayFormat.shortTimeSince(backInTime(21, 0, 0, 0)), "3w") - Assertions.assertEquals(displayFormat.shortTimeSince(backInTime(28, 0, 0, 0)), "4w") - Assertions.assertEquals(displayFormat.shortTimeSince(backInTime(31, 0, 0, 0)), "4w") - Assertions.assertEquals(displayFormat.shortTimeSince(backInTime(32, 0, 0, 0)), "4w") - Assertions.assertEquals(displayFormat.shortTimeSince(backInTime(35, 0, 0, 0)), "5w") - Assertions.assertEquals(displayFormat.shortTimeSince(backInTime(100, 0, 0, 0)), "14w") - Assertions.assertEquals(displayFormat.shortTimeSince(backInTime(200, 0, 0, 0)), "28w") - Assertions.assertEquals(displayFormat.shortTimeSince(backInTime(365, 0, 0, 0)), "52w") - Assertions.assertEquals(displayFormat.shortTimeSince(backInTime(366, 0, 0, 0)), "52w") - Assertions.assertEquals(displayFormat.shortTimeSince(backInTime(367, 0, 0, 0)), "52w") + assertThat(displayFormat.shortTimeSince(backInTime(0, 0, 0, 0))).isEqualTo("0'") + assertThat(displayFormat.shortTimeSince(backInTime(0, 0, 0, 5))).isEqualTo("0'") + assertThat(displayFormat.shortTimeSince(backInTime(0, 0, 0, 55))).isEqualTo("0'") + assertThat(displayFormat.shortTimeSince(backInTime(0, 0, 1, 0))).isEqualTo("1'") + assertThat(displayFormat.shortTimeSince(backInTime(0, 0, 1, 59))).isEqualTo("1'") + assertThat(displayFormat.shortTimeSince(backInTime(0, 0, 2, 0))).isEqualTo("2'") + assertThat(displayFormat.shortTimeSince(backInTime(0, 0, 3, 0))).isEqualTo("3'") + assertThat(displayFormat.shortTimeSince(backInTime(0, 0, 4, 0))).isEqualTo("4'") + assertThat(displayFormat.shortTimeSince(backInTime(0, 0, 10, 0))).isEqualTo("10'") + assertThat(displayFormat.shortTimeSince(backInTime(0, 0, 30, 0))).isEqualTo("30'") + assertThat(displayFormat.shortTimeSince(backInTime(0, 0, 59, 0))).isEqualTo("59'") + assertThat(displayFormat.shortTimeSince(backInTime(0, 0, 59, 59))).isEqualTo("59'") + assertThat(displayFormat.shortTimeSince(backInTime(0, 1, 0, 0))).isEqualTo("1h") + assertThat(displayFormat.shortTimeSince(backInTime(0, 1, 30, 0))).isEqualTo("1h") + assertThat(displayFormat.shortTimeSince(backInTime(0, 1, 59, 59))).isEqualTo("1h") + assertThat(displayFormat.shortTimeSince(backInTime(0, 2, 0, 0))).isEqualTo("2h") + assertThat(displayFormat.shortTimeSince(backInTime(0, 3, 0, 0))).isEqualTo("3h") + assertThat(displayFormat.shortTimeSince(backInTime(0, 4, 0, 0))).isEqualTo("4h") + assertThat(displayFormat.shortTimeSince(backInTime(0, 5, 0, 0))).isEqualTo("5h") + assertThat(displayFormat.shortTimeSince(backInTime(0, 12, 0, 0))).isEqualTo("12h") + assertThat(displayFormat.shortTimeSince(backInTime(0, 18, 0, 0))).isEqualTo("18h") + assertThat(displayFormat.shortTimeSince(backInTime(0, 23, 59, 59))).isEqualTo("23h") + assertThat(displayFormat.shortTimeSince(backInTime(1, 0, 0, 0))).isEqualTo("1d") + assertThat(displayFormat.shortTimeSince(backInTime(1, 12, 0, 0))).isEqualTo("1d") + assertThat(displayFormat.shortTimeSince(backInTime(1, 23, 59, 59))).isEqualTo("1d") + assertThat(displayFormat.shortTimeSince(backInTime(2, 0, 0, 0))).isEqualTo("2d") + assertThat(displayFormat.shortTimeSince(backInTime(3, 0, 0, 0))).isEqualTo("3d") + assertThat(displayFormat.shortTimeSince(backInTime(4, 0, 0, 0))).isEqualTo("4d") + assertThat(displayFormat.shortTimeSince(backInTime(5, 0, 0, 0))).isEqualTo("5d") + assertThat(displayFormat.shortTimeSince(backInTime(6, 0, 0, 0))).isEqualTo("6d") + assertThat(displayFormat.shortTimeSince(backInTime(6, 23, 59, 59))).isEqualTo("6d") + assertThat(displayFormat.shortTimeSince(backInTime(7, 0, 0, 0))).isEqualTo("1w") + assertThat(displayFormat.shortTimeSince(backInTime(8, 0, 0, 0))).isEqualTo("1w") + assertThat(displayFormat.shortTimeSince(backInTime(9, 0, 0, 0))).isEqualTo("1w") + assertThat(displayFormat.shortTimeSince(backInTime(13, 23, 59, 59))).isEqualTo("1w") + assertThat(displayFormat.shortTimeSince(backInTime(14, 0, 0, 0))).isEqualTo("2w") + assertThat(displayFormat.shortTimeSince(backInTime(21, 0, 0, 0))).isEqualTo("3w") + assertThat(displayFormat.shortTimeSince(backInTime(28, 0, 0, 0))).isEqualTo("4w") + assertThat(displayFormat.shortTimeSince(backInTime(31, 0, 0, 0))).isEqualTo("4w") + assertThat(displayFormat.shortTimeSince(backInTime(32, 0, 0, 0))).isEqualTo("4w") + assertThat(displayFormat.shortTimeSince(backInTime(35, 0, 0, 0))).isEqualTo("5w") + assertThat(displayFormat.shortTimeSince(backInTime(100, 0, 0, 0))).isEqualTo("14w") + assertThat(displayFormat.shortTimeSince(backInTime(200, 0, 0, 0))).isEqualTo("28w") + assertThat(displayFormat.shortTimeSince(backInTime(365, 0, 0, 0))).isEqualTo("52w") + assertThat(displayFormat.shortTimeSince(backInTime(366, 0, 0, 0))).isEqualTo("52w") + assertThat(displayFormat.shortTimeSince(backInTime(367, 0, 0, 0))).isEqualTo("52w") } @Test fun shortTrendTest() { val raw = RawDisplayData() - Assertions.assertEquals(displayFormat.shortTrend(raw), "-- Δ--") + assertThat(displayFormat.shortTrend(raw)).isEqualTo("-- Δ--") raw.singleBg.timeStamp = backInTime(0, 0, 2, 0) - Assertions.assertEquals(displayFormat.shortTrend(raw), "2' Δ--") + assertThat(displayFormat.shortTrend(raw)).isEqualTo("2' Δ--") Mockito.`when`(sp.getBoolean("complication_unicode", true)).thenReturn(true) // shortening - Assertions.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(2, "1.2")), "2' Δ1.2") - Assertions.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(11, "1.2")), "11' 1.2") - Assertions.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(12, "0.7")), "12' Δ.7") - Assertions.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(10, "1.0")), "10' Δ1") - Assertions.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(14, "-5.0")), "14' Δ-5") - Assertions.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(13, "-5.1")), "13' -5") - Assertions.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(15, "0.87")), "15' .87") - Assertions.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(10, "-1.78")), "10' -2") - Assertions.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(3, "2.549")), "3' 2.55") - Assertions.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(1, "-1.563")), "1' -1.6") + assertThat(displayFormat.shortTrend(rawDataMocker.rawDelta(2, "1.2"))).isEqualTo("2' Δ1.2") + assertThat(displayFormat.shortTrend(rawDataMocker.rawDelta(11, "1.2"))).isEqualTo("11' 1.2") + assertThat(displayFormat.shortTrend(rawDataMocker.rawDelta(12, "0.7"))).isEqualTo("12' Δ.7") + assertThat(displayFormat.shortTrend(rawDataMocker.rawDelta(10, "1.0"))).isEqualTo("10' Δ1") + assertThat(displayFormat.shortTrend(rawDataMocker.rawDelta(14, "-5.0"))).isEqualTo("14' Δ-5") + assertThat(displayFormat.shortTrend(rawDataMocker.rawDelta(13, "-5.1"))).isEqualTo("13' -5") + assertThat(displayFormat.shortTrend(rawDataMocker.rawDelta(15, "0.87"))).isEqualTo("15' .87") + assertThat(displayFormat.shortTrend(rawDataMocker.rawDelta(10, "-1.78"))).isEqualTo("10' -2") + assertThat(displayFormat.shortTrend(rawDataMocker.rawDelta(3, "2.549"))).isEqualTo("3' 2.55") + assertThat(displayFormat.shortTrend(rawDataMocker.rawDelta(1, "-1.563"))).isEqualTo("1' -1.6") // preserving separator - Assertions.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(2, "1,2")), "2' Δ1,2") - Assertions.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(15, "0,87")), "15' ,87") - Assertions.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(3, "+2,549")), "3' 2,55") - Assertions.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(1, "-1,563")), "1' -1,6") + assertThat(displayFormat.shortTrend(rawDataMocker.rawDelta(2, "1,2"))).isEqualTo("2' Δ1,2") + assertThat(displayFormat.shortTrend(rawDataMocker.rawDelta(15, "0,87"))).isEqualTo("15' ,87") + assertThat(displayFormat.shortTrend(rawDataMocker.rawDelta(3, "+2,549"))).isEqualTo("3' 2,55") + assertThat(displayFormat.shortTrend(rawDataMocker.rawDelta(1, "-1,563"))).isEqualTo("1' -1,6") // UTF-off mode - without delta symbol Mockito.`when`(sp.getBoolean("complication_unicode", true)).thenReturn(false) - Assertions.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(2, "1.2")), "2' 1.2") - Assertions.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(12, "0.7")), "12' 0.7") - Assertions.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(10, "1.0")), "10' 1.0") - Assertions.assertEquals(displayFormat.shortTrend(rawDataMocker.rawDelta(14, "-5.0")), "14' -5") + assertThat(displayFormat.shortTrend(rawDataMocker.rawDelta(2, "1.2"))).isEqualTo("2' 1.2") + assertThat(displayFormat.shortTrend(rawDataMocker.rawDelta(12, "0.7"))).isEqualTo("12' 0.7") + assertThat(displayFormat.shortTrend(rawDataMocker.rawDelta(10, "1.0"))).isEqualTo("10' 1.0") + assertThat(displayFormat.shortTrend(rawDataMocker.rawDelta(14, "-5.0"))).isEqualTo("14' -5") } @Test fun longGlucoseLine() { - Assertions.assertEquals(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("125", 2, "1.2")), "125→ Δ1.2 (2')") - Assertions.assertEquals(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("97", 11, "5.2")), "97↗ Δ5.2 (11')") - Assertions.assertEquals(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("110", 12, "0.7")), "110→ Δ.7 (12')") - Assertions.assertEquals(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("65", 10, "7.0")), "65↗ Δ7 (10')") - Assertions.assertEquals(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("215", 14, "-5.0")), "215↘ Δ-5 (14')") - Assertions.assertEquals(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("8.3", 13, "-5.1")), "8.3↘ Δ-5.1 (13')") - Assertions.assertEquals(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("6.8", 15, "10.83")), "6.8↑ Δ10.83 (15')") - Assertions.assertEquals(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("13.2", 10, "-11.78")), "13.2↓ Δ-11.78 (10')") - Assertions.assertEquals(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("3.9", 3, "2.549")), "3.9→ Δ2.549 (3')") - Assertions.assertEquals(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("11.1", 1, "-15.563")), "11.1↓ Δ-15.563 (1')") + assertThat(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("125", 2, "1.2"))).isEqualTo("125→ Δ1.2 (2')") + assertThat(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("97", 11, "5.2"))).isEqualTo("97↗ Δ5.2 (11')") + assertThat(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("110", 12, "0.7"))).isEqualTo("110→ Δ.7 (12')") + assertThat(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("65", 10, "7.0"))).isEqualTo("65↗ Δ7 (10')") + assertThat(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("215", 14, "-5.0"))).isEqualTo("215↘ Δ-5 (14')") + assertThat(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("8.3", 13, "-5.1"))).isEqualTo("8.3↘ Δ-5.1 (13')") + assertThat(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("6.8", 15, "10.83"))).isEqualTo("6.8↑ Δ10.83 (15')") + assertThat(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("13.2", 10, "-11.78"))).isEqualTo("13.2↓ Δ-11.78 (10')") + assertThat(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("3.9", 3, "2.549"))).isEqualTo("3.9→ Δ2.549 (3')") + assertThat(displayFormat.longGlucoseLine(rawDataMocker.rawSgv("11.1", 1, "-15.563"))).isEqualTo("11.1↓ Δ-15.563 (1')") } @Test fun longDetailsLineTest() { Mockito.`when`(sp.getBoolean("complication_unicode", true)).thenReturn(true) - Assertions.assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("0g", "0U", "3.5U/h")), "0g ⁞ 0U ⁞ ⎍ 3.5U/h") - Assertions.assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("50g", "7.56U", "0%")), "50g ⁞ 7.56U ⁞ ⎍ 0%") - Assertions.assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("12g", "3.23U", "120%")), "12g ⁞ 3.23U ⁞ 120%") - Assertions.assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("2(40)g", "-1.5U", "0.55U/h")), "2(40)g ⁞ -2U ⁞ 0.55U/h") - Assertions.assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("0(24)g", "0.05U", "160%")), "0(24)g ⁞ 0.05U ⁞ 160%") - Assertions.assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("47g", "13.87U", "220%")), "47g ⁞ 13.87U ⁞ 220%") - Assertions.assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("13(5)g", "5.90U", "300%")), "13(5)g ⁞ 5.90U ⁞ 300%") - Assertions.assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("11(50)g", "0U", "70%")), "11(50)g ⁞ 0U ⁞ 70%") - Assertions.assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("7g", "0.54U", "30%")), "7g ⁞ 0.54U ⁞ ⎍ 30%") - Assertions.assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("19(38)g", "35.545U", "12.9U/h")), "19g ⁞ 36U ⁞ 12.9U/h") - Assertions.assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("100(1)g", "12.345U", "6.98647U/h")), "100g 12U 6.98647U/h") + assertThat(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("0g", "0U", "3.5U/h"))).isEqualTo("0g ⁞ 0U ⁞ ⎍ 3.5U/h") + assertThat(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("50g", "7.56U", "0%"))).isEqualTo("50g ⁞ 7.56U ⁞ ⎍ 0%") + assertThat(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("12g", "3.23U", "120%"))).isEqualTo("12g ⁞ 3.23U ⁞ 120%") + assertThat(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("2(40)g", "-1.5U", "0.55U/h"))).isEqualTo("2(40)g ⁞ -2U ⁞ 0.55U/h") + assertThat(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("0(24)g", "0.05U", "160%"))).isEqualTo("0(24)g ⁞ 0.05U ⁞ 160%") + assertThat(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("47g", "13.87U", "220%"))).isEqualTo("47g ⁞ 13.87U ⁞ 220%") + assertThat(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("13(5)g", "5.90U", "300%"))).isEqualTo("13(5)g ⁞ 5.90U ⁞ 300%") + assertThat(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("11(50)g", "0U", "70%"))).isEqualTo("11(50)g ⁞ 0U ⁞ 70%") + assertThat(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("7g", "0.54U", "30%"))).isEqualTo("7g ⁞ 0.54U ⁞ ⎍ 30%") + assertThat(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("19(38)g", "35.545U", "12.9U/h"))).isEqualTo("19g ⁞ 36U ⁞ 12.9U/h") + assertThat(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("100(1)g", "12.345U", "6.98647U/h"))).isEqualTo("100g 12U 6.98647U/h") Mockito.`when`(sp.getBoolean("complication_unicode", true)).thenReturn(false) - Assertions.assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("0g", "0U", "3.5U/h")), "0g | 0U | 3.5U/h") - Assertions.assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("50g", "7.56U", "0%")), "50g | 7.56U | 0%") - Assertions.assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("12g", "3.23U", "120%")), "12g | 3.23U | 120%") - Assertions.assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("7g", "0.54U", "30%")), "7g | 0.54U | 30%") - Assertions.assertEquals(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("19(38)g", "35.545U", "12.9U/h")), "19g | 36U | 12.9U/h") + assertThat(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("0g", "0U", "3.5U/h"))).isEqualTo("0g | 0U | 3.5U/h") + assertThat(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("50g", "7.56U", "0%"))).isEqualTo("50g | 7.56U | 0%") + assertThat(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("12g", "3.23U", "120%"))).isEqualTo("12g | 3.23U | 120%") + assertThat(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("7g", "0.54U", "30%"))).isEqualTo("7g | 0.54U | 30%") + assertThat(displayFormat.longDetailsLine(rawDataMocker.rawCobIobBr("19(38)g", "35.545U", "12.9U/h"))).isEqualTo("19g | 36U | 12.9U/h") } @Test fun detailedIobTest() { - Assertions.assertEquals(displayFormat.detailedIob(rawDataMocker.rawIob("-1.29U", "(0,910|-2,20)")), Pair.create("-1.29U", ",91 -2")) - Assertions.assertEquals(displayFormat.detailedIob(rawDataMocker.rawIob("3.50U", "")), Pair.create("3.50U", "")) - Assertions.assertEquals(displayFormat.detailedIob(rawDataMocker.rawIob("12.5U", "(+1,4|-4.78)")), Pair.create("12.5U", "1,4 -5")) - Assertions.assertEquals(displayFormat.detailedIob(rawDataMocker.rawIob("0.67U", "some junks")), Pair.create(".67U", "")) - Assertions.assertEquals(displayFormat.detailedIob(rawDataMocker.rawIob("-11.0U", "(broken|data)")), Pair.create("-11U", "-- --")) - Assertions.assertEquals(displayFormat.detailedIob(rawDataMocker.rawIob("5.52U", "(0,5439|wrong)")), Pair.create("5.52U", ",54 --")) - Assertions.assertEquals(displayFormat.detailedIob(rawDataMocker.rawIob("-8.1U", "(|-8,1)")), Pair.create("-8.1U", "-- -8")) - Assertions.assertEquals(displayFormat.detailedIob(rawDataMocker.rawIob("-8.1U", "(|-8,1)")), Pair.create("-8.1U", "-- -8")) - Assertions.assertEquals(displayFormat.detailedIob(rawDataMocker.rawIob("7.6U", "(malformed)")), Pair.create("7.6U", "")) - Assertions.assertEquals(displayFormat.detailedIob(rawDataMocker.rawIob("-4.26U", "(6,97|1,3422|too much)")), Pair.create("-4.26U", "7 1,3")) + assertThat(displayFormat.detailedIob(rawDataMocker.rawIob("-1.29U", "(0,910|-2,20)"))).isEqualTo(Pair.create("-1.29U", ",91 -2")) + assertThat(displayFormat.detailedIob(rawDataMocker.rawIob("3.50U", ""))).isEqualTo(Pair.create("3.50U", "")) + assertThat(displayFormat.detailedIob(rawDataMocker.rawIob("12.5U", "(+1,4|-4.78)"))).isEqualTo(Pair.create("12.5U", "1,4 -5")) + assertThat(displayFormat.detailedIob(rawDataMocker.rawIob("0.67U", "some junks"))).isEqualTo(Pair.create(".67U", "")) + assertThat(displayFormat.detailedIob(rawDataMocker.rawIob("-11.0U", "(broken|data)"))).isEqualTo(Pair.create("-11U", "-- --")) + assertThat(displayFormat.detailedIob(rawDataMocker.rawIob("5.52U", "(0,5439|wrong)"))).isEqualTo(Pair.create("5.52U", ",54 --")) + assertThat(displayFormat.detailedIob(rawDataMocker.rawIob("-8.1U", "(|-8,1)"))).isEqualTo(Pair.create("-8.1U", "-- -8")) + assertThat(displayFormat.detailedIob(rawDataMocker.rawIob("-8.1U", "(|-8,1)"))).isEqualTo(Pair.create("-8.1U", "-- -8")) + assertThat(displayFormat.detailedIob(rawDataMocker.rawIob("7.6U", "(malformed)"))).isEqualTo(Pair.create("7.6U", "")) + assertThat(displayFormat.detailedIob(rawDataMocker.rawIob("-4.26U", "(6,97|1,3422|too much)"))).isEqualTo(Pair.create("-4.26U", "7 1,3")) } @Test fun detailedCobTest() { - Assertions.assertEquals(displayFormat.detailedCob(rawDataMocker.rawCob("0g")), Pair.create("0g", "")) - Assertions.assertEquals(displayFormat.detailedCob(rawDataMocker.rawCob("50g")), Pair.create("50g", "")) - Assertions.assertEquals(displayFormat.detailedCob(rawDataMocker.rawCob("2(40)g")), Pair.create("2g", "40g")) - Assertions.assertEquals(displayFormat.detailedCob(rawDataMocker.rawCob("0(24)g")), Pair.create("0g", "24g")) - Assertions.assertEquals(displayFormat.detailedCob(rawDataMocker.rawCob("13(5)g")), Pair.create("13g", "5g")) - Assertions.assertEquals(displayFormat.detailedCob(rawDataMocker.rawCob("11(50)g")), Pair.create("11g", "50g")) - Assertions.assertEquals(displayFormat.detailedCob(rawDataMocker.rawCob("19(38)g")), Pair.create("19g", "38g")) - Assertions.assertEquals(displayFormat.detailedCob(rawDataMocker.rawCob("100(1)g")), Pair.create("100g", "1g")) + assertThat(displayFormat.detailedCob(rawDataMocker.rawCob("0g"))).isEqualTo(Pair.create("0g", "")) + assertThat(displayFormat.detailedCob(rawDataMocker.rawCob("50g"))).isEqualTo(Pair.create("50g", "")) + assertThat(displayFormat.detailedCob(rawDataMocker.rawCob("2(40)g"))).isEqualTo(Pair.create("2g", "40g")) + assertThat(displayFormat.detailedCob(rawDataMocker.rawCob("0(24)g"))).isEqualTo(Pair.create("0g", "24g")) + assertThat(displayFormat.detailedCob(rawDataMocker.rawCob("13(5)g"))).isEqualTo(Pair.create("13g", "5g")) + assertThat(displayFormat.detailedCob(rawDataMocker.rawCob("11(50)g"))).isEqualTo(Pair.create("11g", "50g")) + assertThat(displayFormat.detailedCob(rawDataMocker.rawCob("19(38)g"))).isEqualTo(Pair.create("19g", "38g")) + assertThat(displayFormat.detailedCob(rawDataMocker.rawCob("100(1)g"))).isEqualTo(Pair.create("100g", "1g")) } } From fa49e3e152e9d73d1f00b7a213d392cf8c7ce7f3 Mon Sep 17 00:00:00 2001 From: Ryan Haining Date: Mon, 18 Sep 2023 20:23:29 -0700 Subject: [PATCH 3/3] Rewrites PairTest with matchers Issue #2745 --- .../androidaps/interaction/utils/PairTest.kt | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/wear/src/test/java/info/nightscout/androidaps/interaction/utils/PairTest.kt b/wear/src/test/java/info/nightscout/androidaps/interaction/utils/PairTest.kt index 4f4d782bc6..f678e9f871 100644 --- a/wear/src/test/java/info/nightscout/androidaps/interaction/utils/PairTest.kt +++ b/wear/src/test/java/info/nightscout/androidaps/interaction/utils/PairTest.kt @@ -1,7 +1,6 @@ package info.nightscout.androidaps.interaction.utils import com.google.common.truth.Truth.assertThat -import org.junit.Assert import org.junit.jupiter.api.Test class PairTest { @@ -19,14 +18,14 @@ class PairTest { val no4: Pair<*, *> = Pair.create(12, 345L) // THEN - Assert.assertNotEquals(left, right) - Assert.assertEquals(left, another) - Assert.assertNotEquals(left, samePos1) - Assert.assertNotEquals(left, samePos2) - Assert.assertNotEquals(no1, no2) - Assert.assertNotEquals(no1, no3) - Assert.assertEquals(no1, no4) - Assert.assertNotEquals("aa bbb", left.toString()) + assertThat(right).isNotEqualTo(left) + assertThat(another).isEqualTo(left) + assertThat(samePos1).isNotEqualTo(left) + assertThat(samePos2).isNotEqualTo(left) + assertThat(no2).isNotEqualTo(no1) + assertThat(no3).isNotEqualTo(no1) + assertThat(no4).isEqualTo(no1) + assertThat(left.toString()).isNotEqualTo("aa bbb") } @Test fun pairHashTest() { @@ -46,4 +45,4 @@ class PairTest { assertThat(pair.toString()).contains("the-first") assertThat(pair.toString()).contains("2nd") } -} \ No newline at end of file +}