From 7662f3cc45db3e5bac0e50d1674882c2d128963c Mon Sep 17 00:00:00 2001 From: jbr7rr <> Date: Tue, 15 Aug 2023 08:42:20 +0200 Subject: [PATCH] Medtrum: Fix unit tests, more lints --- .../info/nightscout/pump/medtrum/MedtrumPlugin.kt | 12 ++++++------ .../info/nightscout/pump/medtrum/MedtrumTestBase.kt | 2 ++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/MedtrumPlugin.kt b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/MedtrumPlugin.kt index 1b035cc580..e9eb94d844 100644 --- a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/MedtrumPlugin.kt +++ b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/MedtrumPlugin.kt @@ -293,12 +293,12 @@ import kotlin.math.abs val pumpRate = constraintChecker.applyBasalConstraints(Constraint(absoluteRate), profile).value() temporaryBasalStorage.add(PumpSync.PumpState.TemporaryBasal(dateUtil.now(), T.mins(durationInMinutes.toLong()).msecs(), pumpRate, true, tbrType, 0L, 0L)) val connectionOK = medtrumService?.setTempBasal(pumpRate, durationInMinutes) ?: false - if (connectionOK + return if (connectionOK && medtrumPump.tempBasalInProgress && abs(medtrumPump.tempBasalAbsoluteRate - pumpRate) <= 0.05 ) { - return PumpEnactResult(injector).success(true).enacted(true).duration(durationInMinutes).absolute(medtrumPump.tempBasalAbsoluteRate) + PumpEnactResult(injector).success(true).enacted(true).duration(durationInMinutes).absolute(medtrumPump.tempBasalAbsoluteRate) .isPercent(false) .isTempCancel(false) } else { @@ -306,7 +306,7 @@ import kotlin.math.abs LTag.PUMP, "setTempBasalAbsolute failed, connectionOK: $connectionOK, tempBasalInProgress: ${medtrumPump.tempBasalInProgress}, tempBasalAbsoluteRate: ${medtrumPump.tempBasalAbsoluteRate}" ) - return PumpEnactResult(injector).success(false).enacted(false).comment("Medtrum setTempBasalAbsolute failed") + PumpEnactResult(injector).success(false).enacted(false).comment("Medtrum setTempBasalAbsolute failed") } } @@ -325,11 +325,11 @@ import kotlin.math.abs aapsLogger.info(LTag.PUMP, "cancelTempBasal - enforceNew: $enforceNew") val connectionOK = medtrumService?.cancelTempBasal() ?: false - if (connectionOK && !medtrumPump.tempBasalInProgress) { - return PumpEnactResult(injector).success(true).enacted(true).isTempCancel(true) + return if (connectionOK && !medtrumPump.tempBasalInProgress) { + PumpEnactResult(injector).success(true).enacted(true).isTempCancel(true) } else { aapsLogger.error(LTag.PUMP, "cancelTempBasal failed, connectionOK: $connectionOK, tempBasalInProgress: ${medtrumPump.tempBasalInProgress}") - return PumpEnactResult(injector).success(false).enacted(false).comment("Medtrum cancelTempBasal failed") + PumpEnactResult(injector).success(false).enacted(false).comment("Medtrum cancelTempBasal failed") } } diff --git a/pump/medtrum/src/test/java/info/nightscout/pump/medtrum/MedtrumTestBase.kt b/pump/medtrum/src/test/java/info/nightscout/pump/medtrum/MedtrumTestBase.kt index e800fdb118..77e45b6834 100644 --- a/pump/medtrum/src/test/java/info/nightscout/pump/medtrum/MedtrumTestBase.kt +++ b/pump/medtrum/src/test/java/info/nightscout/pump/medtrum/MedtrumTestBase.kt @@ -7,6 +7,7 @@ import info.nightscout.interfaces.pump.TemporaryBasalStorage import info.nightscout.interfaces.stats.TddCalculator import org.junit.jupiter.api.BeforeEach import org.mockito.Mock +import org.mockito.Mockito open class MedtrumTestBase : TestBaseWithProfile() { @@ -19,6 +20,7 @@ open class MedtrumTestBase : TestBaseWithProfile() { @BeforeEach fun setup() { + Mockito.`when`(sp.getString(R.string.key_active_alarms, "")).thenReturn("") medtrumPump = MedtrumPump(aapsLogger, rh, sp, dateUtil, pumpSync, temporaryBasalStorage) } }