From 8b85e00953ff3647f81250b556020124079d411f Mon Sep 17 00:00:00 2001 From: Ryan Haining Date: Sun, 8 Oct 2023 17:25:32 -0700 Subject: [PATCH] Rewrites NotificationPacketTest with matchers Issue #2745 --- .../comm/packets/NotificationPacketTest.kt | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/pump/medtrum/src/test/java/info/nightscout/pump/medtrum/comm/packets/NotificationPacketTest.kt b/pump/medtrum/src/test/java/info/nightscout/pump/medtrum/comm/packets/NotificationPacketTest.kt index 7e17be2c76..90664ee302 100644 --- a/pump/medtrum/src/test/java/info/nightscout/pump/medtrum/comm/packets/NotificationPacketTest.kt +++ b/pump/medtrum/src/test/java/info/nightscout/pump/medtrum/comm/packets/NotificationPacketTest.kt @@ -1,12 +1,12 @@ package info.nightscout.pump.medtrum.comm.packets import app.aaps.core.interfaces.rx.events.EventOverviewBolusProgress +import com.google.common.truth.Truth.assertThat import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector import info.nightscout.pump.medtrum.MedtrumTestBase import info.nightscout.pump.medtrum.comm.enums.BasalType import info.nightscout.pump.medtrum.comm.enums.MedtrumPumpState -import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Test class NotificationPacketTest : MedtrumTestBase() { @@ -30,7 +30,7 @@ class NotificationPacketTest : MedtrumTestBase() { NotificationPacket(packetInjector).handleNotification(byteArrayOf(state)) // Expected values - Assertions.assertEquals(medtrumPump.pumpState, MedtrumPumpState.fromByte(state)) + assertThat(MedtrumPumpState.fromByte(state)).isEqualTo(medtrumPump.pumpState) } @Test fun handleNotificationGivenBasalDataThenDataSaved() { @@ -41,12 +41,12 @@ class NotificationPacketTest : MedtrumTestBase() { NotificationPacket(packetInjector).handleNotification(data) // Expected values - Assertions.assertEquals(BasalType.ABSOLUTE_TEMP, medtrumPump.lastBasalType) - Assertions.assertEquals(0.85, medtrumPump.lastBasalRate, 0.01) - Assertions.assertEquals(25, medtrumPump.lastBasalSequence) - Assertions.assertEquals(14, medtrumPump.lastBasalPatchId) - Assertions.assertEquals(1685126612000, medtrumPump.lastBasalStartTime) - Assertions.assertEquals(186.80, medtrumPump.reservoir, 0.01) + assertThat(medtrumPump.lastBasalType).isEqualTo(BasalType.ABSOLUTE_TEMP) + assertThat(medtrumPump.lastBasalRate).isWithin(0.01).of(0.85) + assertThat(medtrumPump.lastBasalSequence).isEqualTo(25) + assertThat(medtrumPump.lastBasalPatchId).isEqualTo(14) + assertThat(medtrumPump.lastBasalStartTime).isEqualTo(1685126612000) + assertThat(medtrumPump.reservoir).isWithin(0.01).of(186.80) } @Test fun handleNotificationGivenSequenceAndOtherDataThenDataSaved() { @@ -57,7 +57,7 @@ class NotificationPacketTest : MedtrumTestBase() { NotificationPacket(packetInjector).handleNotification(data) // Expected values - Assertions.assertEquals(167, medtrumPump.currentSequenceNumber) + assertThat(medtrumPump.currentSequenceNumber).isEqualTo(167) } @Test fun handleNotificationGivenBolusInProgressThenDataSaved() { @@ -69,9 +69,9 @@ class NotificationPacketTest : MedtrumTestBase() { NotificationPacket(packetInjector).handleNotification(data) // Expected values - Assertions.assertEquals(false, medtrumPump.bolusDone) - Assertions.assertEquals(0.15, medtrumPump.bolusingTreatment!!.insulin, 0.01) - Assertions.assertEquals(163.5, medtrumPump.reservoir, 0.01) + assertThat(medtrumPump.bolusDone).isFalse() + assertThat(medtrumPump.bolusingTreatment!!.insulin).isWithin(0.01).of(0.15) + assertThat(medtrumPump.reservoir).isWithin(0.01).of(163.5) } @Test fun handleNotificationGivenBolusFinishedThenDataSaved() { @@ -83,8 +83,8 @@ class NotificationPacketTest : MedtrumTestBase() { NotificationPacket(packetInjector).handleNotification(data) // Expected values - Assertions.assertEquals(true, medtrumPump.bolusDone) - Assertions.assertEquals(1.65, medtrumPump.bolusingTreatment!!.insulin, 0.01) - Assertions.assertEquals(161.95, medtrumPump.reservoir, 0.01) + assertThat(medtrumPump.bolusDone).isTrue() + assertThat(medtrumPump.bolusingTreatment!!.insulin).isWithin(0.01).of(1.65) + assertThat(medtrumPump.reservoir).isWithin(0.01).of(161.95) } }