From df233bbb81b4395ab8da58f7316bedd98238e76b Mon Sep 17 00:00:00 2001 From: Ryan Haining Date: Thu, 5 Oct 2023 22:52:31 -0700 Subject: [PATCH] Rewrites OmnipodErosPumpPluginTest with matchers Issue #2745 --- .../omnipod/eros/OmnipodErosPumpPluginTest.kt | 48 +++++++++---------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/pump/omnipod-eros/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/OmnipodErosPumpPluginTest.kt b/pump/omnipod-eros/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/OmnipodErosPumpPluginTest.kt index a9f079cc50..e006ffd4d4 100644 --- a/pump/omnipod-eros/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/OmnipodErosPumpPluginTest.kt +++ b/pump/omnipod-eros/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/OmnipodErosPumpPluginTest.kt @@ -11,6 +11,7 @@ import app.aaps.core.interfaces.utils.DecimalFormatter import app.aaps.implementation.utils.DecimalFormatterImpl import app.aaps.shared.tests.TestBase import app.aaps.shared.tests.rx.TestAapsSchedulers +import com.google.common.truth.Truth.assertThat import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil @@ -19,7 +20,6 @@ import info.nightscout.androidaps.plugins.pump.omnipod.eros.manager.AapsOmnipodE import info.nightscout.pump.common.defs.TempBasalPair import org.joda.time.DateTimeZone import org.joda.time.tz.UTCProvider -import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.mockito.ArgumentMatchers @@ -100,17 +100,17 @@ class OmnipodErosPumpPluginTest : TestBase() { val result5 = plugin.setTempBasalPercent(-50, 60, profile, false, PumpSync.TemporaryBasalType.NORMAL) // Then return correct values - Assertions.assertEquals(result1.absolute, 0.4, 0.01) - Assertions.assertEquals(result1.duration, 30) - Assertions.assertEquals(result2.absolute, 25.0, 0.01) - Assertions.assertEquals(result2.duration, 30000) - Assertions.assertEquals(result3.absolute, 0.0, 0.01) - Assertions.assertEquals(result3.duration, 30) - Assertions.assertEquals(result4.absolute, -1.0, 0.01) - Assertions.assertEquals(result4.duration, -1) + assertThat(result1.absolute).isWithin(0.01).of(0.4) + assertThat(result1.duration).isEqualTo(30) + assertThat(result2.absolute).isWithin(0.01).of(25.0) + assertThat(result2.duration).isEqualTo(30000) + assertThat(result3.absolute).isWithin(0.01).of(0.0) + assertThat(result3.duration).isEqualTo(30) + assertThat(result4.absolute).isWithin(0.01).of(-1.0) + assertThat(result4.duration).isEqualTo(-1) // this is validated downstream, see TempBasalExtraCommand - Assertions.assertEquals(result5.absolute, -0.25, 0.01) - Assertions.assertEquals(result5.duration, 60) + assertThat(result5.absolute).isWithin(0.01).of(-0.25) + assertThat(result5.duration).isEqualTo(60) // Given zero basal `when`(profile.getBasal()).thenReturn(0.0) @@ -120,10 +120,10 @@ class OmnipodErosPumpPluginTest : TestBase() { result2 = plugin.setTempBasalPercent(0, 0, profile, false, PumpSync.TemporaryBasalType.NORMAL) // Then return zero values - Assertions.assertEquals(result1.absolute, 0.0, 0.01) - Assertions.assertEquals(result1.duration, 90) - Assertions.assertEquals(result2.absolute, -1.0, 0.01) - Assertions.assertEquals(result2.duration, -1) + assertThat(result1.absolute).isWithin(0.01).of(0.0) + assertThat(result1.duration).isEqualTo(90) + assertThat(result2.absolute).isWithin(0.01).of(-1.0) + assertThat(result2.duration).isEqualTo(-1) // Given unhealthy basal `when`(profile.getBasal()).thenReturn(500.0) @@ -131,12 +131,10 @@ class OmnipodErosPumpPluginTest : TestBase() { result1 = plugin.setTempBasalPercent(80, 30, profile, false, PumpSync.TemporaryBasalType.NORMAL) // Then return sane values - Assertions.assertEquals( - result1.absolute, - PumpType.OMNIPOD_EROS.determineCorrectBasalSize(500.0 * 0.8), - 0.01 + assertThat(result1.absolute).isWithin(0.01).of( + PumpType.OMNIPOD_EROS.determineCorrectBasalSize(500.0 * 0.8) ) - Assertions.assertEquals(result1.duration, 30) + assertThat(result1.duration).isEqualTo(30) // Given weird basal `when`(profile.getBasal()).thenReturn(1.234567) @@ -144,8 +142,8 @@ class OmnipodErosPumpPluginTest : TestBase() { result1 = plugin.setTempBasalPercent(280, 600, profile, false, PumpSync.TemporaryBasalType.NORMAL) // Then return sane values - Assertions.assertEquals(result1.absolute, 3.4567876, 0.01) - Assertions.assertEquals(result1.duration, 600) + assertThat(result1.absolute).isWithin(0.01).of(3.4567876) + assertThat(result1.duration).isEqualTo(600) // Given negative basal `when`(profile.getBasal()).thenReturn(-1.234567) @@ -153,7 +151,7 @@ class OmnipodErosPumpPluginTest : TestBase() { result1 = plugin.setTempBasalPercent(280, 510, profile, false, PumpSync.TemporaryBasalType.NORMAL) // Then return negative value (this is validated further downstream, see TempBasalExtraCommand) - Assertions.assertEquals(result1.absolute, -3.4567876, 0.01) - Assertions.assertEquals(result1.duration, 510) + assertThat(result1.absolute).isWithin(0.01).of(-3.4567876) + assertThat(result1.duration).isEqualTo(510) } -} \ No newline at end of file +}