Rewrites MedtrumPumpTest with matchers

Issue #2745
This commit is contained in:
Ryan Haining 2023-10-08 16:37:51 -07:00
parent 85532a0332
commit 4d7897dace

View file

@ -7,10 +7,10 @@ import app.aaps.core.interfaces.pump.PumpSync
import app.aaps.core.interfaces.pump.defs.PumpType import app.aaps.core.interfaces.pump.defs.PumpType
import app.aaps.core.interfaces.rx.events.EventOverviewBolusProgress import app.aaps.core.interfaces.rx.events.EventOverviewBolusProgress
import app.aaps.core.interfaces.utils.T import app.aaps.core.interfaces.utils.T
import com.google.common.truth.Truth.assertThat
import info.nightscout.pump.medtrum.comm.enums.BasalType import info.nightscout.pump.medtrum.comm.enums.BasalType
import info.nightscout.pump.medtrum.util.MedtrumSnUtil import info.nightscout.pump.medtrum.util.MedtrumSnUtil
import org.json.JSONObject import org.json.JSONObject
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.mockito.Mockito import org.mockito.Mockito
import org.mockito.Mockito.mock import org.mockito.Mockito.mock
@ -43,7 +43,7 @@ class MedtrumPumpTest : MedtrumTestBase() {
// Expected values // Expected values
val expectedByteArray = byteArrayOf(7, 0, -96, 2, -16, 96, 2, 104, 33, 2, -32, -31, 1, -64, 3, 2, -20, 36, 2, 100, -123, 2) val expectedByteArray = byteArrayOf(7, 0, -96, 2, -16, 96, 2, 104, 33, 2, -32, -31, 1, -64, 3, 2, -20, 36, 2, 100, -123, 2)
Assertions.assertEquals(expectedByteArray.contentToString(), result?.contentToString()) assertThat(result!!.contentToString()).isEqualTo(expectedByteArray.contentToString())
} }
@Test fun buildMedtrumProfileArrayGiveProfileWhenValuesTooHighThenReturnNull() { @Test fun buildMedtrumProfileArrayGiveProfileWhenValuesTooHighThenReturnNull() {
@ -60,7 +60,7 @@ class MedtrumPumpTest : MedtrumTestBase() {
val result = medtrumPump.buildMedtrumProfileArray(profile) val result = medtrumPump.buildMedtrumProfileArray(profile)
// Expected values // Expected values
Assertions.assertNull(result) assertThat(result).isNull()
} }
@Test fun getCurrentHourlyBasalFromMedtrumProfileArrayGivenProfileWhenValuesSetThenReturnCorrectValue() { @Test fun getCurrentHourlyBasalFromMedtrumProfileArrayGivenProfileWhenValuesSetThenReturnCorrectValue() {
@ -88,28 +88,28 @@ class MedtrumPumpTest : MedtrumTestBase() {
val zonedDateTime0399 = localDate.atTime(localTime0399).atZone(ZoneId.systemDefault()) val zonedDateTime0399 = localDate.atTime(localTime0399).atZone(ZoneId.systemDefault())
val time0399 = zonedDateTime0399.toInstant().toEpochMilli() val time0399 = zonedDateTime0399.toInstant().toEpochMilli()
val result = medtrumPump.getHourlyBasalFromMedtrumProfileArray(profileArray!!, time0399) val result = medtrumPump.getHourlyBasalFromMedtrumProfileArray(profileArray!!, time0399)
Assertions.assertEquals(2.1, result, 0.01) assertThat(result).isWithin(0.01).of(2.1)
// For 22:30 // For 22:30
val localTime2230 = LocalTime.of(22, 30) val localTime2230 = LocalTime.of(22, 30)
val zonedDateTime2230 = localDate.atTime(localTime2230).atZone(ZoneId.systemDefault()) val zonedDateTime2230 = localDate.atTime(localTime2230).atZone(ZoneId.systemDefault())
val time2230 = zonedDateTime2230.toInstant().toEpochMilli() val time2230 = zonedDateTime2230.toInstant().toEpochMilli()
val result1 = medtrumPump.getHourlyBasalFromMedtrumProfileArray(profileArray, time2230) val result1 = medtrumPump.getHourlyBasalFromMedtrumProfileArray(profileArray, time2230)
Assertions.assertEquals(1.7, result1, 0.01) assertThat(result1).isWithin(0.01).of(1.7)
// For 23:59 // For 23:59
val localTime2359 = LocalTime.of(23, 59) val localTime2359 = LocalTime.of(23, 59)
val zonedDateTime2359 = localDate.atTime(localTime2359).atZone(ZoneId.systemDefault()) val zonedDateTime2359 = localDate.atTime(localTime2359).atZone(ZoneId.systemDefault())
val time2359 = zonedDateTime2359.toInstant().toEpochMilli() val time2359 = zonedDateTime2359.toInstant().toEpochMilli()
val result2 = medtrumPump.getHourlyBasalFromMedtrumProfileArray(profileArray, time2359) val result2 = medtrumPump.getHourlyBasalFromMedtrumProfileArray(profileArray, time2359)
Assertions.assertEquals(2.0, result2, 0.01) assertThat(result2).isWithin(0.01).of(2.0)
// For 00:00 // For 00:00
val localTime0000 = LocalTime.of(0, 0) val localTime0000 = LocalTime.of(0, 0)
val zonedDateTime0000 = localDate.atTime(localTime0000).atZone(ZoneId.systemDefault()) val zonedDateTime0000 = localDate.atTime(localTime0000).atZone(ZoneId.systemDefault())
val time0000 = zonedDateTime0000.toInstant().toEpochMilli() val time0000 = zonedDateTime0000.toInstant().toEpochMilli()
val result3 = medtrumPump.getHourlyBasalFromMedtrumProfileArray(profileArray, time0000) val result3 = medtrumPump.getHourlyBasalFromMedtrumProfileArray(profileArray, time0000)
Assertions.assertEquals(2.1, result3, 0.01) assertThat(result3).isWithin(0.01).of(2.1)
} }
@Test fun handleBolusStatusUpdateWhenCalledExpectNewData() { @Test fun handleBolusStatusUpdateWhenCalledExpectNewData() {
@ -124,9 +124,9 @@ class MedtrumPumpTest : MedtrumTestBase() {
medtrumPump.handleBolusStatusUpdate(bolusType, bolusCompleted, amount) medtrumPump.handleBolusStatusUpdate(bolusType, bolusCompleted, amount)
// Expected values // Expected values
Assertions.assertEquals(bolusCompleted, medtrumPump.bolusDone) assertThat(medtrumPump.bolusDone).isEqualTo(bolusCompleted)
Assertions.assertEquals(amount, medtrumPump.bolusAmountDeliveredFlow.value, 0.01) assertThat(medtrumPump.bolusAmountDeliveredFlow.value).isWithin(0.01).of(amount)
Assertions.assertEquals(amount, medtrumPump.bolusingTreatment!!.insulin, 0.01) assertThat(medtrumPump.bolusingTreatment!!.insulin).isWithin(0.01).of(amount)
} }
@Test fun handleBasalStatusUpdateWhenBasalTypeIsAbsoluteTempAndTemporaryBasalInfoThenExpectNewData() { @Test fun handleBasalStatusUpdateWhenBasalTypeIsAbsoluteTempAndTemporaryBasalInfoThenExpectNewData() {
@ -174,12 +174,12 @@ class MedtrumPumpTest : MedtrumTestBase() {
pumpSerial = medtrumPump.pumpSN.toString(radix = 16) pumpSerial = medtrumPump.pumpSN.toString(radix = 16)
) )
Assertions.assertEquals(basalType, medtrumPump.lastBasalType) assertThat(medtrumPump.lastBasalType).isEqualTo(basalType)
Assertions.assertEquals(basalRate, medtrumPump.lastBasalRate, 0.01) assertThat(medtrumPump.lastBasalRate).isWithin(0.01).of(basalRate)
Assertions.assertEquals(basalSequence, medtrumPump.lastBasalSequence) assertThat(medtrumPump.lastBasalSequence).isEqualTo(basalSequence)
Assertions.assertEquals(basalSequence, medtrumPump.currentSequenceNumber) assertThat(medtrumPump.currentSequenceNumber).isEqualTo(basalSequence)
Assertions.assertEquals(basalPatchId, medtrumPump.lastBasalPatchId) assertThat(medtrumPump.lastBasalPatchId).isEqualTo(basalPatchId)
Assertions.assertEquals(basalStartTime, medtrumPump.lastBasalStartTime) assertThat(medtrumPump.lastBasalStartTime).isEqualTo(basalStartTime)
} }
@Test fun handleBasalStatusUpdateWhenBasalTypeIsAbsoluteTempAndSameExpectedTemporaryBasalInfoThenExpectNoPumpSync() { @Test fun handleBasalStatusUpdateWhenBasalTypeIsAbsoluteTempAndSameExpectedTemporaryBasalInfoThenExpectNoPumpSync() {
@ -223,12 +223,12 @@ class MedtrumPumpTest : MedtrumTestBase() {
) )
// Check that other fields in medtrumPump are updated // Check that other fields in medtrumPump are updated
Assertions.assertEquals(basalType, medtrumPump.lastBasalType) assertThat(medtrumPump.lastBasalType).isEqualTo(basalType)
Assertions.assertEquals(basalRate, medtrumPump.lastBasalRate, 0.01) assertThat(medtrumPump.lastBasalRate).isWithin(0.01).of(basalRate)
Assertions.assertEquals(basalSequence, medtrumPump.lastBasalSequence) assertThat(medtrumPump.lastBasalSequence).isEqualTo(basalSequence)
Assertions.assertEquals(basalSequence, medtrumPump.currentSequenceNumber) assertThat(medtrumPump.currentSequenceNumber).isEqualTo(basalSequence)
Assertions.assertEquals(basalPatchId, medtrumPump.lastBasalPatchId) assertThat(medtrumPump.lastBasalPatchId).isEqualTo(basalPatchId)
Assertions.assertEquals(basalStartTime, medtrumPump.lastBasalStartTime) assertThat(medtrumPump.lastBasalStartTime).isEqualTo(basalStartTime)
} }
@Test fun handleBasalStatusUpdateWhenBasalTypeIsAbsoluteTempAndNoTemporaryBasalInfoThenExpectNewData() { @Test fun handleBasalStatusUpdateWhenBasalTypeIsAbsoluteTempAndNoTemporaryBasalInfoThenExpectNewData() {
@ -274,12 +274,12 @@ class MedtrumPumpTest : MedtrumTestBase() {
pumpSerial = medtrumPump.pumpSN.toString(radix = 16) pumpSerial = medtrumPump.pumpSN.toString(radix = 16)
) )
Assertions.assertEquals(basalType, medtrumPump.lastBasalType) assertThat(medtrumPump.lastBasalType).isEqualTo(basalType)
Assertions.assertEquals(basalRate, medtrumPump.lastBasalRate, 0.01) assertThat(medtrumPump.lastBasalRate).isWithin(0.01).of(basalRate)
Assertions.assertEquals(basalSequence, medtrumPump.lastBasalSequence) assertThat(medtrumPump.lastBasalSequence).isEqualTo(basalSequence)
Assertions.assertEquals(basalSequence, medtrumPump.currentSequenceNumber) assertThat(medtrumPump.currentSequenceNumber).isEqualTo(basalSequence)
Assertions.assertEquals(basalPatchId, medtrumPump.lastBasalPatchId) assertThat(medtrumPump.lastBasalPatchId).isEqualTo(basalPatchId)
Assertions.assertEquals(basalStartTime, medtrumPump.lastBasalStartTime) assertThat(medtrumPump.lastBasalStartTime).isEqualTo(basalStartTime)
} }
@Test fun handleBasalStatusUpdateWhenBasalTypeIsRelativeTempAndTemporaryBasalInfoThenExpectNewData() { @Test fun handleBasalStatusUpdateWhenBasalTypeIsRelativeTempAndTemporaryBasalInfoThenExpectNewData() {
@ -329,12 +329,12 @@ class MedtrumPumpTest : MedtrumTestBase() {
pumpSerial = medtrumPump.pumpSN.toString(radix = 16) pumpSerial = medtrumPump.pumpSN.toString(radix = 16)
) )
Assertions.assertEquals(basalType, medtrumPump.lastBasalType) assertThat(medtrumPump.lastBasalType).isEqualTo(basalType)
Assertions.assertEquals(basalRate, medtrumPump.lastBasalRate, 0.01) assertThat(medtrumPump.lastBasalRate).isWithin(0.01).of(basalRate)
Assertions.assertEquals(basalSequence, medtrumPump.lastBasalSequence) assertThat(medtrumPump.lastBasalSequence).isEqualTo(basalSequence)
Assertions.assertEquals(basalSequence, medtrumPump.currentSequenceNumber) assertThat(medtrumPump.currentSequenceNumber).isEqualTo(basalSequence)
Assertions.assertEquals(basalPatchId, medtrumPump.lastBasalPatchId) assertThat(medtrumPump.lastBasalPatchId).isEqualTo(basalPatchId)
Assertions.assertEquals(basalStartTime, medtrumPump.lastBasalStartTime) assertThat(medtrumPump.lastBasalStartTime).isEqualTo(basalStartTime)
} }
@Test fun handleBasalStatusUpdateWhenBasalTypeIsSuspendedThenExpectNewData() { @Test fun handleBasalStatusUpdateWhenBasalTypeIsSuspendedThenExpectNewData() {
@ -378,12 +378,12 @@ class MedtrumPumpTest : MedtrumTestBase() {
pumpSerial = medtrumPump.pumpSN.toString(radix = 16) pumpSerial = medtrumPump.pumpSN.toString(radix = 16)
) )
Assertions.assertEquals(basalType, medtrumPump.lastBasalType) assertThat(medtrumPump.lastBasalType).isEqualTo(basalType)
Assertions.assertEquals(basalRate, medtrumPump.lastBasalRate, 0.01) assertThat(medtrumPump.lastBasalRate).isWithin(0.01).of(basalRate)
Assertions.assertEquals(basalSequence, medtrumPump.lastBasalSequence) assertThat(medtrumPump.lastBasalSequence).isEqualTo(basalSequence)
Assertions.assertEquals(basalSequence, medtrumPump.currentSequenceNumber) assertThat(medtrumPump.currentSequenceNumber).isEqualTo(basalSequence)
Assertions.assertEquals(basalPatchId, medtrumPump.lastBasalPatchId) assertThat(medtrumPump.lastBasalPatchId).isEqualTo(basalPatchId)
Assertions.assertEquals(basalStartTime, medtrumPump.lastBasalStartTime) assertThat(medtrumPump.lastBasalStartTime).isEqualTo(basalStartTime)
} }
@Test fun handleBasalStatusUpdateWhenBasalTypeIsATypeIsSuspendedAndSameExpectedTemporaryBasalInfoThenExpectNoPumpSync() { @Test fun handleBasalStatusUpdateWhenBasalTypeIsATypeIsSuspendedAndSameExpectedTemporaryBasalInfoThenExpectNoPumpSync() {
@ -424,12 +424,12 @@ class MedtrumPumpTest : MedtrumTestBase() {
anyOrNull() anyOrNull()
) )
Assertions.assertEquals(basalType, medtrumPump.lastBasalType) assertThat(medtrumPump.lastBasalType).isEqualTo(basalType)
Assertions.assertEquals(basalRate, medtrumPump.lastBasalRate, 0.01) assertThat(medtrumPump.lastBasalRate).isWithin(0.01).of(basalRate)
Assertions.assertEquals(basalSequence, medtrumPump.lastBasalSequence) assertThat(medtrumPump.lastBasalSequence).isEqualTo(basalSequence)
Assertions.assertEquals(basalSequence, medtrumPump.currentSequenceNumber) assertThat(medtrumPump.currentSequenceNumber).isEqualTo(basalSequence)
Assertions.assertEquals(basalPatchId, medtrumPump.lastBasalPatchId) assertThat(medtrumPump.lastBasalPatchId).isEqualTo(basalPatchId)
Assertions.assertEquals(basalStartTime, medtrumPump.lastBasalStartTime) assertThat(medtrumPump.lastBasalStartTime).isEqualTo(basalStartTime)
} }
@Test fun handleBasalStatusUpdateWhenBasalTypeIsSuspendedAndNewerFakeTBRThenExpectInvalidateAndNewData() { @Test fun handleBasalStatusUpdateWhenBasalTypeIsSuspendedAndNewerFakeTBRThenExpectInvalidateAndNewData() {
@ -475,12 +475,12 @@ class MedtrumPumpTest : MedtrumTestBase() {
pumpSerial = medtrumPump.pumpSN.toString(radix = 16) pumpSerial = medtrumPump.pumpSN.toString(radix = 16)
) )
Assertions.assertEquals(basalType, medtrumPump.lastBasalType) assertThat(medtrumPump.lastBasalType).isEqualTo(basalType)
Assertions.assertEquals(basalRate, medtrumPump.lastBasalRate, 0.01) assertThat(medtrumPump.lastBasalRate).isWithin(0.01).of(basalRate)
Assertions.assertEquals(basalSequence, medtrumPump.lastBasalSequence) assertThat(medtrumPump.lastBasalSequence).isEqualTo(basalSequence)
Assertions.assertEquals(basalSequence, medtrumPump.currentSequenceNumber) assertThat(medtrumPump.currentSequenceNumber).isEqualTo(basalSequence)
Assertions.assertEquals(basalPatchId, medtrumPump.lastBasalPatchId) assertThat(medtrumPump.lastBasalPatchId).isEqualTo(basalPatchId)
Assertions.assertEquals(basalStartTime, medtrumPump.lastBasalStartTime) assertThat(medtrumPump.lastBasalStartTime).isEqualTo(basalStartTime)
} }
@Test fun handleBasalStatusUpdateWhenBasalTypeIsNoneAndThenExpectFakeTBR() { @Test fun handleBasalStatusUpdateWhenBasalTypeIsNoneAndThenExpectFakeTBR() {
@ -520,12 +520,12 @@ class MedtrumPumpTest : MedtrumTestBase() {
pumpSerial = medtrumPump.pumpSN.toString(radix = 16) pumpSerial = medtrumPump.pumpSN.toString(radix = 16)
) )
Assertions.assertEquals(basalType, medtrumPump.lastBasalType) assertThat(medtrumPump.lastBasalType).isEqualTo(basalType)
Assertions.assertEquals(basalRate, medtrumPump.lastBasalRate, 0.01) assertThat(medtrumPump.lastBasalRate).isWithin(0.01).of(basalRate)
Assertions.assertEquals(basalSequence, medtrumPump.lastBasalSequence) assertThat(medtrumPump.lastBasalSequence).isEqualTo(basalSequence)
Assertions.assertEquals(basalSequence, medtrumPump.currentSequenceNumber) assertThat(medtrumPump.currentSequenceNumber).isEqualTo(basalSequence)
Assertions.assertEquals(basalPatchId, medtrumPump.lastBasalPatchId) assertThat(medtrumPump.lastBasalPatchId).isEqualTo(basalPatchId)
Assertions.assertEquals(basalStartTime, medtrumPump.lastBasalStartTime) assertThat(medtrumPump.lastBasalStartTime).isEqualTo(basalStartTime)
} }
@Test fun handleBasalStatusUpdateWhenBasalTypeIsStandardAndTempBasalExpectedThenExpectSyncStop() { @Test fun handleBasalStatusUpdateWhenBasalTypeIsStandardAndTempBasalExpectedThenExpectSyncStop() {
@ -564,12 +564,12 @@ class MedtrumPumpTest : MedtrumTestBase() {
pumpSerial = medtrumPump.pumpSN.toString(radix = 16) pumpSerial = medtrumPump.pumpSN.toString(radix = 16)
) )
Assertions.assertEquals(basalType, medtrumPump.lastBasalType) assertThat(medtrumPump.lastBasalType).isEqualTo(basalType)
Assertions.assertEquals(basalRate, medtrumPump.lastBasalRate, 0.01) assertThat(medtrumPump.lastBasalRate).isWithin(0.01).of(basalRate)
Assertions.assertEquals(basalSequence, medtrumPump.lastBasalSequence) assertThat(medtrumPump.lastBasalSequence).isEqualTo(basalSequence)
Assertions.assertEquals(basalSequence, medtrumPump.currentSequenceNumber) assertThat(medtrumPump.currentSequenceNumber).isEqualTo(basalSequence)
Assertions.assertEquals(basalPatchId, medtrumPump.lastBasalPatchId) assertThat(medtrumPump.lastBasalPatchId).isEqualTo(basalPatchId)
Assertions.assertEquals(basalStartTime, medtrumPump.lastBasalStartTime) assertThat(medtrumPump.lastBasalStartTime).isEqualTo(basalStartTime)
} }
@Test fun handleBasalStatusUpdateWhenBasalTypeIsStandardAndNoTempBasalExpectedThenExpectNoSyncStop() { @Test fun handleBasalStatusUpdateWhenBasalTypeIsStandardAndNoTempBasalExpectedThenExpectNoSyncStop() {
@ -605,12 +605,12 @@ class MedtrumPumpTest : MedtrumTestBase() {
anyOrNull() anyOrNull()
) )
Assertions.assertEquals(basalType, medtrumPump.lastBasalType) assertThat(medtrumPump.lastBasalType).isEqualTo(basalType)
Assertions.assertEquals(basalRate, medtrumPump.lastBasalRate, 0.01) assertThat(medtrumPump.lastBasalRate).isWithin(0.01).of(basalRate)
Assertions.assertEquals(basalSequence, medtrumPump.lastBasalSequence) assertThat(medtrumPump.lastBasalSequence).isEqualTo(basalSequence)
Assertions.assertEquals(basalSequence, medtrumPump.currentSequenceNumber) assertThat(medtrumPump.currentSequenceNumber).isEqualTo(basalSequence)
Assertions.assertEquals(basalPatchId, medtrumPump.lastBasalPatchId) assertThat(medtrumPump.lastBasalPatchId).isEqualTo(basalPatchId)
Assertions.assertEquals(basalStartTime, medtrumPump.lastBasalStartTime) assertThat(medtrumPump.lastBasalStartTime).isEqualTo(basalStartTime)
} }
@Test fun handleNewPatchCalledWhenCalledExpectNewDataPresent() { @Test fun handleNewPatchCalledWhenCalledExpectNewDataPresent() {
@ -626,10 +626,10 @@ class MedtrumPumpTest : MedtrumTestBase() {
medtrumPump.handleNewPatch(newPatchId, newSequenceNumber, newStartTime) medtrumPump.handleNewPatch(newPatchId, newSequenceNumber, newStartTime)
// Expected values // Expected values
Assertions.assertEquals(newPatchId, medtrumPump.patchId) assertThat(medtrumPump.patchId).isEqualTo(newPatchId)
Assertions.assertEquals(newSequenceNumber, medtrumPump.currentSequenceNumber) assertThat(medtrumPump.currentSequenceNumber).isEqualTo(newSequenceNumber)
Assertions.assertEquals(newStartTime, medtrumPump.patchStartTime) assertThat(medtrumPump.patchStartTime).isEqualTo(newStartTime)
Assertions.assertEquals(1, medtrumPump.syncedSequenceNumber) assertThat(medtrumPump.syncedSequenceNumber).isEqualTo(1)
} }
@Test fun handleStopStatusUpdateWhenSequenceThenExpectUpdate() { @Test fun handleStopStatusUpdateWhenSequenceThenExpectUpdate() {
@ -644,8 +644,8 @@ class MedtrumPumpTest : MedtrumTestBase() {
medtrumPump.handleStopStatusUpdate(sequence, patchId) medtrumPump.handleStopStatusUpdate(sequence, patchId)
// Expected values // Expected values
Assertions.assertEquals(patchId, medtrumPump.lastStopPatchId) assertThat(medtrumPump.lastStopPatchId).isEqualTo(patchId)
Assertions.assertEquals(sequence, medtrumPump.currentSequenceNumber) assertThat(medtrumPump.currentSequenceNumber).isEqualTo(sequence)
} }
@Test fun setFakeTBRIfNotSetWhenNoFakeTBRAlreadyRunningExpectPumpSync() { @Test fun setFakeTBRIfNotSetWhenNoFakeTBRAlreadyRunningExpectPumpSync() {