fix tests

This commit is contained in:
Milos Kozak 2021-04-10 12:19:31 +02:00
parent 194cf305fd
commit 4eef2507fb
28 changed files with 61 additions and 56 deletions

View file

@ -79,7 +79,7 @@ open class AppModule {
@Binds fun bindCommandQueueProvider(commandQueue: CommandQueue): CommandQueueProvider @Binds fun bindCommandQueueProvider(commandQueue: CommandQueue): CommandQueueProvider
@Binds fun bindConfigInterface(config: Config): ConfigInterface @Binds fun bindConfigInterface(config: Config): ConfigInterface
@Binds fun bindConfigBuilderInterface(configBuilderPlugin: ConfigBuilderPlugin): ConfigBuilderInterface @Binds fun bindConfigBuilderInterface(configBuilderPlugin: ConfigBuilderPlugin): ConfigBuilderInterface
@Binds fun bindTreatmentInterface(treatmentsPlugin: TreatmentsPlugin): TreatmentsInterface @Binds fun bindTreatmentsInterface(treatmentsPlugin: TreatmentsPlugin): TreatmentsInterface
@Binds fun bindDatabaseHelperInterface(databaseHelperProvider: DatabaseHelperProvider): DatabaseHelperInterface @Binds fun bindDatabaseHelperInterface(databaseHelperProvider: DatabaseHelperProvider): DatabaseHelperInterface
@Binds fun bindNotificationHolderInterface(notificationHolder: NotificationHolder): NotificationHolderInterface @Binds fun bindNotificationHolderInterface(notificationHolder: NotificationHolder): NotificationHolderInterface
@Binds fun bindImportExportPrefsInterface(importExportPrefs: ImportExportPrefs): ImportExportPrefsInterface @Binds fun bindImportExportPrefsInterface(importExportPrefs: ImportExportPrefs): ImportExportPrefsInterface

View file

@ -8,6 +8,7 @@ import info.nightscout.androidaps.TestPumpPlugin
import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.data.PumpEnactResult
import info.nightscout.androidaps.interfaces.* import info.nightscout.androidaps.interfaces.*
import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.UserEntryLogger
import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.general.automation.triggers.Trigger import info.nightscout.androidaps.plugins.general.automation.triggers.Trigger
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
@ -17,7 +18,7 @@ import org.mockito.Mock
import org.mockito.Mockito.`when` import org.mockito.Mockito.`when`
import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.core.classloader.annotations.PrepareForTest
@PrepareForTest(RxBusWrapper::class, ActionsTestBase.TestLoopPlugin::class) @PrepareForTest(RxBusWrapper::class, ActionsTestBase.TestLoopPlugin::class, UserEntryLogger::class)
open class ActionsTestBase : TestBaseWithProfile() { open class ActionsTestBase : TestBaseWithProfile() {
open class TestLoopPlugin( open class TestLoopPlugin(
@ -29,7 +30,7 @@ open class ActionsTestBase : TestBaseWithProfile() {
pluginDescription, aapsLogger, resourceHelper, injector pluginDescription, aapsLogger, resourceHelper, injector
), LoopInterface { ), LoopInterface {
var suspended = false private var suspended = false
override var lastRun: LoopInterface.LastRun? = LoopInterface.LastRun() override var lastRun: LoopInterface.LastRun? = LoopInterface.LastRun()
override val isSuspended: Boolean = suspended override val isSuspended: Boolean = suspended
override fun suspendTo(endTime: Long) {} override fun suspendTo(endTime: Long) {}
@ -44,6 +45,7 @@ open class ActionsTestBase : TestBaseWithProfile() {
@Mock lateinit var profilePlugin: ProfileInterface @Mock lateinit var profilePlugin: ProfileInterface
@Mock lateinit var smsCommunicatorPlugin: SmsCommunicatorInterface @Mock lateinit var smsCommunicatorPlugin: SmsCommunicatorInterface
@Mock lateinit var loopPlugin: TestLoopPlugin @Mock lateinit var loopPlugin: TestLoopPlugin
@Mock lateinit var uel: UserEntryLogger
private val pluginDescription = PluginDescription() private val pluginDescription = PluginDescription()
lateinit var testPumpPlugin: TestPumpPlugin lateinit var testPumpPlugin: TestPumpPlugin
@ -55,6 +57,7 @@ open class ActionsTestBase : TestBaseWithProfile() {
it.resourceHelper = resourceHelper it.resourceHelper = resourceHelper
it.dateUtil = dateUtil it.dateUtil = dateUtil
it.repository = repository it.repository = repository
it.uel = uel
} }
if (it is ActionStartTempTarget) { if (it is ActionStartTempTarget) {
it.aapsLogger = aapsLogger it.aapsLogger = aapsLogger
@ -62,6 +65,7 @@ open class ActionsTestBase : TestBaseWithProfile() {
it.activePlugin = activePlugin it.activePlugin = activePlugin
it.repository = repository it.repository = repository
it.profileFunction = profileFunction it.profileFunction = profileFunction
it.uel = uel
} }
if (it is ActionSendSMS) { if (it is ActionSendSMS) {
it.aapsLogger = aapsLogger it.aapsLogger = aapsLogger
@ -73,10 +77,12 @@ open class ActionsTestBase : TestBaseWithProfile() {
it.resourceHelper = resourceHelper it.resourceHelper = resourceHelper
it.activePlugin = activePlugin it.activePlugin = activePlugin
it.profileFunction = profileFunction it.profileFunction = profileFunction
it.uel = uel
} }
if (it is ActionProfileSwitchPercent) { if (it is ActionProfileSwitchPercent) {
it.resourceHelper = resourceHelper it.resourceHelper = resourceHelper
it.activePlugin = activePlugin it.activePlugin = activePlugin
it.uel = uel
} }
if (it is ActionNotification) { if (it is ActionNotification) {
it.resourceHelper = resourceHelper it.resourceHelper = resourceHelper
@ -86,18 +92,21 @@ open class ActionsTestBase : TestBaseWithProfile() {
it.loopPlugin = loopPlugin it.loopPlugin = loopPlugin
it.resourceHelper = resourceHelper it.resourceHelper = resourceHelper
it.rxBus = rxBus it.rxBus = rxBus
it.uel = uel
} }
if (it is ActionLoopResume) { if (it is ActionLoopResume) {
it.loopPlugin = loopPlugin it.loopPlugin = loopPlugin
it.resourceHelper = resourceHelper it.resourceHelper = resourceHelper
it.configBuilderPlugin = configBuilderPlugin it.configBuilderPlugin = configBuilderPlugin
it.rxBus = rxBus it.rxBus = rxBus
it.uel = uel
} }
if (it is ActionLoopEnable) { if (it is ActionLoopEnable) {
it.loopPlugin = loopPlugin it.loopPlugin = loopPlugin
it.resourceHelper = resourceHelper it.resourceHelper = resourceHelper
it.configBuilderPlugin = configBuilderPlugin it.configBuilderPlugin = configBuilderPlugin
it.rxBus = rxBus it.rxBus = rxBus
it.uel = uel
} }
if (it is ActionLoopDisable) { if (it is ActionLoopDisable) {
it.loopPlugin = loopPlugin it.loopPlugin = loopPlugin
@ -105,6 +114,7 @@ open class ActionsTestBase : TestBaseWithProfile() {
it.configBuilderPlugin = configBuilderPlugin it.configBuilderPlugin = configBuilderPlugin
it.commandQueue = commandQueue it.commandQueue = commandQueue
it.rxBus = rxBus it.rxBus = rxBus
it.uel = uel
} }
if (it is PumpEnactResult) { if (it is PumpEnactResult) {
it.resourceHelper = resourceHelper it.resourceHelper = resourceHelper

View file

@ -30,7 +30,7 @@ class TriggerIobTest : TriggerTestBase() {
} }
@Test fun shouldRunTest() { @Test fun shouldRunTest() {
`when`(iobCobCalculatorPlugin.calculateFromTreatmentsAndTempsSynchronized(ArgumentMatchers.anyLong(), ArgumentMatchers.any(Profile::class.java))).thenReturn(generateIobRecordData()) `when`(iobCobCalculatorPlugin.calculateFromTreatmentsAndTempsSynchronized(ArgumentMatchers.anyLong(), anyObject())).thenReturn(generateIobRecordData())
var t: TriggerIob = TriggerIob(injector).setValue(1.1).comparator(Comparator.Compare.IS_EQUAL) var t: TriggerIob = TriggerIob(injector).setValue(1.1).comparator(Comparator.Compare.IS_EQUAL)
Assert.assertFalse(t.shouldRun()) Assert.assertFalse(t.shouldRun())
t = TriggerIob(injector).setValue(1.0).comparator(Comparator.Compare.IS_EQUAL) t = TriggerIob(injector).setValue(1.0).comparator(Comparator.Compare.IS_EQUAL)

View file

@ -33,6 +33,7 @@ object SealedClassHelper {
val x = gson.fromJson<T>(jsonReader, innerClass.javaObjectType) val x = gson.fromJson<T>(jsonReader, innerClass.javaObjectType)
jsonReader.endObject() jsonReader.endObject()
// if there a static object, actually return that // if there a static object, actually return that
@Suppress("UNCHECKED_CAST")
return innerClass.objectInstance as T? ?: x return innerClass.objectInstance as T? ?: x
} }

View file

@ -19,7 +19,6 @@ import info.nightscout.androidaps.danar.R;
import info.nightscout.androidaps.data.DetailedBolusInfo; import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.db.ExtendedBolus;
import info.nightscout.androidaps.events.EventAppExit; import info.nightscout.androidaps.events.EventAppExit;
import info.nightscout.androidaps.interfaces.ActivePluginProvider; import info.nightscout.androidaps.interfaces.ActivePluginProvider;
import info.nightscout.androidaps.interfaces.CommandQueueProvider; import info.nightscout.androidaps.interfaces.CommandQueueProvider;

View file

@ -25,7 +25,7 @@ class MsgInitConnStatusBasic(
danaPump.currentBasal = intFromBuff(bytes, 11, 2) / 100.0 danaPump.currentBasal = intFromBuff(bytes, 11, 2) / 100.0
val tempBasalPercent = intFromBuff(bytes, 13, 1) val tempBasalPercent = intFromBuff(bytes, 13, 1)
val isExtendedInProgress = intFromBuff(bytes, 14, 1) == 1 val isExtendedInProgress = intFromBuff(bytes, 14, 1) == 1
val isTempBasalInProgress = intFromBuff(bytes, 15, 1) == 1 //val isTempBasalInProgress = intFromBuff(bytes, 15, 1) == 1
val statusBasalUDOption = intFromBuff(bytes, 16, 1) val statusBasalUDOption = intFromBuff(bytes, 16, 1)
danaPump.isDualBolusInProgress = intFromBuff(bytes, 17, 1) == 1 danaPump.isDualBolusInProgress = intFromBuff(bytes, 17, 1) == 1
val extendedBolusRate = intFromBuff(bytes, 18, 2) / 100.0 val extendedBolusRate = intFromBuff(bytes, 18, 2) / 100.0
@ -46,8 +46,8 @@ class MsgInitConnStatusBasic(
aapsLogger.debug(LTag.PUMPCOMM, "Reservoir remaining units: " + danaPump.reservoirRemainingUnits) aapsLogger.debug(LTag.PUMPCOMM, "Reservoir remaining units: " + danaPump.reservoirRemainingUnits)
aapsLogger.debug(LTag.PUMPCOMM, "Bolus blocked: " + danaPump.bolusBlocked) aapsLogger.debug(LTag.PUMPCOMM, "Bolus blocked: " + danaPump.bolusBlocked)
aapsLogger.debug(LTag.PUMPCOMM, "Current basal: " + danaPump.currentBasal) aapsLogger.debug(LTag.PUMPCOMM, "Current basal: " + danaPump.currentBasal)
aapsLogger.debug(LTag.PUMPCOMM, "Current temp basal percent: " + tempBasalPercent) aapsLogger.debug(LTag.PUMPCOMM, "Current temp basal percent: $tempBasalPercent")
aapsLogger.debug(LTag.PUMPCOMM, "Is extended bolus running: " + isExtendedInProgress) aapsLogger.debug(LTag.PUMPCOMM, "Is extended bolus running: $isExtendedInProgress")
aapsLogger.debug(LTag.PUMPCOMM, "statusBasalUDOption: $statusBasalUDOption") aapsLogger.debug(LTag.PUMPCOMM, "statusBasalUDOption: $statusBasalUDOption")
aapsLogger.debug(LTag.PUMPCOMM, "Is dual bolus running: " + danaPump.isDualBolusInProgress) aapsLogger.debug(LTag.PUMPCOMM, "Is dual bolus running: " + danaPump.isDualBolusInProgress)
aapsLogger.debug(LTag.PUMPCOMM, "Extended bolus rate: $extendedBolusRate") aapsLogger.debug(LTag.PUMPCOMM, "Extended bolus rate: $extendedBolusRate")

View file

@ -16,8 +16,10 @@ class MsgStatusTempBasal(
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }
var isTempBasalInProgress = false
override fun handleMessage(bytes: ByteArray) { override fun handleMessage(bytes: ByteArray) {
val isTempBasalInProgress = intFromBuff(bytes, 0, 1) and 0x01 == 0x01 isTempBasalInProgress = intFromBuff(bytes, 0, 1) and 0x01 == 0x01
val isAPSTempBasalInProgress = intFromBuff(bytes, 0, 1) and 0x02 == 0x02 val isAPSTempBasalInProgress = intFromBuff(bytes, 0, 1) and 0x02 == 0x02
var tempBasalPercent = intFromBuff(bytes, 1, 1) var tempBasalPercent = intFromBuff(bytes, 1, 1)
if (tempBasalPercent > 200) tempBasalPercent = (tempBasalPercent - 200) * 10 if (tempBasalPercent > 200) tempBasalPercent = (tempBasalPercent - 200) * 10
@ -47,7 +49,7 @@ class MsgStatusTempBasal(
} }
private fun getDateFromSecAgo(tempBasalAgoSecs: Int): Long { private fun getDateFromSecAgo(tempBasalAgoSecs: Int): Long {
return (floor(System.currentTimeMillis() / 1000.0) - tempBasalAgoSecs).toLong() * 1000 return (floor(dateUtil._now() / 1000.0) - tempBasalAgoSecs).toLong() * 1000
} }
// because there is no fixed timestamp of start allow update of tbr only if tbr start differs more // because there is no fixed timestamp of start allow update of tbr only if tbr start differs more

View file

@ -32,7 +32,6 @@ open class DanaRTestBase : TestBase() {
@Mock lateinit var activePluginProvider: ActivePluginProvider @Mock lateinit var activePluginProvider: ActivePluginProvider
@Mock lateinit var dateUtil: DateUtil @Mock lateinit var dateUtil: DateUtil
@Mock lateinit var databaseHelper: DatabaseHelperInterface @Mock lateinit var databaseHelper: DatabaseHelperInterface
@Mock lateinit var treatmentsInterface: TreatmentsInterface
@Mock lateinit var danaRPlugin: DanaRPlugin @Mock lateinit var danaRPlugin: DanaRPlugin
@Mock lateinit var danaRKoreanPlugin: DanaRKoreanPlugin @Mock lateinit var danaRKoreanPlugin: DanaRKoreanPlugin
@Mock lateinit var danaRv2Plugin: DanaRv2Plugin @Mock lateinit var danaRv2Plugin: DanaRv2Plugin
@ -49,7 +48,6 @@ open class DanaRTestBase : TestBase() {
fun setup() { fun setup() {
danaPump = DanaPump(aapsLogger, sp, dateUtil, injector) danaPump = DanaPump(aapsLogger, sp, dateUtil, injector)
testPumpPlugin = TestPumpPlugin(injector) testPumpPlugin = TestPumpPlugin(injector)
`when`(activePluginProvider.activeTreatments).thenReturn(treatmentsInterface)
`when`(activePluginProvider.activePump).thenReturn(testPumpPlugin) `when`(activePluginProvider.activePump).thenReturn(testPumpPlugin)
doNothing().`when`(danaRKoreanPlugin).setPluginEnabled(anyObject(), anyBoolean()) doNothing().`when`(danaRKoreanPlugin).setPluginEnabled(anyObject(), anyBoolean())
doNothing().`when`(danaRPlugin).setPluginEnabled(anyObject(), anyBoolean()) doNothing().`when`(danaRPlugin).setPluginEnabled(anyObject(), anyBoolean())

View file

@ -5,7 +5,6 @@ import info.nightscout.androidaps.utils.T
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
import org.mockito.Mockito.`when`
import org.powermock.modules.junit4.PowerMockRunner import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class) @RunWith(PowerMockRunner::class)
@ -13,12 +12,12 @@ class MsgStatusBolusExtendedTest : DanaRTestBase() {
@Test @Test
fun runTest() { fun runTest() {
`when`(activePluginProvider.activeTreatments).thenReturn(treatmentsInterface)
val packet = MsgStatusBolusExtended(injector) val packet = MsgStatusBolusExtended(injector)
// test message decoding // test message decoding
val array = ByteArray(100) val array = ByteArray(100)
putByteToArray(array, 0, 1)
putByteToArray(array, 1, 1) putByteToArray(array, 1, 1)
packet.handleMessage(array) packet.handleMessage(array)
Assert.assertEquals(T.mins(30).msecs() , danaPump.extendedBolusDuration) Assert.assertEquals(T.mins(30).msecs(), danaPump.extendedBolusDuration)
} }
} }

View file

@ -12,11 +12,10 @@ class MsgStatusTempBasalTest : DanaRTestBase() {
@Test fun runTest() { @Test fun runTest() {
val packet = MsgStatusTempBasal(injector) val packet = MsgStatusTempBasal(injector)
// test message decoding // test message decoding
// test message decoding
packet.handleMessage(createArray(34, 1.toByte())) packet.handleMessage(createArray(34, 1.toByte()))
Assert.assertEquals(true, danaPump.isTempBasalInProgress) Assert.assertEquals(true, packet.isTempBasalInProgress)
// passing an bigger number // passing an bigger number
packet.handleMessage(createArray(34, 2.toByte())) packet.handleMessage(createArray(34, 2.toByte()))
Assert.assertEquals(false, danaPump.isTempBasalInProgress) Assert.assertEquals(false, packet.isTempBasalInProgress)
} }
} }

View file

@ -48,7 +48,7 @@ class DanaRKoreanPluginTest : TestBaseWithProfile() {
`when`(resourceHelper.gs(R.string.limitingbasalratio)).thenReturn("Limiting max basal rate to %1\$.2f U/h because of %2\$s") `when`(resourceHelper.gs(R.string.limitingbasalratio)).thenReturn("Limiting max basal rate to %1\$.2f U/h because of %2\$s")
`when`(resourceHelper.gs(R.string.limitingpercentrate)).thenReturn("Limiting max percent rate to %1\$d%% because of %2\$s") `when`(resourceHelper.gs(R.string.limitingpercentrate)).thenReturn("Limiting max percent rate to %1\$d%% because of %2\$s")
danaPump = DanaPump(aapsLogger, sp, dateUtil, injector) danaPump = DanaPump(aapsLogger, sp, dateUtil, injector)
danaRPlugin = DanaRKoreanPlugin(injector, aapsLogger, aapsSchedulers, rxBus, danaPump, context, resourceHelper, constraintChecker, activePluginProvider, sp, commandQueue, dateUtil, pumpSync, fabricPrivacy) danaRPlugin = DanaRKoreanPlugin(injector, aapsLogger, aapsSchedulers, rxBus, context, resourceHelper, constraintChecker, activePluginProvider, sp, commandQueue, danaPump, dateUtil, fabricPrivacy, pumpSync)
} }
@Test @Throws(Exception::class) @Test @Throws(Exception::class)

View file

@ -25,7 +25,7 @@ import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class) @RunWith(PowerMockRunner::class)
@PrepareForTest(ConstraintChecker::class, DetailedBolusInfoStorage::class) @PrepareForTest(ConstraintChecker::class, DetailedBolusInfoStorage::class, TemporaryBasalStorage::class)
class DanaRv2PluginTest : TestBaseWithProfile() { class DanaRv2PluginTest : TestBaseWithProfile() {
@Mock lateinit var context: Context @Mock lateinit var context: Context
@ -51,7 +51,7 @@ class DanaRv2PluginTest : TestBaseWithProfile() {
`when`(resourceHelper.gs(R.string.limitingbasalratio)).thenReturn("Limiting max basal rate to %1\$.2f U/h because of %2\$s") `when`(resourceHelper.gs(R.string.limitingbasalratio)).thenReturn("Limiting max basal rate to %1\$.2f U/h because of %2\$s")
`when`(resourceHelper.gs(R.string.limitingpercentrate)).thenReturn("Limiting max percent rate to %1\$d%% because of %2\$s") `when`(resourceHelper.gs(R.string.limitingpercentrate)).thenReturn("Limiting max percent rate to %1\$d%% because of %2\$s")
danaPump = DanaPump(aapsLogger, sp, dateUtil, injector) danaPump = DanaPump(aapsLogger, sp, dateUtil, injector)
danaRv2Plugin = DanaRv2Plugin(injector, aapsLogger, aapsSchedulers, rxBus, context, danaPump, resourceHelper, constraintChecker, activePluginProvider, sp, commandQueue, detailedBolusInfoStorage, temporaryBasalStorage, dateUtil, fabricPrivacy, pumpSync) danaRv2Plugin = DanaRv2Plugin(injector, aapsLogger, aapsSchedulers, rxBus, context, resourceHelper, constraintChecker, activePluginProvider, sp, commandQueue, danaPump,detailedBolusInfoStorage, temporaryBasalStorage, dateUtil, fabricPrivacy, pumpSync)
} }
@Test @Test

View file

@ -19,12 +19,12 @@ class MsgHistoryEventsRv2Test : DanaRTestBase() {
// test message decoding // test message decoding
val array = createArray(100, 2) val array = createArray(100, 2)
putByteToArray(array, 0, 0xFF.toByte())
packet.handleMessage(array)
Assert.assertEquals(true, danaPump.historyDoneReceived)
// passing an bigger number
putByteToArray(array, 0, 0x01.toByte()) putByteToArray(array, 0, 0x01.toByte())
packet.handleMessage(array) packet.handleMessage(array)
Assert.assertEquals(false, danaPump.historyDoneReceived) Assert.assertEquals(false, danaPump.historyDoneReceived)
putByteToArray(array, 0, 0xFF.toByte())
packet.handleMessage(array)
Assert.assertEquals(true, danaPump.historyDoneReceived)
} }
} }

View file

@ -19,14 +19,18 @@ class DanaRS_Packet_Basal_Get_Temporary_Basal_State(
aapsLogger.debug(LTag.PUMPCOMM, "Requesting temporary basal status") aapsLogger.debug(LTag.PUMPCOMM, "Requesting temporary basal status")
} }
var isTempBasalInProgress: Boolean = false
var tempBasalTotalSec: Int = 0
var tempBasalPercent: Int = 0
override fun handleMessage(data: ByteArray) { override fun handleMessage(data: ByteArray) {
val error = byteArrayToInt(getBytes(data, DATA_START, 1)) val error = byteArrayToInt(getBytes(data, DATA_START, 1))
val isTempBasalInProgress = byteArrayToInt(getBytes(data, DATA_START + 1, 1)) == 0x01 isTempBasalInProgress = byteArrayToInt(getBytes(data, DATA_START + 1, 1)) == 0x01
val isAPSTempBasalInProgress = byteArrayToInt(getBytes(data, DATA_START + 1, 1)) == 0x02 val isAPSTempBasalInProgress = byteArrayToInt(getBytes(data, DATA_START + 1, 1)) == 0x02
var tempBasalPercent = byteArrayToInt(getBytes(data, DATA_START + 2, 1)) tempBasalPercent = byteArrayToInt(getBytes(data, DATA_START + 2, 1))
if (tempBasalPercent > 200) tempBasalPercent = (tempBasalPercent - 200) * 10 if (tempBasalPercent > 200) tempBasalPercent = (tempBasalPercent - 200) * 10
val durationHour = byteArrayToInt(getBytes(data, DATA_START + 3, 1)) val durationHour = byteArrayToInt(getBytes(data, DATA_START + 3, 1))
val tempBasalTotalSec: Int = if (durationHour == 150) 15 * 60 else if (durationHour == 160) 30 * 60 else durationHour * 60 * 60 tempBasalTotalSec = if (durationHour == 150) 15 * 60 else if (durationHour == 160) 30 * 60 else durationHour * 60 * 60
val runningMin = byteArrayToInt(getBytes(data, DATA_START + 4, 2)) val runningMin = byteArrayToInt(getBytes(data, DATA_START + 4, 2))
if (error != 0) failed = true if (error != 0) failed = true
val tempBasalRemainingMin = (danaPump.tempBasalTotalSec - runningMin * 60) / 60 val tempBasalRemainingMin = (danaPump.tempBasalTotalSec - runningMin * 60) / 60

View file

@ -18,13 +18,15 @@ class DanaRS_Packet_Bolus_Get_Extended_Bolus_State(
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }
var isExtendedInProgress: Boolean = false
override fun handleMessage(data: ByteArray) { override fun handleMessage(data: ByteArray) {
var dataIndex = DATA_START var dataIndex = DATA_START
var dataSize = 1 var dataSize = 1
val error = byteArrayToInt(getBytes(data, dataIndex, dataSize)) val error = byteArrayToInt(getBytes(data, dataIndex, dataSize))
dataIndex += dataSize dataIndex += dataSize
dataSize = 1 dataSize = 1
val isExtendedInProgress = byteArrayToInt(getBytes(data, dataIndex, dataSize)) == 0x01 isExtendedInProgress = byteArrayToInt(getBytes(data, dataIndex, dataSize)) == 0x01
dataIndex += dataSize dataIndex += dataSize
dataSize = 1 dataSize = 1
val extendedBolusDuration = T.mins(byteArrayToInt(getBytes(data, dataIndex, dataSize)) * 30L).msecs() val extendedBolusDuration = T.mins(byteArrayToInt(getBytes(data, dataIndex, dataSize)) * 30L).msecs()

View file

@ -17,13 +17,15 @@ class DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State(
aapsLogger.debug(LTag.PUMPCOMM, "New message") aapsLogger.debug(LTag.PUMPCOMM, "New message")
} }
var isExtendedInProgress: Boolean = false
override fun handleMessage(data: ByteArray) { override fun handleMessage(data: ByteArray) {
var dataIndex = DATA_START var dataIndex = DATA_START
var dataSize = 1 var dataSize = 1
val extendedMenuOption = byteArrayToInt(getBytes(data, dataIndex, dataSize)) val extendedMenuOption = byteArrayToInt(getBytes(data, dataIndex, dataSize))
dataIndex += dataSize dataIndex += dataSize
dataSize = 1 dataSize = 1
val isExtendedInProgress = byteArrayToInt(getBytes(data, dataIndex, dataSize)) == 0x01 isExtendedInProgress = byteArrayToInt(getBytes(data, dataIndex, dataSize)) == 0x01
aapsLogger.debug(LTag.PUMPCOMM, "extendedMenuOption: $extendedMenuOption") aapsLogger.debug(LTag.PUMPCOMM, "extendedMenuOption: $extendedMenuOption")
} }

View file

@ -23,7 +23,7 @@ import org.powermock.modules.junit4.PowerMockRunner
@Suppress("SpellCheckingInspection") @Suppress("SpellCheckingInspection")
@RunWith(PowerMockRunner::class) @RunWith(PowerMockRunner::class)
@PrepareForTest(ConstraintChecker::class, RxBusWrapper::class, DetailedBolusInfoStorage::class) @PrepareForTest(ConstraintChecker::class, RxBusWrapper::class, DetailedBolusInfoStorage::class, TemporaryBasalStorage::class)
class DanaRSPluginTest : DanaRSTestBase() { class DanaRSPluginTest : DanaRSTestBase() {
@Mock lateinit var context: Context @Mock lateinit var context: Context

View file

@ -5,7 +5,6 @@ import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBaseWithProfile import info.nightscout.androidaps.TestBaseWithProfile
import info.nightscout.androidaps.dana.DanaPump import info.nightscout.androidaps.dana.DanaPump
import info.nightscout.androidaps.danars.comm.DanaRS_Packet import info.nightscout.androidaps.danars.comm.DanaRS_Packet
import info.nightscout.androidaps.db.TemporaryBasal
import info.nightscout.androidaps.utils.sharedPreferences.SP import info.nightscout.androidaps.utils.sharedPreferences.SP
import org.junit.Before import org.junit.Before
import org.mockito.ArgumentMatchers import org.mockito.ArgumentMatchers
@ -16,16 +15,7 @@ open class DanaRSTestBase : TestBaseWithProfile() {
@Mock lateinit var sp: SP @Mock lateinit var sp: SP
val injector = HasAndroidInjector { val injector = HasAndroidInjector { AndroidInjector { } }
AndroidInjector {
if (it is TemporaryBasal) {
it.aapsLogger = aapsLogger
it.activePlugin = activePluginProvider
it.profileFunction = profileFunction
it.sp = sp
}
}
}
lateinit var danaPump: DanaPump lateinit var danaPump: DanaPump

View file

@ -20,7 +20,7 @@ import org.powermock.modules.junit4.PowerMockRunner
import java.util.* import java.util.*
@RunWith(PowerMockRunner::class) @RunWith(PowerMockRunner::class)
@PrepareForTest(RxBusWrapper::class, DetailedBolusInfoStorage::class, DanaRSPlugin::class) @PrepareForTest(RxBusWrapper::class, DetailedBolusInfoStorage::class, TemporaryBasalStorage::class, DanaRSPlugin::class)
class DanaRsPacketApsHistoryEventsTest : DanaRSTestBase() { class DanaRsPacketApsHistoryEventsTest : DanaRSTestBase() {
@Mock lateinit var context: Context @Mock lateinit var context: Context

View file

@ -34,9 +34,9 @@ class DanaRsPacketBasalGetTemporaryBasalStateTest : DanaRSTestBase() {
putIntToArray(array, 4, 1) putIntToArray(array, 4, 1)
packet.handleMessage(array) packet.handleMessage(array)
Assert.assertTrue(packet.failed) Assert.assertTrue(packet.failed)
Assert.assertTrue(danaPump.isTempBasalInProgress) Assert.assertTrue(packet.isTempBasalInProgress)
Assert.assertEquals(300, danaPump.tempBasalPercent) Assert.assertEquals(300, packet.tempBasalPercent)
Assert.assertEquals(15 * 60, danaPump.tempBasalTotalSec) Assert.assertEquals(15 * 60, packet.tempBasalTotalSec)
Assert.assertEquals("BASAL__TEMPORARY_BASAL_STATE", packet.friendlyName) Assert.assertEquals("BASAL__TEMPORARY_BASAL_STATE", packet.friendlyName)
} }
} }

View file

@ -33,7 +33,6 @@ class DanaRsPacketBolusGetDualBolusTest : DanaRSTestBase() {
packet.handleMessage(array) packet.handleMessage(array)
Assert.assertTrue(packet.failed) Assert.assertTrue(packet.failed)
Assert.assertEquals(1.0, danaPump.bolusStep, 0.0) Assert.assertEquals(1.0, danaPump.bolusStep, 0.0)
Assert.assertEquals(0.55, danaPump.extendedBolusAbsoluteRate, 0.0)
Assert.assertEquals(40.0, danaPump.maxBolus, 0.0) Assert.assertEquals(40.0, danaPump.maxBolus, 0.0)
Assert.assertEquals("BOLUS__GET_DUAL_BOLUS", packet.friendlyName) Assert.assertEquals("BOLUS__GET_DUAL_BOLUS", packet.friendlyName)

View file

@ -31,7 +31,7 @@ class DanaRsPacketBolusGetExtendedBolusStateTest : DanaRSTestBase() {
testValue = 1.0 testValue = 1.0
packet.handleMessage(createArray(11, testValue.toInt().toByte())) packet.handleMessage(createArray(11, testValue.toInt().toByte()))
// is extended bolus in progress // is extended bolus in progress
Assert.assertEquals(testValue == 1.0, danaPump.isExtendedInProgress) Assert.assertEquals(testValue == 1.0, packet.isExtendedInProgress)
Assert.assertEquals(testValue != 0.0, packet.failed) Assert.assertEquals(testValue != 0.0, packet.failed)
Assert.assertEquals("BOLUS__GET_EXTENDED_BOLUS_STATE", packet.friendlyName) Assert.assertEquals("BOLUS__GET_EXTENDED_BOLUS_STATE", packet.friendlyName)
} }

View file

@ -26,10 +26,10 @@ class DanaRsPacketBolusGetExtendedMenuOptionStateTest : DanaRSTestBase() {
// test message decoding // test message decoding
packet.handleMessage(createArray(34, 0.toByte())) packet.handleMessage(createArray(34, 0.toByte()))
// isExtendedInProgress should be false // isExtendedInProgress should be false
Assert.assertEquals(false, danaPump.isExtendedInProgress) Assert.assertEquals(false, packet.isExtendedInProgress)
// assertEquals(false, packet.failed); // assertEquals(false, packet.failed);
packet.handleMessage(createArray(34, 1.toByte())) packet.handleMessage(createArray(34, 1.toByte()))
Assert.assertEquals(true, danaPump.isExtendedInProgress) Assert.assertEquals(true, packet.isExtendedInProgress)
Assert.assertEquals("BOLUS__GET_EXTENDED_MENU_OPTION_STATE", packet.friendlyName) Assert.assertEquals("BOLUS__GET_EXTENDED_MENU_OPTION_STATE", packet.friendlyName)
} }
} }

View file

@ -21,7 +21,7 @@ import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class) @RunWith(PowerMockRunner::class)
@PrepareForTest(ConstraintChecker::class, DetailedBolusInfoStorage::class) @PrepareForTest(ConstraintChecker::class, DetailedBolusInfoStorage::class, TemporaryBasalStorage::class)
class DanaRsPacketBolusSetStepBolusStartTest : DanaRSTestBase() { class DanaRsPacketBolusSetStepBolusStartTest : DanaRSTestBase() {
@Mock lateinit var constraintChecker: ConstraintChecker @Mock lateinit var constraintChecker: ConstraintChecker

View file

@ -44,8 +44,6 @@ class DanaRsPacketGeneralGetMoreInformationTest : DanaRSTestBase() {
Assert.assertFalse(packet.failed) Assert.assertFalse(packet.failed)
Assert.assertEquals(6.0, danaPump.iob, 0.01) Assert.assertEquals(6.0, danaPump.iob, 0.01)
Assert.assertEquals(12.5, danaPump.dailyTotalUnits, 0.01) Assert.assertEquals(12.5, danaPump.dailyTotalUnits, 0.01)
Assert.assertTrue(danaPump.isExtendedInProgress)
Assert.assertEquals(150, danaPump.extendedBolusRemainingMinutes)
val lastBolus = Calendar.getInstance() val lastBolus = Calendar.getInstance()
lastBolus.timeInMillis = danaPump.lastBolusTime lastBolus.timeInMillis = danaPump.lastBolusTime
Assert.assertEquals(15, lastBolus.get(Calendar.HOUR_OF_DAY)) Assert.assertEquals(15, lastBolus.get(Calendar.HOUR_OF_DAY))

View file

@ -24,7 +24,7 @@ import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class) @RunWith(PowerMockRunner::class)
@PrepareForTest(ConstraintChecker::class, RxBusWrapper::class, DetailedBolusInfoStorage::class) @PrepareForTest(ConstraintChecker::class, RxBusWrapper::class, DetailedBolusInfoStorage::class, TemporaryBasalStorage::class)
class DanaRsPacketNotifyDeliveryRateDisplayTest : DanaRSTestBase() { class DanaRsPacketNotifyDeliveryRateDisplayTest : DanaRSTestBase() {
@Mock lateinit var activePlugin: ActivePluginProvider @Mock lateinit var activePlugin: ActivePluginProvider

View file

@ -33,6 +33,7 @@ object SealedClassHelper {
val x = gson.fromJson<T>(jsonReader, innerClass.javaObjectType) val x = gson.fromJson<T>(jsonReader, innerClass.javaObjectType)
jsonReader.endObject() jsonReader.endObject()
// if there a static object, actually return that // if there a static object, actually return that
@Suppress("UNCHECKED_CAST")
return innerClass.objectInstance as T? ?: x return innerClass.objectInstance as T? ?: x
} }

View file

@ -68,9 +68,10 @@ public class OmnipodErosPumpPluginTest {
OmnipodErosPumpPlugin plugin = new OmnipodErosPumpPlugin(injector, aapsLogger, new TestAapsSchedulers(), rxBusWrapper, null, OmnipodErosPumpPlugin plugin = new OmnipodErosPumpPlugin(injector, aapsLogger, new TestAapsSchedulers(), rxBusWrapper, null,
resourceHelper, activePluginProvider, null, null, aapsOmnipodErosManager, commandQueueProvider, resourceHelper, activePluginProvider, null, null, aapsOmnipodErosManager, commandQueueProvider,
null, null, null, null, null, null, null, null,
rileyLinkUtil, null, null, null rileyLinkUtil, null, null, pumpSync
); );
when(pumpSync.expectedPumpState().getTemporaryBasal()).thenReturn(null); PumpSync.PumpState pumpState = new PumpSync.PumpState(null, null, null, null);
when(pumpSync.expectedPumpState()).thenReturn(pumpState);
when(rileyLinkUtil.getRileyLinkHistory()).thenReturn(new ArrayList<>()); when(rileyLinkUtil.getRileyLinkHistory()).thenReturn(new ArrayList<>());
when(injector.androidInjector()).thenReturn(instance -> { when(injector.androidInjector()).thenReturn(instance -> {
}); });