From f3fb533cf00801294f95dd1a4de3e040fd994e65 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 18 Feb 2021 21:38:36 +0100 Subject: [PATCH] fix tests and dependencies --- .../aps/openAPSAMA/OpenAPSAMAPlugin.kt | 3 +- .../aps/openAPSSMB/OpenAPSSMBPlugin.kt | 3 +- .../constraints/safety/SafetyPlugin.kt | 3 +- .../general/automation/triggers/Trigger.kt | 12 ++--- .../automation/triggers/TriggerBolusAgo.kt | 2 +- .../automation/triggers/TriggerTempTarget.kt | 2 +- .../general/openhumans/OpenHumansUploader.kt | 2 +- .../smsCommunicator/SmsCommunicatorPlugin.kt | 2 +- .../plugins/pump/combo/ComboPlugin.java | 5 ++- .../pump/insight/LocalInsightPlugin.java | 6 +-- .../plugins/treatments/TreatmentService.java | 25 +++-------- .../plugins/treatments/TreatmentsPlugin.java | 17 ++++--- .../androidaps/TestBaseWithProfile.kt | 5 ++- .../interfaces/ConstraintsCheckerTest.kt | 10 ++--- .../plugins/aps/loop/APSResultTest.kt | 44 +++++++++---------- .../constraints/safety/SafetyPluginTest.kt | 2 +- .../actions/ActionProfileSwitchPercentTest.kt | 4 +- .../actions/ActionProfileSwitchTest.kt | 4 +- .../actions/ActionStartTempTargetTest.kt | 5 +-- .../actions/ActionStopTempTargetTest.kt | 4 +- .../triggers/TriggerBolusAgoTest.kt | 4 +- .../triggers/TriggerTempTargetTest.kt | 4 +- .../automation/triggers/TriggerTestBase.kt | 2 +- .../SmsCommunicatorPluginTest.kt | 8 ++-- .../androidaps/queue/CommandQueueTest.kt | 4 +- .../androidaps/queue/QueueThreadTest.kt | 4 +- .../interfaces/TreatmentServiceInterface.kt | 18 ++++++++ .../interfaces/TreatmentsInterface.java | 3 ++ .../androidaps/interfaces/UpdateReturn.kt | 11 +++++ .../androidaps/TestBaseWithProfile.kt | 14 +++--- .../comm/DanaRSPacketHistoryAlarmTest.kt | 8 +++- 31 files changed, 132 insertions(+), 108 deletions(-) create mode 100644 core/src/main/java/info/nightscout/androidaps/interfaces/TreatmentServiceInterface.kt create mode 100644 core/src/main/java/info/nightscout/androidaps/interfaces/UpdateReturn.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAPlugin.kt index 97a6079e4a..fe15677807 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAPlugin.kt @@ -15,7 +15,6 @@ import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensResult import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin -import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.HardLimits @@ -36,7 +35,7 @@ open class OpenAPSAMAPlugin @Inject constructor( private val profileFunction: ProfileFunction, private val context: Context, private val activePlugin: ActivePluginProvider, - private val treatmentsPlugin: TreatmentsPlugin, + private val treatmentsPlugin: TreatmentsInterface, private val iobCobCalculatorPlugin: IobCobCalculatorPlugin, private val hardLimits: HardLimits, private val profiler: Profiler, diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.kt index f1245810f0..c57e427194 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.kt @@ -17,7 +17,6 @@ import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensResult import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin -import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.HardLimits import info.nightscout.androidaps.utils.Profiler @@ -37,7 +36,7 @@ open class OpenAPSSMBPlugin @Inject constructor( private val profileFunction: ProfileFunction, private val context: Context, private val activePlugin: ActivePluginProvider, - private val treatmentsPlugin: TreatmentsPlugin, + private val treatmentsPlugin: TreatmentsInterface, private val iobCobCalculatorPlugin: IobCobCalculatorPlugin, private val hardLimits: HardLimits, private val profiler: Profiler, diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPlugin.kt index f1a3dde59b..c2cbe83ff7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPlugin.kt @@ -13,7 +13,6 @@ import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification import info.nightscout.androidaps.plugins.general.overview.notifications.Notification import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin -import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.utils.DecimalFormatter import info.nightscout.androidaps.utils.HardLimits import info.nightscout.androidaps.utils.Round @@ -38,7 +37,7 @@ class SafetyPlugin @Inject constructor( private val activePlugin: ActivePluginProvider, private val hardLimits: HardLimits, private val buildHelper: BuildHelper, - private val treatmentsPlugin: TreatmentsPlugin, + private val treatmentsPlugin: TreatmentsInterface, private val config: Config ) : PluginBase(PluginDescription() .mainType(PluginType.CONSTRAINTS) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/Trigger.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/Trigger.kt index fce6bb41c4..def0d59a6c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/Trigger.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/Trigger.kt @@ -11,15 +11,15 @@ import com.google.common.base.Optional import dagger.android.HasAndroidInjector import info.nightscout.androidaps.R import info.nightscout.androidaps.interfaces.ActivePluginProvider +import info.nightscout.androidaps.interfaces.ProfileFunction +import info.nightscout.androidaps.interfaces.TreatmentsInterface import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.plugins.bus.RxBusWrapper -import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.plugins.general.automation.dialogs.ChooseTriggerDialog import info.nightscout.androidaps.plugins.general.automation.events.EventTriggerChanged import info.nightscout.androidaps.plugins.general.automation.events.EventTriggerClone import info.nightscout.androidaps.plugins.general.automation.events.EventTriggerRemove import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin -import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.services.LastLocationDataContainer import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP @@ -29,13 +29,14 @@ import javax.inject.Inject import kotlin.reflect.full.primaryConstructor abstract class Trigger(val injector: HasAndroidInjector) { + @Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var rxBus: RxBusWrapper @Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var profileFunction: ProfileFunction @Inject lateinit var sp: SP @Inject lateinit var locationDataContainer: LastLocationDataContainer - @Inject lateinit var treatmentsPlugin: TreatmentsPlugin + @Inject lateinit var treatmentsInterface: TreatmentsInterface @Inject lateinit var activePlugin: ActivePluginProvider @Inject lateinit var iobCobCalculatorPlugin: IobCobCalculatorPlugin @@ -53,12 +54,13 @@ abstract class Trigger(val injector: HasAndroidInjector) { abstract fun duplicate(): Trigger companion object { + @JvmStatic fun scanForActivity(cont: Context?): AppCompatActivity? { when (cont) { - null -> return null + null -> return null is AppCompatActivity -> return cont - is ContextWrapper -> return scanForActivity(cont.baseContext) + is ContextWrapper -> return scanForActivity(cont.baseContext) else -> return null } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBolusAgo.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBolusAgo.kt index 27f736cf9a..5ff50b561c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBolusAgo.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBolusAgo.kt @@ -35,7 +35,7 @@ class TriggerBolusAgo(injector: HasAndroidInjector) : Trigger(injector) { } override fun shouldRun(): Boolean { - val lastBolusTime = treatmentsPlugin.getLastBolusTime(true) + val lastBolusTime = treatmentsInterface.getLastBolusTime(true) if (lastBolusTime == 0L) return if (comparator.value == Comparator.Compare.IS_NOT_AVAILABLE) { aapsLogger.debug(LTag.AUTOMATION, "Ready for execution: " + friendlyDescription()) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTempTarget.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTempTarget.kt index 26aa0c81b7..25ef553816 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTempTarget.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTempTarget.kt @@ -28,7 +28,7 @@ class TriggerTempTarget(injector: HasAndroidInjector) : Trigger(injector) { } override fun shouldRun(): Boolean { - val tt = treatmentsPlugin.tempTargetFromHistory + val tt = treatmentsInterface.tempTargetFromHistory if (tt == null && comparator.value == ComparatorExists.Compare.NOT_EXISTS) { aapsLogger.debug(LTag.AUTOMATION, "Ready for execution: " + friendlyDescription()) return true diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/openhumans/OpenHumansUploader.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/openhumans/OpenHumansUploader.kt index ecd151e426..31aa345d65 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/openhumans/OpenHumansUploader.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/openhumans/OpenHumansUploader.kt @@ -363,7 +363,7 @@ class OpenHumansUploader @Inject constructor( copyDisposable = Completable.fromCallable { MainApp.getDbHelper().clearOpenHumansQueue() } .andThen(Single.defer { Single.just(MainApp.getDbHelper().countOfAllRows + treatmentsPlugin.service.count()) }) .doOnSuccess { maxProgress = it } - .flatMapObservable { Observable.defer { Observable.fromIterable(treatmentsPlugin.service.treatmentData) } } + .flatMapObservable { Observable.defer { Observable.fromIterable(treatmentsPlugin.service.getTreatmentData()) } } .map { enqueueTreatment(it); increaseCounter() } .ignoreElements() .andThen(Observable.defer { Observable.fromIterable(repository.compatGetBgReadingsDataFromTime(0, true).blockingGet()) }) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt index 92761bfa74..75f4ddc8a3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt @@ -450,7 +450,7 @@ class SmsCommunicatorPlugin @Inject constructor( private fun processTREATMENTS(divided: Array, receivedSms: Sms) { if (divided[1].toUpperCase(Locale.getDefault()) == "REFRESH") { - (activePlugin.activeTreatments as TreatmentsPlugin).service.resetTreatments() + activePlugin.activeTreatments.service.resetTreatments() rxBus.send(EventNSClientRestart()) sendSMS(Sms(receivedSms.phoneNumber, "TREATMENTS REFRESH SENT")) receivedSms.processed = true diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java index 15ae4409ad..354468f7aa 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java @@ -41,6 +41,7 @@ import info.nightscout.androidaps.interfaces.ProfileFunction; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.PumpPluginBase; +import info.nightscout.androidaps.interfaces.TreatmentsInterface; import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.plugins.bus.RxBusWrapper; @@ -80,7 +81,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr private final ResourceHelper resourceHelper; private final ProfileFunction profileFunction; - private final TreatmentsPlugin treatmentsPlugin; + private final TreatmentsInterface treatmentsPlugin; private final info.nightscout.androidaps.utils.sharedPreferences.SP sp; private RxBusWrapper rxBus; private final CommandQueueProvider commandQueue; @@ -136,7 +137,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr RxBusWrapper rxBus, ResourceHelper resourceHelper, ProfileFunction profileFunction, - TreatmentsPlugin treatmentsPlugin, + TreatmentsInterface treatmentsPlugin, SP sp, CommandQueueProvider commandQueue, Context context diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java index f5b46ffc9e..638439e728 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java @@ -49,6 +49,7 @@ import info.nightscout.androidaps.interfaces.ProfileFunction; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.PumpPluginBase; +import info.nightscout.androidaps.interfaces.TreatmentsInterface; import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.plugins.bus.RxBusWrapper; @@ -129,7 +130,6 @@ import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_erro import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.NoActiveTBRToCanceLException; import info.nightscout.androidaps.plugins.pump.insight.utils.ExceptionTranslator; import info.nightscout.androidaps.plugins.pump.insight.utils.ParameterBlockUtil; -import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.TimeChangeType; import info.nightscout.androidaps.utils.resources.ResourceHelper; @@ -141,7 +141,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface, private final AAPSLogger aapsLogger; private final RxBusWrapper rxBus; private final ResourceHelper resourceHelper; - private final TreatmentsPlugin treatmentsPlugin; + private final TreatmentsInterface treatmentsPlugin; private final SP sp; private final CommandQueueProvider commandQueue; private final ProfileFunction profileFunction; @@ -203,7 +203,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface, AAPSLogger aapsLogger, RxBusWrapper rxBus, ResourceHelper resourceHelper, - TreatmentsPlugin treatmentsPlugin, + TreatmentsInterface treatmentsPlugin, SP sp, CommandQueueProvider commandQueue, ProfileFunction profileFunction, diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentService.java b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentService.java index 49d1070b7d..a4f85e3882 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentService.java @@ -16,6 +16,7 @@ import com.j256.ormlite.support.ConnectionSource; import com.j256.ormlite.table.TableUtils; import org.apache.commons.lang3.StringUtils; +import org.jetbrains.annotations.NotNull; import org.json.JSONException; import org.json.JSONObject; @@ -39,6 +40,8 @@ import info.nightscout.androidaps.events.EventNsTreatment; import info.nightscout.androidaps.events.EventReloadTreatmentData; import info.nightscout.androidaps.events.EventTreatmentChange; import info.nightscout.androidaps.interfaces.DatabaseHelperInterface; +import info.nightscout.androidaps.interfaces.TreatmentServiceInterface; +import info.nightscout.androidaps.interfaces.UpdateReturn; import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.plugins.bus.RxBusWrapper; @@ -57,7 +60,7 @@ import io.reactivex.disposables.CompositeDisposable; * Created by mike on 24.09.2017. */ -public class TreatmentService extends OrmLiteBaseService { +public class TreatmentService extends OrmLiteBaseService implements TreatmentServiceInterface { @Inject AAPSLogger aapsLogger; @Inject FabricPrivacy fabricPrivacy; @@ -471,7 +474,7 @@ public class TreatmentService extends OrmLiteBaseService { } - public UpdateReturn createOrUpdateMedtronic(Treatment treatment, boolean fromNightScout) { + @NotNull public UpdateReturn createOrUpdateMedtronic(@NotNull Treatment treatment, boolean fromNightScout) { if (MedtronicHistoryData.doubleBolusDebug) aapsLogger.debug(LTag.DATATREATMENTS, "DoubleBolusDebug: createOrUpdateMedtronic:: originalTreatment={}, fromNightScout={}", treatment, fromNightScout); @@ -821,22 +824,4 @@ public class TreatmentService extends OrmLiteBaseService { return null; } - public class UpdateReturn { - public UpdateReturn(boolean success, boolean newRecord) { - this.success = success; - this.newRecord = newRecord; - } - - boolean newRecord; - boolean success; - - @Override - public String toString() { - return "UpdateReturn [" + - "newRecord=" + newRecord + - ", success=" + success + - ']'; - } - } - } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java index dbb4846bde..41e3673493 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java @@ -46,7 +46,9 @@ import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.ProfileFunction; import info.nightscout.androidaps.interfaces.ProfileStore; import info.nightscout.androidaps.interfaces.PumpInterface; +import info.nightscout.androidaps.interfaces.TreatmentServiceInterface; import info.nightscout.androidaps.interfaces.TreatmentsInterface; +import info.nightscout.androidaps.interfaces.UpdateReturn; import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.plugins.bus.RxBusWrapper; @@ -82,7 +84,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface private final CompositeDisposable disposable = new CompositeDisposable(); - protected TreatmentService service; + protected TreatmentServiceInterface service; private IobTotal lastTreatmentCalculation; private IobTotal lastTempBasalsCalculation; @@ -180,7 +182,8 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface super.onStop(); } - public TreatmentService getService() { + @Override + public TreatmentServiceInterface getService() { return this.service; } @@ -620,9 +623,9 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface } public TreatmentUpdateReturn createOrUpdateMedtronic(Treatment treatment, boolean fromNightScout) { - TreatmentService.UpdateReturn resultRecord = getService().createOrUpdateMedtronic(treatment, fromNightScout); + UpdateReturn resultRecord = getService().createOrUpdateMedtronic(treatment, fromNightScout); - return new TreatmentUpdateReturn(resultRecord.success, resultRecord.newRecord); + return new TreatmentUpdateReturn(resultRecord.getSuccess(), resultRecord.getNewRecord()); } // return true if new record is created @@ -643,7 +646,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface treatment.carbs = detailedBolusInfo.carbs; treatment.mealBolus = treatment.carbs > 0; treatment.boluscalc = detailedBolusInfo.boluscalc != null ? detailedBolusInfo.boluscalc.toString() : null; - TreatmentService.UpdateReturn creatOrUpdateResult; + UpdateReturn creatOrUpdateResult; getAapsLogger().debug(medtronicPump && MedtronicHistoryData.doubleBolusDebug, LTag.DATATREATMENTS, "DoubleBolusDebug: addToHistoryTreatment::treatment={} " + treatment); @@ -652,7 +655,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface else creatOrUpdateResult = getService().createOrUpdateMedtronic(treatment, false); - boolean newRecordCreated = creatOrUpdateResult.newRecord; + boolean newRecordCreated = creatOrUpdateResult.getNewRecord(); //log.debug("Adding new Treatment record" + treatment.toString()); if (detailedBolusInfo.carbTime != 0) { @@ -673,7 +676,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface if (newRecordCreated && detailedBolusInfo.isValid) nsUpload.uploadTreatmentRecord(detailedBolusInfo); - if (!allowUpdate && !creatOrUpdateResult.success) { + if (!allowUpdate && !creatOrUpdateResult.getSuccess()) { getAapsLogger().error("Treatment could not be added to DB", new Exception()); String status = String.format(resourceHelper.gs(R.string.error_adding_treatment_message), treatment.insulin, (int) treatment.carbs, dateUtil.dateAndTimeString(treatment.date)); diff --git a/app/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt b/app/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt index 10ffa5c70f..e3e5c7391b 100644 --- a/app/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt +++ b/app/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt @@ -20,12 +20,13 @@ import org.junit.Before import org.mockito.Mock import org.powermock.core.classloader.annotations.PrepareForTest +@Suppress("SpellCheckingInspection") @PrepareForTest(FabricPrivacy::class) open class TestBaseWithProfile : TestBase() { @Mock lateinit var activePluginProvider: ActivePluginProvider @Mock lateinit var resourceHelper: ResourceHelper - @Mock lateinit var treatmentsPlugin: TreatmentsInterface + @Mock lateinit var treatmentsInterface: TreatmentsInterface @Mock lateinit var fabricPrivacy: FabricPrivacy @Mock lateinit var profileFunction: ProfileFunction @Mock lateinit var defaultValueHelper: DefaultValueHelper @@ -45,7 +46,7 @@ open class TestBaseWithProfile : TestBase() { it.configInterface = configInterface } if (it is ProfileSwitch) { - it.treatmentsPlugin = treatmentsPlugin + it.treatmentsPlugin = treatmentsInterface it.aapsLogger = aapsLogger it.rxBus = rxBus it.resourceHelper = resourceHelper diff --git a/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt b/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt index 0fc6acac16..df2e00d3af 100644 --- a/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt @@ -123,13 +123,13 @@ class ConstraintsCheckerTest : TestBaseWithProfile() { danaPump = DanaPump(aapsLogger, sp, injector) hardLimits = HardLimits(aapsLogger, rxBus, sp, resourceHelper, context, nsUpload) objectivesPlugin = ObjectivesPlugin(injector, aapsLogger, resourceHelper, activePlugin, sp, Config(), uel) - comboPlugin = ComboPlugin(injector, aapsLogger, rxBus, resourceHelper, profileFunction, treatmentsPlugin, sp, commandQueue, context) + comboPlugin = ComboPlugin(injector, aapsLogger, rxBus, resourceHelper, profileFunction, treatmentsInterface, sp, commandQueue, context) danaRPlugin = DanaRPlugin(injector, aapsLogger, aapsSchedulers, rxBus, context, resourceHelper, constraintChecker, activePlugin, sp, commandQueue, danaPump, dateUtil, fabricPrivacy) danaRSPlugin = DanaRSPlugin(injector, aapsLogger, aapsSchedulers, rxBus, context, resourceHelper, constraintChecker, profileFunction, activePluginProvider, sp, commandQueue, danaPump, detailedBolusInfoStorage, fabricPrivacy, dateUtil) - insightPlugin = LocalInsightPlugin(injector, aapsLogger, rxBus, resourceHelper, treatmentsPlugin, sp, commandQueue, profileFunction, nsUpload, context, uploadQueue, Config(), dateUtil) - openAPSSMBPlugin = OpenAPSSMBPlugin(injector, aapsLogger, rxBus, constraintChecker, resourceHelper, profileFunction, context, activePlugin, treatmentsPlugin, iobCobCalculatorPlugin, hardLimits, profiler, sp) - openAPSAMAPlugin = OpenAPSAMAPlugin(injector, aapsLogger, rxBus, constraintChecker, resourceHelper, profileFunction, context, activePlugin, treatmentsPlugin, iobCobCalculatorPlugin, hardLimits, profiler, fabricPrivacy) - safetyPlugin = SafetyPlugin(injector, aapsLogger, resourceHelper, sp, rxBus, constraintChecker, openAPSAMAPlugin, openAPSSMBPlugin, sensitivityOref1Plugin, activePlugin, hardLimits, BuildHelper(Config(), loggerUtils), treatmentsPlugin, Config()) + insightPlugin = LocalInsightPlugin(injector, aapsLogger, rxBus, resourceHelper, treatmentsInterface, sp, commandQueue, profileFunction, nsUpload, context, uploadQueue, Config(), dateUtil) + openAPSSMBPlugin = OpenAPSSMBPlugin(injector, aapsLogger, rxBus, constraintChecker, resourceHelper, profileFunction, context, activePlugin, treatmentsInterface, iobCobCalculatorPlugin, hardLimits, profiler, sp) + openAPSAMAPlugin = OpenAPSAMAPlugin(injector, aapsLogger, rxBus, constraintChecker, resourceHelper, profileFunction, context, activePlugin, treatmentsInterface, iobCobCalculatorPlugin, hardLimits, profiler, fabricPrivacy) + safetyPlugin = SafetyPlugin(injector, aapsLogger, resourceHelper, sp, rxBus, constraintChecker, openAPSAMAPlugin, openAPSSMBPlugin, sensitivityOref1Plugin, activePlugin, hardLimits, BuildHelper(Config(), loggerUtils), treatmentsInterface, Config()) val constraintsPluginsList = ArrayList() constraintsPluginsList.add(safetyPlugin) constraintsPluginsList.add(objectivesPlugin) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/aps/loop/APSResultTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/aps/loop/APSResultTest.kt index 3c7b148760..0b922eea35 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/aps/loop/APSResultTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/aps/loop/APSResultTest.kt @@ -43,7 +43,7 @@ class APSResultTest : TestBaseWithProfile() { it.constraintChecker = constraintChecker it.sp = sp it.activePlugin = activePluginProvider - it.treatmentsPlugin = treatmentsPlugin + it.treatmentsPlugin = treatmentsInterface it.profileFunction = profileFunction it.resourceHelper = resourceHelper } @@ -56,7 +56,7 @@ class APSResultTest : TestBaseWithProfile() { // closed loop mode return original request closedLoopEnabled.set(aapsLogger, true) - `when`(treatmentsPlugin.getTempBasalFromHistory(ArgumentMatchers.anyLong())).thenReturn(null) + `when`(treatmentsInterface.getTempBasalFromHistory(ArgumentMatchers.anyLong())).thenReturn(null) apsResult.tempBasalRequested(false) Assert.assertEquals(false, apsResult.isChangeRequested) apsResult.tempBasalRequested(true).percent(200).duration(30) @@ -65,46 +65,46 @@ class APSResultTest : TestBaseWithProfile() { // open loop closedLoopEnabled.set(aapsLogger, false) // no change requested - `when`(treatmentsPlugin.getTempBasalFromHistory(ArgumentMatchers.anyLong())).thenReturn(null) + `when`(treatmentsInterface.getTempBasalFromHistory(ArgumentMatchers.anyLong())).thenReturn(null) apsResult.tempBasalRequested(false) Assert.assertEquals(false, apsResult.isChangeRequested) // request 100% when no temp is running - `when`(treatmentsPlugin.getTempBasalFromHistory(ArgumentMatchers.anyLong())).thenReturn(null) + `when`(treatmentsInterface.getTempBasalFromHistory(ArgumentMatchers.anyLong())).thenReturn(null) apsResult.tempBasalRequested(true).percent(100).duration(30) Assert.assertEquals(false, apsResult.isChangeRequested) // request equal temp - `when`(treatmentsPlugin.getTempBasalFromHistory(ArgumentMatchers.anyLong())).thenReturn(TemporaryBasal(injector).percent(70).duration(30)) + `when`(treatmentsInterface.getTempBasalFromHistory(ArgumentMatchers.anyLong())).thenReturn(TemporaryBasal(injector).percent(70).duration(30)) apsResult.tempBasalRequested(true).percent(70).duration(30) Assert.assertEquals(false, apsResult.isChangeRequested) // request zero temp - `when`(treatmentsPlugin.getTempBasalFromHistory(ArgumentMatchers.anyLong())).thenReturn(TemporaryBasal(injector).percent(10).duration(30)) + `when`(treatmentsInterface.getTempBasalFromHistory(ArgumentMatchers.anyLong())).thenReturn(TemporaryBasal(injector).percent(10).duration(30)) apsResult.tempBasalRequested(true).percent(0).duration(30) Assert.assertEquals(true, apsResult.isChangeRequested) // request high temp - `when`(treatmentsPlugin.getTempBasalFromHistory(ArgumentMatchers.anyLong())).thenReturn(TemporaryBasal(injector).percent(190).duration(30)) + `when`(treatmentsInterface.getTempBasalFromHistory(ArgumentMatchers.anyLong())).thenReturn(TemporaryBasal(injector).percent(190).duration(30)) apsResult.tempBasalRequested(true).percent(200).duration(30) Assert.assertEquals(true, apsResult.isChangeRequested) // request slightly different temp - `when`(treatmentsPlugin.getTempBasalFromHistory(ArgumentMatchers.anyLong())).thenReturn(TemporaryBasal(injector).percent(70).duration(30)) + `when`(treatmentsInterface.getTempBasalFromHistory(ArgumentMatchers.anyLong())).thenReturn(TemporaryBasal(injector).percent(70).duration(30)) apsResult.tempBasalRequested(true).percent(80).duration(30) Assert.assertEquals(false, apsResult.isChangeRequested) // request different temp - `when`(treatmentsPlugin.getTempBasalFromHistory(ArgumentMatchers.anyLong())).thenReturn(TemporaryBasal(injector).percent(70).duration(30)) + `when`(treatmentsInterface.getTempBasalFromHistory(ArgumentMatchers.anyLong())).thenReturn(TemporaryBasal(injector).percent(70).duration(30)) apsResult.tempBasalRequested(true).percent(120).duration(30) Assert.assertEquals(true, apsResult.isChangeRequested) // it should work with absolute temps too // request different temp - `when`(treatmentsPlugin.getTempBasalFromHistory(ArgumentMatchers.anyLong())).thenReturn(TemporaryBasal(injector).absolute(1.0).duration(30)) + `when`(treatmentsInterface.getTempBasalFromHistory(ArgumentMatchers.anyLong())).thenReturn(TemporaryBasal(injector).absolute(1.0).duration(30)) apsResult.tempBasalRequested(true).percent(100).duration(30) Assert.assertEquals(false, apsResult.isChangeRequested) - `when`(treatmentsPlugin.getTempBasalFromHistory(ArgumentMatchers.anyLong())).thenReturn(TemporaryBasal(injector).absolute(2.0).duration(30)) + `when`(treatmentsInterface.getTempBasalFromHistory(ArgumentMatchers.anyLong())).thenReturn(TemporaryBasal(injector).absolute(2.0).duration(30)) apsResult.tempBasalRequested(true).percent(50).duration(30) Assert.assertEquals(true, apsResult.isChangeRequested) @@ -115,44 +115,44 @@ class APSResultTest : TestBaseWithProfile() { // open loop closedLoopEnabled.set(aapsLogger, false) // request 100% when no temp is running - `when`(treatmentsPlugin.getTempBasalFromHistory(ArgumentMatchers.anyLong())).thenReturn(null) + `when`(treatmentsInterface.getTempBasalFromHistory(ArgumentMatchers.anyLong())).thenReturn(null) apsResult.tempBasalRequested(true).rate(1.0).duration(30) Assert.assertEquals(false, apsResult.isChangeRequested) // request equal temp - `when`(treatmentsPlugin.getTempBasalFromHistory(ArgumentMatchers.anyLong())).thenReturn(TemporaryBasal(injector).absolute(2.0).duration(30)) + `when`(treatmentsInterface.getTempBasalFromHistory(ArgumentMatchers.anyLong())).thenReturn(TemporaryBasal(injector).absolute(2.0).duration(30)) apsResult.tempBasalRequested(true).rate(2.0).duration(30) Assert.assertEquals(false, apsResult.isChangeRequested) - `when`(treatmentsPlugin.getTempBasalFromHistory(ArgumentMatchers.anyLong())).thenReturn(TemporaryBasal(injector).percent(200).duration(30)) + `when`(treatmentsInterface.getTempBasalFromHistory(ArgumentMatchers.anyLong())).thenReturn(TemporaryBasal(injector).percent(200).duration(30)) apsResult.tempBasalRequested(true).rate(2.0).duration(30) Assert.assertEquals(false, apsResult.isChangeRequested) // request zero temp - `when`(treatmentsPlugin.getTempBasalFromHistory(ArgumentMatchers.anyLong())).thenReturn(TemporaryBasal(injector).absolute(0.1).duration(30)) + `when`(treatmentsInterface.getTempBasalFromHistory(ArgumentMatchers.anyLong())).thenReturn(TemporaryBasal(injector).absolute(0.1).duration(30)) apsResult.tempBasalRequested(true).rate(0.0).duration(30) Assert.assertEquals(true, apsResult.isChangeRequested) // request high temp - `when`(treatmentsPlugin.getTempBasalFromHistory(ArgumentMatchers.anyLong())).thenReturn(TemporaryBasal(injector).absolute(34.9).duration(30)) + `when`(treatmentsInterface.getTempBasalFromHistory(ArgumentMatchers.anyLong())).thenReturn(TemporaryBasal(injector).absolute(34.9).duration(30)) apsResult.tempBasalRequested(true).rate(35.0).duration(30) Assert.assertEquals(true, apsResult.isChangeRequested) // request slightly different temp - `when`(treatmentsPlugin.getTempBasalFromHistory(ArgumentMatchers.anyLong())).thenReturn(TemporaryBasal(injector).absolute(1.1).duration(30)) + `when`(treatmentsInterface.getTempBasalFromHistory(ArgumentMatchers.anyLong())).thenReturn(TemporaryBasal(injector).absolute(1.1).duration(30)) apsResult.tempBasalRequested(true).rate(1.2).duration(30) Assert.assertEquals(false, apsResult.isChangeRequested) // request different temp - `when`(treatmentsPlugin.getTempBasalFromHistory(ArgumentMatchers.anyLong())).thenReturn(TemporaryBasal(injector).absolute(1.1).duration(30)) + `when`(treatmentsInterface.getTempBasalFromHistory(ArgumentMatchers.anyLong())).thenReturn(TemporaryBasal(injector).absolute(1.1).duration(30)) apsResult.tempBasalRequested(true).rate(1.5).duration(30) Assert.assertEquals(true, apsResult.isChangeRequested) // it should work with percent temps too // request different temp - `when`(treatmentsPlugin.getTempBasalFromHistory(ArgumentMatchers.anyLong())).thenReturn(TemporaryBasal(injector).percent(110).duration(30)) + `when`(treatmentsInterface.getTempBasalFromHistory(ArgumentMatchers.anyLong())).thenReturn(TemporaryBasal(injector).percent(110).duration(30)) apsResult.tempBasalRequested(true).rate(1.1).duration(30) Assert.assertEquals(false, apsResult.isChangeRequested) - `when`(treatmentsPlugin.getTempBasalFromHistory(ArgumentMatchers.anyLong())).thenReturn(TemporaryBasal(injector).percent(200).duration(30)) + `when`(treatmentsInterface.getTempBasalFromHistory(ArgumentMatchers.anyLong())).thenReturn(TemporaryBasal(injector).percent(200).duration(30)) apsResult.tempBasalRequested(true).rate(0.5).duration(30) Assert.assertEquals(true, apsResult.isChangeRequested) } @@ -164,7 +164,7 @@ class APSResultTest : TestBaseWithProfile() { it.constraintChecker = constraintChecker it.sp = sp it.activePlugin = activePluginProvider - it.treatmentsPlugin = treatmentsPlugin + it.treatmentsPlugin = treatmentsInterface it.profileFunction = profileFunction it.resourceHelper = resourceHelper } @@ -181,7 +181,7 @@ class APSResultTest : TestBaseWithProfile() { it.constraintChecker = constraintChecker it.sp = sp it.activePlugin = activePluginProvider - it.treatmentsPlugin = treatmentsPlugin + it.treatmentsPlugin = treatmentsInterface it.profileFunction = profileFunction it.resourceHelper = resourceHelper } diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPluginTest.kt index 4f85fb9b02..75b01f02e6 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPluginTest.kt @@ -76,7 +76,7 @@ class SafetyPluginTest : TestBaseWithProfile() { `when`(activePlugin.activePump).thenReturn(virtualPumpPlugin) `when`(virtualPumpPlugin.pumpDescription).thenReturn(pumpDescription) hardLimits = HardLimits(aapsLogger, rxBus, sp, resourceHelper, context, nsUpload) - safetyPlugin = SafetyPlugin(injector, aapsLogger, resourceHelper, sp, rxBus, constraintChecker, openAPSAMAPlugin, openAPSSMBPlugin, sensitivityOref1Plugin, activePlugin, hardLimits, buildHelper, treatmentsPlugin, Config()) + safetyPlugin = SafetyPlugin(injector, aapsLogger, resourceHelper, sp, rxBus, constraintChecker, openAPSAMAPlugin, openAPSSMBPlugin, sensitivityOref1Plugin, activePlugin, hardLimits, buildHelper, treatmentsInterface, Config()) } @Test fun pumpDescriptionShouldLimitLoopInvocation() { diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitchPercentTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitchPercentTest.kt index dd324e3373..d2b5180756 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitchPercentTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitchPercentTest.kt @@ -20,7 +20,7 @@ class ActionProfileSwitchPercentTest : ActionsTestBase() { @Before fun setup() { - `when`(activePlugin.activeTreatments).thenReturn(treatmentsPlugin) + `when`(activePlugin.activeTreatments).thenReturn(treatmentsInterface) `when`(resourceHelper.gs(R.string.startprofileforever)).thenReturn("Start profile %d%%") `when`(resourceHelper.gs(R.string.startprofile)).thenReturn("Start profile %d%% for %d min") @@ -49,7 +49,7 @@ class ActionProfileSwitchPercentTest : ActionsTestBase() { Assert.assertTrue(result.success) } }) - Mockito.verify(treatmentsPlugin, Mockito.times(1)).doProfileSwitch(30, 110, 0) + Mockito.verify(treatmentsInterface, Mockito.times(1)).doProfileSwitch(30, 110, 0) } @Test fun hasDialogTest() { diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitchTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitchTest.kt index 569ab4d0da..f7e7c52f5a 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitchTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitchTest.kt @@ -26,7 +26,7 @@ class ActionProfileSwitchTest : ActionsTestBase() { private val stringJson = "{\"data\":{\"profileToSwitchTo\":\"Test\"},\"type\":\"info.nightscout.androidaps.plugins.general.automation.actions.ActionProfileSwitch\"}" @Before fun setUp() { - `when`(activePlugin.activeTreatments).thenReturn(treatmentsPlugin) + `when`(activePlugin.activeTreatments).thenReturn(treatmentsInterface) `when`(resourceHelper.gs(R.string.profilename)).thenReturn("Change profile to") `when`(resourceHelper.gs(ArgumentMatchers.eq(R.string.changengetoprofilename), ArgumentMatchers.anyString())).thenReturn("Change profile to %s") `when`(resourceHelper.gs(R.string.alreadyset)).thenReturn("Already set") @@ -97,7 +97,7 @@ class ActionProfileSwitchTest : ActionsTestBase() { Assert.assertEquals("OK", result.comment) } }) - Mockito.verify(treatmentsPlugin, Mockito.times(1)).doProfileSwitch(anyObject(), anyString(), anyInt(), anyInt(), anyInt(), anyLong()) + Mockito.verify(treatmentsInterface, Mockito.times(1)).doProfileSwitch(anyObject(), anyString(), anyInt(), anyInt(), anyInt(), anyLong()) } @Test fun hasDialogTest() { diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTargetTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTargetTest.kt index b3e06b29e8..5988e3519a 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTargetTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTargetTest.kt @@ -12,7 +12,6 @@ import org.junit.Test import org.junit.runner.RunWith import org.mockito.Mockito import org.mockito.Mockito.`when` -import org.powermock.api.mockito.PowerMockito import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @@ -45,13 +44,13 @@ class ActionStartTempTargetTest : ActionsTestBase() { } @Test fun doActionTest() { - `when`(activePlugin.activeTreatments).thenReturn(treatmentsPlugin) + `when`(activePlugin.activeTreatments).thenReturn(treatmentsInterface) sut.doAction(object : Callback() { override fun run() { Assert.assertTrue(result.success) } }) - Mockito.verify(treatmentsPlugin, Mockito.times(1)).addToHistoryTempTarget(anyObject()) + Mockito.verify(treatmentsInterface, Mockito.times(1)).addToHistoryTempTarget(anyObject()) } @Test fun hasDialogTest() { diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStopTempTargetTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStopTempTargetTest.kt index 069d06cfbe..bf5ce1551e 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStopTempTargetTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStopTempTargetTest.kt @@ -38,13 +38,13 @@ class ActionStopTempTargetTest : ActionsTestBase() { } @Test fun doActionTest() { - `when`(activePlugin.activeTreatments).thenReturn(treatmentsPlugin) + `when`(activePlugin.activeTreatments).thenReturn(treatmentsInterface) sut.doAction(object : Callback() { override fun run() { Assert.assertTrue(result.success) } }) - Mockito.verify(treatmentsPlugin, Mockito.times(1)).addToHistoryTempTarget(anyObject()) + Mockito.verify(treatmentsInterface, Mockito.times(1)).addToHistoryTempTarget(anyObject()) } @Test fun hasDialogTest() { diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBolusAgoTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBolusAgoTest.kt index b1aefd5b3a..ad087bf69c 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBolusAgoTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBolusAgoTest.kt @@ -30,7 +30,7 @@ class TriggerBolusAgoTest : TriggerTestBase() { @Test fun shouldRunTest() { - `when`(treatmentsPlugin.getLastBolusTime(true)).thenReturn(now) // Set last bolus time to now + `when`(treatmentsInterface.getLastBolusTime(true)).thenReturn(now) // Set last bolus time to now `when`(DateUtil.now()).thenReturn(now + 10 * 60 * 1000) // set current time to now + 10 min var t = TriggerBolusAgo(injector).setValue(110).comparator(Comparator.Compare.IS_EQUAL) Assert.assertEquals(110, t.minutesAgo.value) @@ -53,7 +53,7 @@ class TriggerBolusAgoTest : TriggerTestBase() { Assert.assertTrue(t.shouldRun()) t = TriggerBolusAgo(injector).setValue(390).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER) Assert.assertTrue(t.shouldRun()) - PowerMockito.`when`(treatmentsPlugin.getLastBolusTime(true)).thenReturn(0L) // Set last bolus time to 0 + PowerMockito.`when`(treatmentsInterface.getLastBolusTime(true)).thenReturn(0L) // Set last bolus time to 0 t = TriggerBolusAgo(injector).comparator(Comparator.Compare.IS_NOT_AVAILABLE) Assert.assertTrue(t.shouldRun()) } diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTempTargetTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTempTargetTest.kt index 9632e3aa78..a37108d6f6 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTempTargetTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTempTargetTest.kt @@ -28,12 +28,12 @@ class TriggerTempTargetTest : TriggerTestBase() { } @Test fun shouldRunTest() { - `when`(treatmentsPlugin.tempTargetFromHistory).thenReturn(null) + `when`(treatmentsInterface.tempTargetFromHistory).thenReturn(null) var t: TriggerTempTarget = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.EXISTS) Assert.assertFalse(t.shouldRun()) t = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.NOT_EXISTS) Assert.assertTrue(t.shouldRun()) - PowerMockito.`when`(treatmentsPlugin.tempTargetFromHistory).thenReturn(TempTarget()) + PowerMockito.`when`(treatmentsInterface.tempTargetFromHistory).thenReturn(TempTarget()) t = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.NOT_EXISTS) Assert.assertFalse(t.shouldRun()) t = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.EXISTS) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTestBase.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTestBase.kt index c669a78c1c..f439403553 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTestBase.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTestBase.kt @@ -45,7 +45,7 @@ open class TriggerTestBase : TestBaseWithProfile() { it.profileFunction = profileFunction it.sp = sp it.locationDataContainer = locationDataContainer - it.treatmentsPlugin = treatmentsPlugin + it.treatmentsInterface = treatmentsInterface it.activePlugin = activePlugin it.iobCobCalculatorPlugin = iobCobCalculatorPlugin } diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPluginTest.kt index 38558f5e84..d52904378f 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPluginTest.kt @@ -154,16 +154,16 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { }.`when`(commandQueue).extendedBolus(ArgumentMatchers.anyDouble(), ArgumentMatchers.anyInt(), ArgumentMatchers.any(Callback::class.java)) `when`(activePlugin.activePump).thenReturn(virtualPumpPlugin) - `when`(activePlugin.activeTreatments).thenReturn(treatmentsPlugin) + `when`(activePlugin.activeTreatments).thenReturn(treatmentsInterface) `when`(virtualPumpPlugin.shortStatus(ArgumentMatchers.anyBoolean())).thenReturn("Virtual Pump") `when`(virtualPumpPlugin.isSuspended()).thenReturn(false) `when`(virtualPumpPlugin.pumpDescription).thenReturn(PumpDescription()) `when`(virtualPumpPlugin.model()).thenReturn(PumpType.GenericAAPS) - `when`(treatmentsPlugin.lastCalculationTreatments).thenReturn(IobTotal(0)) - `when`(treatmentsPlugin.lastCalculationTempBasals).thenReturn(IobTotal(0)) - `when`(treatmentsPlugin.service).thenReturn(treatmentService) + `when`(treatmentsInterface.lastCalculationTreatments).thenReturn(IobTotal(0)) + `when`(treatmentsInterface.lastCalculationTempBasals).thenReturn(IobTotal(0)) + `when`(treatmentsInterface.service).thenReturn(treatmentService) `when`(activePlugin.activeProfileInterface).thenReturn(localProfilePlugin) diff --git a/app/src/test/java/info/nightscout/androidaps/queue/CommandQueueTest.kt b/app/src/test/java/info/nightscout/androidaps/queue/CommandQueueTest.kt index 90a77637f9..9673e1ba38 100644 --- a/app/src/test/java/info/nightscout/androidaps/queue/CommandQueueTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/queue/CommandQueueTest.kt @@ -107,8 +107,8 @@ class CommandQueueTest : TestBaseWithProfile() { `when`(context.getSystemService(Context.POWER_SERVICE)).thenReturn(powerManager) `when`(lazyActivePlugin.get()).thenReturn(activePlugin) `when`(activePlugin.activePump).thenReturn(testPumpPlugin) - `when`(activePlugin.activeTreatments).thenReturn(treatmentsPlugin) - `when`(treatmentsPlugin.lastBolusTime).thenReturn(Calendar.getInstance().also { it.set(2000, 0, 1) }.timeInMillis) + `when`(activePlugin.activeTreatments).thenReturn(treatmentsInterface) + `when`(treatmentsInterface.lastBolusTime).thenReturn(Calendar.getInstance().also { it.set(2000, 0, 1) }.timeInMillis) `when`(profileFunction.getProfile()).thenReturn(validProfile) val bolusConstraint = Constraint(0.0) diff --git a/app/src/test/java/info/nightscout/androidaps/queue/QueueThreadTest.kt b/app/src/test/java/info/nightscout/androidaps/queue/QueueThreadTest.kt index 55e7aa55a5..d44a52bdb4 100644 --- a/app/src/test/java/info/nightscout/androidaps/queue/QueueThreadTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/queue/QueueThreadTest.kt @@ -72,8 +72,8 @@ class QueueThreadTest : TestBaseWithProfile() { Mockito.`when`(context.getSystemService(Context.POWER_SERVICE)).thenReturn(powerManager) Mockito.`when`(lazyActivePlugin.get()).thenReturn(activePlugin) Mockito.`when`(activePlugin.activePump).thenReturn(pumpPlugin) - Mockito.`when`(activePlugin.activeTreatments).thenReturn(treatmentsPlugin) - Mockito.`when`(treatmentsPlugin.lastBolusTime).thenReturn(Calendar.getInstance().also { it.set(2000, 0, 1) }.timeInMillis) + Mockito.`when`(activePlugin.activeTreatments).thenReturn(treatmentsInterface) + Mockito.`when`(treatmentsInterface.lastBolusTime).thenReturn(Calendar.getInstance().also { it.set(2000, 0, 1) }.timeInMillis) Mockito.`when`(profileFunction.getProfile()).thenReturn(validProfile) val bolusConstraint = Constraint(0.0) diff --git a/core/src/main/java/info/nightscout/androidaps/interfaces/TreatmentServiceInterface.kt b/core/src/main/java/info/nightscout/androidaps/interfaces/TreatmentServiceInterface.kt new file mode 100644 index 0000000000..ff3aaa114f --- /dev/null +++ b/core/src/main/java/info/nightscout/androidaps/interfaces/TreatmentServiceInterface.kt @@ -0,0 +1,18 @@ +package info.nightscout.androidaps.interfaces + +import info.nightscout.androidaps.db.Treatment + +interface TreatmentServiceInterface { + + fun getTreatmentDataFromTime(mills: Long, ascending: Boolean): List + fun getTreatmentDataFromTime(from: Long, to: Long, ascending: Boolean): List + fun getTreatmentData(): List + fun getLastBolus(excludeSMB: Boolean): Treatment? + fun getLastCarb(): Treatment? + fun createOrUpdateMedtronic(treatment: Treatment, fromNightScout: Boolean): UpdateReturn + fun createOrUpdate(treatment: Treatment): UpdateReturn + fun resetTreatments() + fun delete(data: Treatment) + fun update(data: Treatment) + fun count(): Long +} \ No newline at end of file diff --git a/core/src/main/java/info/nightscout/androidaps/interfaces/TreatmentsInterface.java b/core/src/main/java/info/nightscout/androidaps/interfaces/TreatmentsInterface.java index c17fc1119f..2f847d6228 100644 --- a/core/src/main/java/info/nightscout/androidaps/interfaces/TreatmentsInterface.java +++ b/core/src/main/java/info/nightscout/androidaps/interfaces/TreatmentsInterface.java @@ -21,6 +21,8 @@ import info.nightscout.androidaps.plugins.treatments.TreatmentUpdateReturn; */ public interface TreatmentsInterface { + TreatmentServiceInterface getService(); + void updateTotalIOBTreatments(); void updateTotalIOBTempBasals(); @@ -40,6 +42,7 @@ public interface TreatmentsInterface { List getTreatmentsFromHistoryAfterTimestamp(long timestamp); long getLastBolusTime(); + long getLastBolusTime(boolean excludeSMB); // real basals (not faked by extended bolus) boolean isInHistoryRealTempBasalInProgress(); diff --git a/core/src/main/java/info/nightscout/androidaps/interfaces/UpdateReturn.kt b/core/src/main/java/info/nightscout/androidaps/interfaces/UpdateReturn.kt new file mode 100644 index 0000000000..f0321ba25a --- /dev/null +++ b/core/src/main/java/info/nightscout/androidaps/interfaces/UpdateReturn.kt @@ -0,0 +1,11 @@ +package info.nightscout.androidaps.interfaces + +class UpdateReturn(var success: Boolean, var newRecord: Boolean) { + + override fun toString(): String { + return "UpdateReturn [" + + "newRecord=" + newRecord + + ", success=" + success + + ']' + } +} \ No newline at end of file diff --git a/danars/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt b/danars/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt index e23ced876d..e3e5c7391b 100644 --- a/danars/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt +++ b/danars/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt @@ -20,12 +20,13 @@ import org.junit.Before import org.mockito.Mock import org.powermock.core.classloader.annotations.PrepareForTest +@Suppress("SpellCheckingInspection") @PrepareForTest(FabricPrivacy::class) open class TestBaseWithProfile : TestBase() { @Mock lateinit var activePluginProvider: ActivePluginProvider @Mock lateinit var resourceHelper: ResourceHelper - @Mock lateinit var treatmentsPlugin: TreatmentsInterface + @Mock lateinit var treatmentsInterface: TreatmentsInterface @Mock lateinit var fabricPrivacy: FabricPrivacy @Mock lateinit var profileFunction: ProfileFunction @Mock lateinit var defaultValueHelper: DefaultValueHelper @@ -34,7 +35,7 @@ open class TestBaseWithProfile : TestBase() { val rxBus = RxBusWrapper(aapsSchedulers) - private val profileInjector = HasAndroidInjector { + val profileInjector = HasAndroidInjector { AndroidInjector { if (it is Profile) { it.aapsLogger = aapsLogger @@ -45,7 +46,7 @@ open class TestBaseWithProfile : TestBase() { it.configInterface = configInterface } if (it is ProfileSwitch) { - it.treatmentsPlugin = treatmentsPlugin + it.treatmentsPlugin = treatmentsInterface it.aapsLogger = aapsLogger it.rxBus = rxBus it.resourceHelper = resourceHelper @@ -62,11 +63,10 @@ open class TestBaseWithProfile : TestBase() { private lateinit var validProfileJSON: String lateinit var validProfile: Profile - private val testProfileName = "someProfile" + @Suppress("PropertyName") val TESTPROFILENAME = "someProfile" @Before fun prepareMock() { - @Suppress("SpellCheckingInspection") validProfileJSON = "{\"dia\":\"3\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"100\"},{\"time\":\"2:00\",\"value\":\"110\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4\"}],\"target_high\":[{\"time\":\"00:00\",\"value\":\"5\"}],\"startDate\":\"1970-01-01T00:00:00.000Z\",\"units\":\"mmol\"}" validProfile = Profile(profileInjector, JSONObject(validProfileJSON), Constants.MGDL) } @@ -74,8 +74,8 @@ open class TestBaseWithProfile : TestBase() { fun getValidProfileStore(): ProfileStore { val json = JSONObject() val store = JSONObject() - store.put(testProfileName, JSONObject(validProfileJSON)) - json.put("defaultProfile", testProfileName) + store.put(TESTPROFILENAME, JSONObject(validProfileJSON)) + json.put("defaultProfile", TESTPROFILENAME) json.put("store", store) return ProfileStore(profileInjector, json) } diff --git a/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRSPacketHistoryAlarmTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRSPacketHistoryAlarmTest.kt index 7d861f35cd..05627b2b5b 100644 --- a/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRSPacketHistoryAlarmTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRSPacketHistoryAlarmTest.kt @@ -2,6 +2,7 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.dana.comm.RecordTypes import info.nightscout.androidaps.danars.DanaRSTestBase import info.nightscout.androidaps.interfaces.DatabaseHelperInterface import info.nightscout.androidaps.plugins.general.nsclient.NSUpload @@ -48,8 +49,11 @@ class DanaRSPacketHistoryAlarmTest : DanaRSTestBase() { putByteToArray(array, 9, 100) // value packet.handleMessage(array) - Assert.assertEquals(info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_ALARM, packet.danaRHistoryRecord.recordCode) - val date = Calendar.getInstance().also { it.set(2019, 2, 4, 20, 11, 35) } + Assert.assertEquals(RecordTypes.RECORD_TYPE_ALARM, packet.danaRHistoryRecord.recordCode) + val date = GregorianCalendar().also { + it.clear() + it.set(2019, 1, 4, 20, 11, 35) + } Assert.assertEquals(date.timeInMillis, packet.danaRHistoryRecord.recordDate) Assert.assertEquals("Occlusion", packet.danaRHistoryRecord.recordAlarm) Assert.assertEquals(3.56, packet.danaRHistoryRecord.recordValue, 0.01)