Add unit tests
This commit is contained in:
parent
f98d310a8e
commit
4a38a5b219
|
@ -432,7 +432,7 @@ class MedtronicHistoryData @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun processBgReceived(bgRecords: List<PumpHistoryEntry>) {
|
fun processBgReceived(bgRecords: List<PumpHistoryEntry>) {
|
||||||
for (bgRecord in bgRecords) {
|
for (bgRecord in bgRecords) {
|
||||||
val glucoseMgdl = bgRecord.getDecodedDataEntry("GlucoseMgdl")
|
val glucoseMgdl = bgRecord.getDecodedDataEntry("GlucoseMgdl")
|
||||||
if (glucoseMgdl == null || glucoseMgdl as Int == 0) {
|
if (glucoseMgdl == null || glucoseMgdl as Int == 0) {
|
||||||
|
|
|
@ -51,6 +51,24 @@ open class MedtronicTestBase : TestBaseWithProfile() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getPumpHistoryEntryFromData(vararg elements: Int): PumpHistoryEntry {
|
||||||
|
val data: MutableList<Byte> = ArrayList()
|
||||||
|
for (item in elements) {
|
||||||
|
var b = if (item > 128) item - 256 else item
|
||||||
|
data.add(b.toByte());
|
||||||
|
}
|
||||||
|
|
||||||
|
val entryType = PumpHistoryEntryType.getByCode(data[0])
|
||||||
|
|
||||||
|
val phe = PumpHistoryEntry()
|
||||||
|
phe.setEntryType(medtronicUtil.medtronicPumpModel, entryType)
|
||||||
|
phe.setData(data, false)
|
||||||
|
|
||||||
|
decoder.decodeRecord(phe)
|
||||||
|
|
||||||
|
return phe
|
||||||
|
}
|
||||||
|
|
||||||
private fun preProcessTBRs(tbrsInput: MutableList<PumpHistoryEntry>): MutableList<PumpHistoryEntry> {
|
private fun preProcessTBRs(tbrsInput: MutableList<PumpHistoryEntry>): MutableList<PumpHistoryEntry> {
|
||||||
val tbrs: MutableList<PumpHistoryEntry> = mutableListOf()
|
val tbrs: MutableList<PumpHistoryEntry> = mutableListOf()
|
||||||
val map: MutableMap<String?, PumpHistoryEntry?> = HashMap()
|
val map: MutableMap<String?, PumpHistoryEntry?> = HashMap()
|
||||||
|
|
|
@ -1,8 +1,16 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump
|
package info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump
|
||||||
|
|
||||||
|
import app.aaps.core.interfaces.ui.UiInteraction
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicTestBase
|
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicTestBase
|
||||||
|
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.MedtronicPumpHistoryDecoder
|
||||||
|
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicDeviceType
|
||||||
|
import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus
|
||||||
|
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil
|
||||||
import com.google.common.truth.Truth.assertThat
|
import com.google.common.truth.Truth.assertThat
|
||||||
|
import org.junit.jupiter.api.BeforeEach
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
import org.mockito.Mock
|
||||||
|
import org.mockito.Mockito.`when`
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by andy on 4/9/19.
|
* Created by andy on 4/9/19.
|
||||||
|
@ -10,6 +18,16 @@ import org.junit.jupiter.api.Test
|
||||||
*/
|
*/
|
||||||
class PumpHistoryEntryUTest : MedtronicTestBase() {
|
class PumpHistoryEntryUTest : MedtronicTestBase() {
|
||||||
|
|
||||||
|
@Mock lateinit var medtronicPumpStatus: MedtronicPumpStatus
|
||||||
|
@Mock lateinit var uiInteraction: UiInteraction
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
fun setUp() {
|
||||||
|
medtronicUtil = MedtronicUtil(aapsLogger, rxBus, rileyLinkUtil, medtronicPumpStatus, uiInteraction)
|
||||||
|
`when`(medtronicUtil.medtronicPumpModel).thenReturn(MedtronicDeviceType.Medtronic_723_Revel)
|
||||||
|
decoder = MedtronicPumpHistoryDecoder(aapsLogger, medtronicUtil)
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun checkIsAfter() {
|
fun checkIsAfter() {
|
||||||
val dateObject = 20191010000000L
|
val dateObject = 20191010000000L
|
||||||
|
@ -18,4 +36,21 @@ class PumpHistoryEntryUTest : MedtronicTestBase() {
|
||||||
phe.atechDateTime = dateObject
|
phe.atechDateTime = dateObject
|
||||||
assertThat(phe.isAfter(queryObject)).isTrue()
|
assertThat(phe.isAfter(queryObject)).isTrue()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun decodeBgReceived() {
|
||||||
|
val bgRecord = getPumpHistoryEntryFromData(
|
||||||
|
// head
|
||||||
|
0x39, 0x15,
|
||||||
|
// datetime (combined with glucose in mg/dl)
|
||||||
|
0xC2, 0x25, 0xF3, 0x61, 0x17,
|
||||||
|
// serial number
|
||||||
|
0x12, 0x34, 0x56
|
||||||
|
)
|
||||||
|
val expectedGlucoseMgdl = 175
|
||||||
|
val expectedMeterSerial = "123456"
|
||||||
|
|
||||||
|
assertThat(bgRecord.getDecodedDataEntry("GlucoseMgdl")).isEqualTo(expectedGlucoseMgdl)
|
||||||
|
assertThat(bgRecord.getDecodedDataEntry("MeterSerial")).isEqualTo(expectedMeterSerial)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,24 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.medtronic.data
|
package info.nightscout.androidaps.plugins.pump.medtronic.data
|
||||||
|
|
||||||
|
import app.aaps.core.interfaces.db.GlucoseUnit
|
||||||
import app.aaps.core.interfaces.ui.UiInteraction
|
import app.aaps.core.interfaces.ui.UiInteraction
|
||||||
|
import app.aaps.core.utils.DateTimeUtil
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
import com.google.gson.internal.LinkedTreeMap
|
import com.google.gson.internal.LinkedTreeMap
|
||||||
import com.google.gson.reflect.TypeToken
|
import com.google.gson.reflect.TypeToken
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicTestBase
|
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicTestBase
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.MedtronicPumpHistoryDecoder
|
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.MedtronicPumpHistoryDecoder
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpHistoryEntry
|
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpHistoryEntry
|
||||||
|
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpHistoryEntryType
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.TempBasalPair
|
import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.TempBasalPair
|
||||||
|
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicDeviceType
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus
|
import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil
|
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil
|
||||||
import org.junit.jupiter.api.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.mockito.Mock
|
import org.mockito.Mock
|
||||||
|
import org.mockito.Mockito.verify
|
||||||
|
import org.mockito.Mockito.`when`
|
||||||
import java.lang.reflect.Type
|
import java.lang.reflect.Type
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
@ -24,6 +30,7 @@ class MedtronicHistoryDataUTest : MedtronicTestBase() {
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
fun setUp() {
|
fun setUp() {
|
||||||
medtronicUtil = MedtronicUtil(aapsLogger, rxBus, rileyLinkUtil, medtronicPumpStatus, uiInteraction)
|
medtronicUtil = MedtronicUtil(aapsLogger, rxBus, rileyLinkUtil, medtronicPumpStatus, uiInteraction)
|
||||||
|
`when`(medtronicUtil.medtronicPumpModel).thenReturn(MedtronicDeviceType.Medtronic_723_Revel)
|
||||||
decoder = MedtronicPumpHistoryDecoder(aapsLogger, medtronicUtil)
|
decoder = MedtronicPumpHistoryDecoder(aapsLogger, medtronicUtil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,4 +117,70 @@ class MedtronicHistoryDataUTest : MedtronicTestBase() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun processBgReceived_WithMgdl() {
|
||||||
|
|
||||||
|
val unitToTest = MedtronicHistoryData(
|
||||||
|
packetInjector, aapsLogger, sp, rh, rxBus, activePlugin,
|
||||||
|
medtronicUtil, decoder,
|
||||||
|
medtronicPumpStatus,
|
||||||
|
pumpSync,
|
||||||
|
pumpSyncStorage, uiInteraction, profileUtil
|
||||||
|
)
|
||||||
|
|
||||||
|
val glucoseMgdl = 175
|
||||||
|
|
||||||
|
`when`(sp.getString(app.aaps.core.utils.R.string.key_units, GlucoseUnit.MGDL.asText)).thenReturn(GlucoseUnit.MGDL.asText)
|
||||||
|
|
||||||
|
val bgRecord = PumpHistoryEntry()
|
||||||
|
bgRecord.setEntryType(medtronicUtil.medtronicPumpModel, PumpHistoryEntryType.BGReceived)
|
||||||
|
bgRecord.addDecodedData("GlucoseMgdl", glucoseMgdl)
|
||||||
|
bgRecord.addDecodedData("MeterSerial", "123456")
|
||||||
|
|
||||||
|
unitToTest.processBgReceived(listOf(bgRecord))
|
||||||
|
|
||||||
|
verify(pumpSync).insertFingerBgIfNewWithTimestamp(
|
||||||
|
DateTimeUtil.toMillisFromATD(bgRecord.atechDateTime),
|
||||||
|
glucoseMgdl.toDouble(),
|
||||||
|
GlucoseUnit.MGDL, null,
|
||||||
|
bgRecord.pumpId,
|
||||||
|
medtronicPumpStatus.pumpType,
|
||||||
|
medtronicPumpStatus.serialNumber
|
||||||
|
)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun processBgReceived_WithMmol() {
|
||||||
|
|
||||||
|
val unitToTest = MedtronicHistoryData(
|
||||||
|
packetInjector, aapsLogger, sp, rh, rxBus, activePlugin,
|
||||||
|
medtronicUtil, decoder,
|
||||||
|
medtronicPumpStatus,
|
||||||
|
pumpSync,
|
||||||
|
pumpSyncStorage, uiInteraction, profileUtil
|
||||||
|
)
|
||||||
|
val glucoseMgdl = 180
|
||||||
|
val glucoseMmol = 10.0
|
||||||
|
|
||||||
|
`when`(sp.getString(app.aaps.core.utils.R.string.key_units, GlucoseUnit.MGDL.asText)).thenReturn(GlucoseUnit.MMOL.asText)
|
||||||
|
|
||||||
|
val bgRecord = PumpHistoryEntry()
|
||||||
|
bgRecord.setEntryType(medtronicUtil.medtronicPumpModel, PumpHistoryEntryType.BGReceived)
|
||||||
|
bgRecord.addDecodedData("GlucoseMgdl", glucoseMgdl)
|
||||||
|
bgRecord.addDecodedData("MeterSerial", "123456")
|
||||||
|
|
||||||
|
unitToTest.processBgReceived(listOf(bgRecord))
|
||||||
|
|
||||||
|
verify(pumpSync).insertFingerBgIfNewWithTimestamp(
|
||||||
|
DateTimeUtil.toMillisFromATD(bgRecord.atechDateTime),
|
||||||
|
glucoseMmol,
|
||||||
|
GlucoseUnit.MMOL, null,
|
||||||
|
bgRecord.pumpId,
|
||||||
|
medtronicPumpStatus.pumpType,
|
||||||
|
medtronicPumpStatus.serialNumber
|
||||||
|
)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue