fix tests and dependencies
This commit is contained in:
parent
738964faef
commit
f3fb533cf0
31 changed files with 132 additions and 108 deletions
|
@ -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.AutosensResult
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin
|
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.DateUtil
|
||||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||||
import info.nightscout.androidaps.utils.HardLimits
|
import info.nightscout.androidaps.utils.HardLimits
|
||||||
|
@ -36,7 +35,7 @@ open class OpenAPSAMAPlugin @Inject constructor(
|
||||||
private val profileFunction: ProfileFunction,
|
private val profileFunction: ProfileFunction,
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
private val activePlugin: ActivePluginProvider,
|
private val activePlugin: ActivePluginProvider,
|
||||||
private val treatmentsPlugin: TreatmentsPlugin,
|
private val treatmentsPlugin: TreatmentsInterface,
|
||||||
private val iobCobCalculatorPlugin: IobCobCalculatorPlugin,
|
private val iobCobCalculatorPlugin: IobCobCalculatorPlugin,
|
||||||
private val hardLimits: HardLimits,
|
private val hardLimits: HardLimits,
|
||||||
private val profiler: Profiler,
|
private val profiler: Profiler,
|
||||||
|
|
|
@ -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.AutosensResult
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin
|
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.DateUtil
|
||||||
import info.nightscout.androidaps.utils.HardLimits
|
import info.nightscout.androidaps.utils.HardLimits
|
||||||
import info.nightscout.androidaps.utils.Profiler
|
import info.nightscout.androidaps.utils.Profiler
|
||||||
|
@ -37,7 +36,7 @@ open class OpenAPSSMBPlugin @Inject constructor(
|
||||||
private val profileFunction: ProfileFunction,
|
private val profileFunction: ProfileFunction,
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
private val activePlugin: ActivePluginProvider,
|
private val activePlugin: ActivePluginProvider,
|
||||||
private val treatmentsPlugin: TreatmentsPlugin,
|
private val treatmentsPlugin: TreatmentsInterface,
|
||||||
private val iobCobCalculatorPlugin: IobCobCalculatorPlugin,
|
private val iobCobCalculatorPlugin: IobCobCalculatorPlugin,
|
||||||
private val hardLimits: HardLimits,
|
private val hardLimits: HardLimits,
|
||||||
private val profiler: Profiler,
|
private val profiler: Profiler,
|
||||||
|
|
|
@ -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.events.EventNewNotification
|
||||||
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification
|
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification
|
||||||
import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin
|
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.DecimalFormatter
|
||||||
import info.nightscout.androidaps.utils.HardLimits
|
import info.nightscout.androidaps.utils.HardLimits
|
||||||
import info.nightscout.androidaps.utils.Round
|
import info.nightscout.androidaps.utils.Round
|
||||||
|
@ -38,7 +37,7 @@ class SafetyPlugin @Inject constructor(
|
||||||
private val activePlugin: ActivePluginProvider,
|
private val activePlugin: ActivePluginProvider,
|
||||||
private val hardLimits: HardLimits,
|
private val hardLimits: HardLimits,
|
||||||
private val buildHelper: BuildHelper,
|
private val buildHelper: BuildHelper,
|
||||||
private val treatmentsPlugin: TreatmentsPlugin,
|
private val treatmentsPlugin: TreatmentsInterface,
|
||||||
private val config: Config
|
private val config: Config
|
||||||
) : PluginBase(PluginDescription()
|
) : PluginBase(PluginDescription()
|
||||||
.mainType(PluginType.CONSTRAINTS)
|
.mainType(PluginType.CONSTRAINTS)
|
||||||
|
|
|
@ -11,15 +11,15 @@ import com.google.common.base.Optional
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
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.logging.AAPSLogger
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
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.dialogs.ChooseTriggerDialog
|
||||||
import info.nightscout.androidaps.plugins.general.automation.events.EventTriggerChanged
|
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.EventTriggerClone
|
||||||
import info.nightscout.androidaps.plugins.general.automation.events.EventTriggerRemove
|
import info.nightscout.androidaps.plugins.general.automation.events.EventTriggerRemove
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin
|
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.services.LastLocationDataContainer
|
||||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||||
|
@ -29,13 +29,14 @@ import javax.inject.Inject
|
||||||
import kotlin.reflect.full.primaryConstructor
|
import kotlin.reflect.full.primaryConstructor
|
||||||
|
|
||||||
abstract class Trigger(val injector: HasAndroidInjector) {
|
abstract class Trigger(val injector: HasAndroidInjector) {
|
||||||
|
|
||||||
@Inject lateinit var aapsLogger: AAPSLogger
|
@Inject lateinit var aapsLogger: AAPSLogger
|
||||||
@Inject lateinit var rxBus: RxBusWrapper
|
@Inject lateinit var rxBus: RxBusWrapper
|
||||||
@Inject lateinit var resourceHelper: ResourceHelper
|
@Inject lateinit var resourceHelper: ResourceHelper
|
||||||
@Inject lateinit var profileFunction: ProfileFunction
|
@Inject lateinit var profileFunction: ProfileFunction
|
||||||
@Inject lateinit var sp: SP
|
@Inject lateinit var sp: SP
|
||||||
@Inject lateinit var locationDataContainer: LastLocationDataContainer
|
@Inject lateinit var locationDataContainer: LastLocationDataContainer
|
||||||
@Inject lateinit var treatmentsPlugin: TreatmentsPlugin
|
@Inject lateinit var treatmentsInterface: TreatmentsInterface
|
||||||
@Inject lateinit var activePlugin: ActivePluginProvider
|
@Inject lateinit var activePlugin: ActivePluginProvider
|
||||||
@Inject lateinit var iobCobCalculatorPlugin: IobCobCalculatorPlugin
|
@Inject lateinit var iobCobCalculatorPlugin: IobCobCalculatorPlugin
|
||||||
|
|
||||||
|
@ -53,12 +54,13 @@ abstract class Trigger(val injector: HasAndroidInjector) {
|
||||||
abstract fun duplicate(): Trigger
|
abstract fun duplicate(): Trigger
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun scanForActivity(cont: Context?): AppCompatActivity? {
|
fun scanForActivity(cont: Context?): AppCompatActivity? {
|
||||||
when (cont) {
|
when (cont) {
|
||||||
null -> return null
|
null -> return null
|
||||||
is AppCompatActivity -> return cont
|
is AppCompatActivity -> return cont
|
||||||
is ContextWrapper -> return scanForActivity(cont.baseContext)
|
is ContextWrapper -> return scanForActivity(cont.baseContext)
|
||||||
else -> return null
|
else -> return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ class TriggerBolusAgo(injector: HasAndroidInjector) : Trigger(injector) {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun shouldRun(): Boolean {
|
override fun shouldRun(): Boolean {
|
||||||
val lastBolusTime = treatmentsPlugin.getLastBolusTime(true)
|
val lastBolusTime = treatmentsInterface.getLastBolusTime(true)
|
||||||
if (lastBolusTime == 0L)
|
if (lastBolusTime == 0L)
|
||||||
return if (comparator.value == Comparator.Compare.IS_NOT_AVAILABLE) {
|
return if (comparator.value == Comparator.Compare.IS_NOT_AVAILABLE) {
|
||||||
aapsLogger.debug(LTag.AUTOMATION, "Ready for execution: " + friendlyDescription())
|
aapsLogger.debug(LTag.AUTOMATION, "Ready for execution: " + friendlyDescription())
|
||||||
|
|
|
@ -28,7 +28,7 @@ class TriggerTempTarget(injector: HasAndroidInjector) : Trigger(injector) {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun shouldRun(): Boolean {
|
override fun shouldRun(): Boolean {
|
||||||
val tt = treatmentsPlugin.tempTargetFromHistory
|
val tt = treatmentsInterface.tempTargetFromHistory
|
||||||
if (tt == null && comparator.value == ComparatorExists.Compare.NOT_EXISTS) {
|
if (tt == null && comparator.value == ComparatorExists.Compare.NOT_EXISTS) {
|
||||||
aapsLogger.debug(LTag.AUTOMATION, "Ready for execution: " + friendlyDescription())
|
aapsLogger.debug(LTag.AUTOMATION, "Ready for execution: " + friendlyDescription())
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -363,7 +363,7 @@ class OpenHumansUploader @Inject constructor(
|
||||||
copyDisposable = Completable.fromCallable { MainApp.getDbHelper().clearOpenHumansQueue() }
|
copyDisposable = Completable.fromCallable { MainApp.getDbHelper().clearOpenHumansQueue() }
|
||||||
.andThen(Single.defer { Single.just(MainApp.getDbHelper().countOfAllRows + treatmentsPlugin.service.count()) })
|
.andThen(Single.defer { Single.just(MainApp.getDbHelper().countOfAllRows + treatmentsPlugin.service.count()) })
|
||||||
.doOnSuccess { maxProgress = it }
|
.doOnSuccess { maxProgress = it }
|
||||||
.flatMapObservable { Observable.defer { Observable.fromIterable(treatmentsPlugin.service.treatmentData) } }
|
.flatMapObservable { Observable.defer { Observable.fromIterable(treatmentsPlugin.service.getTreatmentData()) } }
|
||||||
.map { enqueueTreatment(it); increaseCounter() }
|
.map { enqueueTreatment(it); increaseCounter() }
|
||||||
.ignoreElements()
|
.ignoreElements()
|
||||||
.andThen(Observable.defer { Observable.fromIterable(repository.compatGetBgReadingsDataFromTime(0, true).blockingGet()) })
|
.andThen(Observable.defer { Observable.fromIterable(repository.compatGetBgReadingsDataFromTime(0, true).blockingGet()) })
|
||||||
|
|
|
@ -450,7 +450,7 @@ class SmsCommunicatorPlugin @Inject constructor(
|
||||||
|
|
||||||
private fun processTREATMENTS(divided: Array<String>, receivedSms: Sms) {
|
private fun processTREATMENTS(divided: Array<String>, receivedSms: Sms) {
|
||||||
if (divided[1].toUpperCase(Locale.getDefault()) == "REFRESH") {
|
if (divided[1].toUpperCase(Locale.getDefault()) == "REFRESH") {
|
||||||
(activePlugin.activeTreatments as TreatmentsPlugin).service.resetTreatments()
|
activePlugin.activeTreatments.service.resetTreatments()
|
||||||
rxBus.send(EventNSClientRestart())
|
rxBus.send(EventNSClientRestart())
|
||||||
sendSMS(Sms(receivedSms.phoneNumber, "TREATMENTS REFRESH SENT"))
|
sendSMS(Sms(receivedSms.phoneNumber, "TREATMENTS REFRESH SENT"))
|
||||||
receivedSms.processed = true
|
receivedSms.processed = true
|
||||||
|
|
|
@ -41,6 +41,7 @@ import info.nightscout.androidaps.interfaces.ProfileFunction;
|
||||||
import info.nightscout.androidaps.interfaces.PumpDescription;
|
import info.nightscout.androidaps.interfaces.PumpDescription;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.interfaces.PumpPluginBase;
|
import info.nightscout.androidaps.interfaces.PumpPluginBase;
|
||||||
|
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||||
import info.nightscout.androidaps.logging.LTag;
|
import info.nightscout.androidaps.logging.LTag;
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
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 ResourceHelper resourceHelper;
|
||||||
private final ProfileFunction profileFunction;
|
private final ProfileFunction profileFunction;
|
||||||
private final TreatmentsPlugin treatmentsPlugin;
|
private final TreatmentsInterface treatmentsPlugin;
|
||||||
private final info.nightscout.androidaps.utils.sharedPreferences.SP sp;
|
private final info.nightscout.androidaps.utils.sharedPreferences.SP sp;
|
||||||
private RxBusWrapper rxBus;
|
private RxBusWrapper rxBus;
|
||||||
private final CommandQueueProvider commandQueue;
|
private final CommandQueueProvider commandQueue;
|
||||||
|
@ -136,7 +137,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
|
||||||
RxBusWrapper rxBus,
|
RxBusWrapper rxBus,
|
||||||
ResourceHelper resourceHelper,
|
ResourceHelper resourceHelper,
|
||||||
ProfileFunction profileFunction,
|
ProfileFunction profileFunction,
|
||||||
TreatmentsPlugin treatmentsPlugin,
|
TreatmentsInterface treatmentsPlugin,
|
||||||
SP sp,
|
SP sp,
|
||||||
CommandQueueProvider commandQueue,
|
CommandQueueProvider commandQueue,
|
||||||
Context context
|
Context context
|
||||||
|
|
|
@ -49,6 +49,7 @@ import info.nightscout.androidaps.interfaces.ProfileFunction;
|
||||||
import info.nightscout.androidaps.interfaces.PumpDescription;
|
import info.nightscout.androidaps.interfaces.PumpDescription;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.interfaces.PumpPluginBase;
|
import info.nightscout.androidaps.interfaces.PumpPluginBase;
|
||||||
|
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||||
import info.nightscout.androidaps.logging.LTag;
|
import info.nightscout.androidaps.logging.LTag;
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
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.exceptions.app_layer_errors.NoActiveTBRToCanceLException;
|
||||||
import info.nightscout.androidaps.plugins.pump.insight.utils.ExceptionTranslator;
|
import info.nightscout.androidaps.plugins.pump.insight.utils.ExceptionTranslator;
|
||||||
import info.nightscout.androidaps.plugins.pump.insight.utils.ParameterBlockUtil;
|
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.DateUtil;
|
||||||
import info.nightscout.androidaps.utils.TimeChangeType;
|
import info.nightscout.androidaps.utils.TimeChangeType;
|
||||||
import info.nightscout.androidaps.utils.resources.ResourceHelper;
|
import info.nightscout.androidaps.utils.resources.ResourceHelper;
|
||||||
|
@ -141,7 +141,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
private final AAPSLogger aapsLogger;
|
private final AAPSLogger aapsLogger;
|
||||||
private final RxBusWrapper rxBus;
|
private final RxBusWrapper rxBus;
|
||||||
private final ResourceHelper resourceHelper;
|
private final ResourceHelper resourceHelper;
|
||||||
private final TreatmentsPlugin treatmentsPlugin;
|
private final TreatmentsInterface treatmentsPlugin;
|
||||||
private final SP sp;
|
private final SP sp;
|
||||||
private final CommandQueueProvider commandQueue;
|
private final CommandQueueProvider commandQueue;
|
||||||
private final ProfileFunction profileFunction;
|
private final ProfileFunction profileFunction;
|
||||||
|
@ -203,7 +203,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
AAPSLogger aapsLogger,
|
AAPSLogger aapsLogger,
|
||||||
RxBusWrapper rxBus,
|
RxBusWrapper rxBus,
|
||||||
ResourceHelper resourceHelper,
|
ResourceHelper resourceHelper,
|
||||||
TreatmentsPlugin treatmentsPlugin,
|
TreatmentsInterface treatmentsPlugin,
|
||||||
SP sp,
|
SP sp,
|
||||||
CommandQueueProvider commandQueue,
|
CommandQueueProvider commandQueue,
|
||||||
ProfileFunction profileFunction,
|
ProfileFunction profileFunction,
|
||||||
|
|
|
@ -16,6 +16,7 @@ import com.j256.ormlite.support.ConnectionSource;
|
||||||
import com.j256.ormlite.table.TableUtils;
|
import com.j256.ormlite.table.TableUtils;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
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.EventReloadTreatmentData;
|
||||||
import info.nightscout.androidaps.events.EventTreatmentChange;
|
import info.nightscout.androidaps.events.EventTreatmentChange;
|
||||||
import info.nightscout.androidaps.interfaces.DatabaseHelperInterface;
|
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.AAPSLogger;
|
||||||
import info.nightscout.androidaps.logging.LTag;
|
import info.nightscout.androidaps.logging.LTag;
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
||||||
|
@ -57,7 +60,7 @@ import io.reactivex.disposables.CompositeDisposable;
|
||||||
* Created by mike on 24.09.2017.
|
* Created by mike on 24.09.2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
|
public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> implements TreatmentServiceInterface {
|
||||||
|
|
||||||
@Inject AAPSLogger aapsLogger;
|
@Inject AAPSLogger aapsLogger;
|
||||||
@Inject FabricPrivacy fabricPrivacy;
|
@Inject FabricPrivacy fabricPrivacy;
|
||||||
|
@ -471,7 +474,7 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public UpdateReturn createOrUpdateMedtronic(Treatment treatment, boolean fromNightScout) {
|
@NotNull public UpdateReturn createOrUpdateMedtronic(@NotNull Treatment treatment, boolean fromNightScout) {
|
||||||
|
|
||||||
if (MedtronicHistoryData.doubleBolusDebug)
|
if (MedtronicHistoryData.doubleBolusDebug)
|
||||||
aapsLogger.debug(LTag.DATATREATMENTS, "DoubleBolusDebug: createOrUpdateMedtronic:: originalTreatment={}, fromNightScout={}", treatment, fromNightScout);
|
aapsLogger.debug(LTag.DATATREATMENTS, "DoubleBolusDebug: createOrUpdateMedtronic:: originalTreatment={}, fromNightScout={}", treatment, fromNightScout);
|
||||||
|
@ -821,22 +824,4 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
|
||||||
return null;
|
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 +
|
|
||||||
']';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,9 @@ import info.nightscout.androidaps.interfaces.PluginType;
|
||||||
import info.nightscout.androidaps.interfaces.ProfileFunction;
|
import info.nightscout.androidaps.interfaces.ProfileFunction;
|
||||||
import info.nightscout.androidaps.interfaces.ProfileStore;
|
import info.nightscout.androidaps.interfaces.ProfileStore;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
|
import info.nightscout.androidaps.interfaces.TreatmentServiceInterface;
|
||||||
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
|
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
|
||||||
|
import info.nightscout.androidaps.interfaces.UpdateReturn;
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||||
import info.nightscout.androidaps.logging.LTag;
|
import info.nightscout.androidaps.logging.LTag;
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
||||||
|
@ -82,7 +84,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
||||||
|
|
||||||
private final CompositeDisposable disposable = new CompositeDisposable();
|
private final CompositeDisposable disposable = new CompositeDisposable();
|
||||||
|
|
||||||
protected TreatmentService service;
|
protected TreatmentServiceInterface service;
|
||||||
|
|
||||||
private IobTotal lastTreatmentCalculation;
|
private IobTotal lastTreatmentCalculation;
|
||||||
private IobTotal lastTempBasalsCalculation;
|
private IobTotal lastTempBasalsCalculation;
|
||||||
|
@ -180,7 +182,8 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
||||||
super.onStop();
|
super.onStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
public TreatmentService getService() {
|
@Override
|
||||||
|
public TreatmentServiceInterface getService() {
|
||||||
return this.service;
|
return this.service;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -620,9 +623,9 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
public TreatmentUpdateReturn createOrUpdateMedtronic(Treatment treatment, boolean fromNightScout) {
|
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
|
// return true if new record is created
|
||||||
|
@ -643,7 +646,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
||||||
treatment.carbs = detailedBolusInfo.carbs;
|
treatment.carbs = detailedBolusInfo.carbs;
|
||||||
treatment.mealBolus = treatment.carbs > 0;
|
treatment.mealBolus = treatment.carbs > 0;
|
||||||
treatment.boluscalc = detailedBolusInfo.boluscalc != null ? detailedBolusInfo.boluscalc.toString() : null;
|
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);
|
getAapsLogger().debug(medtronicPump && MedtronicHistoryData.doubleBolusDebug, LTag.DATATREATMENTS, "DoubleBolusDebug: addToHistoryTreatment::treatment={} " + treatment);
|
||||||
|
|
||||||
|
@ -652,7 +655,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
||||||
else
|
else
|
||||||
creatOrUpdateResult = getService().createOrUpdateMedtronic(treatment, false);
|
creatOrUpdateResult = getService().createOrUpdateMedtronic(treatment, false);
|
||||||
|
|
||||||
boolean newRecordCreated = creatOrUpdateResult.newRecord;
|
boolean newRecordCreated = creatOrUpdateResult.getNewRecord();
|
||||||
//log.debug("Adding new Treatment record" + treatment.toString());
|
//log.debug("Adding new Treatment record" + treatment.toString());
|
||||||
if (detailedBolusInfo.carbTime != 0) {
|
if (detailedBolusInfo.carbTime != 0) {
|
||||||
|
|
||||||
|
@ -673,7 +676,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
||||||
if (newRecordCreated && detailedBolusInfo.isValid)
|
if (newRecordCreated && detailedBolusInfo.isValid)
|
||||||
nsUpload.uploadTreatmentRecord(detailedBolusInfo);
|
nsUpload.uploadTreatmentRecord(detailedBolusInfo);
|
||||||
|
|
||||||
if (!allowUpdate && !creatOrUpdateResult.success) {
|
if (!allowUpdate && !creatOrUpdateResult.getSuccess()) {
|
||||||
getAapsLogger().error("Treatment could not be added to DB", new Exception());
|
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));
|
String status = String.format(resourceHelper.gs(R.string.error_adding_treatment_message), treatment.insulin, (int) treatment.carbs, dateUtil.dateAndTimeString(treatment.date));
|
||||||
|
|
|
@ -20,12 +20,13 @@ import org.junit.Before
|
||||||
import org.mockito.Mock
|
import org.mockito.Mock
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest
|
import org.powermock.core.classloader.annotations.PrepareForTest
|
||||||
|
|
||||||
|
@Suppress("SpellCheckingInspection")
|
||||||
@PrepareForTest(FabricPrivacy::class)
|
@PrepareForTest(FabricPrivacy::class)
|
||||||
open class TestBaseWithProfile : TestBase() {
|
open class TestBaseWithProfile : TestBase() {
|
||||||
|
|
||||||
@Mock lateinit var activePluginProvider: ActivePluginProvider
|
@Mock lateinit var activePluginProvider: ActivePluginProvider
|
||||||
@Mock lateinit var resourceHelper: ResourceHelper
|
@Mock lateinit var resourceHelper: ResourceHelper
|
||||||
@Mock lateinit var treatmentsPlugin: TreatmentsInterface
|
@Mock lateinit var treatmentsInterface: TreatmentsInterface
|
||||||
@Mock lateinit var fabricPrivacy: FabricPrivacy
|
@Mock lateinit var fabricPrivacy: FabricPrivacy
|
||||||
@Mock lateinit var profileFunction: ProfileFunction
|
@Mock lateinit var profileFunction: ProfileFunction
|
||||||
@Mock lateinit var defaultValueHelper: DefaultValueHelper
|
@Mock lateinit var defaultValueHelper: DefaultValueHelper
|
||||||
|
@ -45,7 +46,7 @@ open class TestBaseWithProfile : TestBase() {
|
||||||
it.configInterface = configInterface
|
it.configInterface = configInterface
|
||||||
}
|
}
|
||||||
if (it is ProfileSwitch) {
|
if (it is ProfileSwitch) {
|
||||||
it.treatmentsPlugin = treatmentsPlugin
|
it.treatmentsPlugin = treatmentsInterface
|
||||||
it.aapsLogger = aapsLogger
|
it.aapsLogger = aapsLogger
|
||||||
it.rxBus = rxBus
|
it.rxBus = rxBus
|
||||||
it.resourceHelper = resourceHelper
|
it.resourceHelper = resourceHelper
|
||||||
|
|
|
@ -123,13 +123,13 @@ class ConstraintsCheckerTest : TestBaseWithProfile() {
|
||||||
danaPump = DanaPump(aapsLogger, sp, injector)
|
danaPump = DanaPump(aapsLogger, sp, injector)
|
||||||
hardLimits = HardLimits(aapsLogger, rxBus, sp, resourceHelper, context, nsUpload)
|
hardLimits = HardLimits(aapsLogger, rxBus, sp, resourceHelper, context, nsUpload)
|
||||||
objectivesPlugin = ObjectivesPlugin(injector, aapsLogger, resourceHelper, activePlugin, sp, Config(), uel)
|
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)
|
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)
|
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)
|
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, treatmentsPlugin, iobCobCalculatorPlugin, hardLimits, profiler, sp)
|
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, treatmentsPlugin, iobCobCalculatorPlugin, hardLimits, profiler, fabricPrivacy)
|
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), treatmentsPlugin, Config())
|
safetyPlugin = SafetyPlugin(injector, aapsLogger, resourceHelper, sp, rxBus, constraintChecker, openAPSAMAPlugin, openAPSSMBPlugin, sensitivityOref1Plugin, activePlugin, hardLimits, BuildHelper(Config(), loggerUtils), treatmentsInterface, Config())
|
||||||
val constraintsPluginsList = ArrayList<PluginBase>()
|
val constraintsPluginsList = ArrayList<PluginBase>()
|
||||||
constraintsPluginsList.add(safetyPlugin)
|
constraintsPluginsList.add(safetyPlugin)
|
||||||
constraintsPluginsList.add(objectivesPlugin)
|
constraintsPluginsList.add(objectivesPlugin)
|
||||||
|
|
|
@ -43,7 +43,7 @@ class APSResultTest : TestBaseWithProfile() {
|
||||||
it.constraintChecker = constraintChecker
|
it.constraintChecker = constraintChecker
|
||||||
it.sp = sp
|
it.sp = sp
|
||||||
it.activePlugin = activePluginProvider
|
it.activePlugin = activePluginProvider
|
||||||
it.treatmentsPlugin = treatmentsPlugin
|
it.treatmentsPlugin = treatmentsInterface
|
||||||
it.profileFunction = profileFunction
|
it.profileFunction = profileFunction
|
||||||
it.resourceHelper = resourceHelper
|
it.resourceHelper = resourceHelper
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ class APSResultTest : TestBaseWithProfile() {
|
||||||
|
|
||||||
// closed loop mode return original request
|
// closed loop mode return original request
|
||||||
closedLoopEnabled.set(aapsLogger, true)
|
closedLoopEnabled.set(aapsLogger, true)
|
||||||
`when`(treatmentsPlugin.getTempBasalFromHistory(ArgumentMatchers.anyLong())).thenReturn(null)
|
`when`(treatmentsInterface.getTempBasalFromHistory(ArgumentMatchers.anyLong())).thenReturn(null)
|
||||||
apsResult.tempBasalRequested(false)
|
apsResult.tempBasalRequested(false)
|
||||||
Assert.assertEquals(false, apsResult.isChangeRequested)
|
Assert.assertEquals(false, apsResult.isChangeRequested)
|
||||||
apsResult.tempBasalRequested(true).percent(200).duration(30)
|
apsResult.tempBasalRequested(true).percent(200).duration(30)
|
||||||
|
@ -65,46 +65,46 @@ class APSResultTest : TestBaseWithProfile() {
|
||||||
// open loop
|
// open loop
|
||||||
closedLoopEnabled.set(aapsLogger, false)
|
closedLoopEnabled.set(aapsLogger, false)
|
||||||
// no change requested
|
// no change requested
|
||||||
`when`(treatmentsPlugin.getTempBasalFromHistory(ArgumentMatchers.anyLong())).thenReturn(null)
|
`when`(treatmentsInterface.getTempBasalFromHistory(ArgumentMatchers.anyLong())).thenReturn(null)
|
||||||
apsResult.tempBasalRequested(false)
|
apsResult.tempBasalRequested(false)
|
||||||
Assert.assertEquals(false, apsResult.isChangeRequested)
|
Assert.assertEquals(false, apsResult.isChangeRequested)
|
||||||
|
|
||||||
// request 100% when no temp is running
|
// 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)
|
apsResult.tempBasalRequested(true).percent(100).duration(30)
|
||||||
Assert.assertEquals(false, apsResult.isChangeRequested)
|
Assert.assertEquals(false, apsResult.isChangeRequested)
|
||||||
|
|
||||||
// request equal temp
|
// 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)
|
apsResult.tempBasalRequested(true).percent(70).duration(30)
|
||||||
Assert.assertEquals(false, apsResult.isChangeRequested)
|
Assert.assertEquals(false, apsResult.isChangeRequested)
|
||||||
|
|
||||||
// request zero temp
|
// 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)
|
apsResult.tempBasalRequested(true).percent(0).duration(30)
|
||||||
Assert.assertEquals(true, apsResult.isChangeRequested)
|
Assert.assertEquals(true, apsResult.isChangeRequested)
|
||||||
|
|
||||||
// request high temp
|
// 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)
|
apsResult.tempBasalRequested(true).percent(200).duration(30)
|
||||||
Assert.assertEquals(true, apsResult.isChangeRequested)
|
Assert.assertEquals(true, apsResult.isChangeRequested)
|
||||||
|
|
||||||
// request slightly different temp
|
// 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)
|
apsResult.tempBasalRequested(true).percent(80).duration(30)
|
||||||
Assert.assertEquals(false, apsResult.isChangeRequested)
|
Assert.assertEquals(false, apsResult.isChangeRequested)
|
||||||
|
|
||||||
// request different temp
|
// 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)
|
apsResult.tempBasalRequested(true).percent(120).duration(30)
|
||||||
Assert.assertEquals(true, apsResult.isChangeRequested)
|
Assert.assertEquals(true, apsResult.isChangeRequested)
|
||||||
|
|
||||||
// it should work with absolute temps too
|
// it should work with absolute temps too
|
||||||
// request different temp
|
// 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)
|
apsResult.tempBasalRequested(true).percent(100).duration(30)
|
||||||
Assert.assertEquals(false, apsResult.isChangeRequested)
|
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)
|
apsResult.tempBasalRequested(true).percent(50).duration(30)
|
||||||
Assert.assertEquals(true, apsResult.isChangeRequested)
|
Assert.assertEquals(true, apsResult.isChangeRequested)
|
||||||
|
|
||||||
|
@ -115,44 +115,44 @@ class APSResultTest : TestBaseWithProfile() {
|
||||||
// open loop
|
// open loop
|
||||||
closedLoopEnabled.set(aapsLogger, false)
|
closedLoopEnabled.set(aapsLogger, false)
|
||||||
// request 100% when no temp is running
|
// 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)
|
apsResult.tempBasalRequested(true).rate(1.0).duration(30)
|
||||||
Assert.assertEquals(false, apsResult.isChangeRequested)
|
Assert.assertEquals(false, apsResult.isChangeRequested)
|
||||||
|
|
||||||
// request equal temp
|
// 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)
|
apsResult.tempBasalRequested(true).rate(2.0).duration(30)
|
||||||
Assert.assertEquals(false, apsResult.isChangeRequested)
|
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)
|
apsResult.tempBasalRequested(true).rate(2.0).duration(30)
|
||||||
Assert.assertEquals(false, apsResult.isChangeRequested)
|
Assert.assertEquals(false, apsResult.isChangeRequested)
|
||||||
|
|
||||||
// request zero temp
|
// 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)
|
apsResult.tempBasalRequested(true).rate(0.0).duration(30)
|
||||||
Assert.assertEquals(true, apsResult.isChangeRequested)
|
Assert.assertEquals(true, apsResult.isChangeRequested)
|
||||||
|
|
||||||
// request high temp
|
// 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)
|
apsResult.tempBasalRequested(true).rate(35.0).duration(30)
|
||||||
Assert.assertEquals(true, apsResult.isChangeRequested)
|
Assert.assertEquals(true, apsResult.isChangeRequested)
|
||||||
|
|
||||||
// request slightly different temp
|
// 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)
|
apsResult.tempBasalRequested(true).rate(1.2).duration(30)
|
||||||
Assert.assertEquals(false, apsResult.isChangeRequested)
|
Assert.assertEquals(false, apsResult.isChangeRequested)
|
||||||
|
|
||||||
// request different temp
|
// 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)
|
apsResult.tempBasalRequested(true).rate(1.5).duration(30)
|
||||||
Assert.assertEquals(true, apsResult.isChangeRequested)
|
Assert.assertEquals(true, apsResult.isChangeRequested)
|
||||||
|
|
||||||
// it should work with percent temps too
|
// it should work with percent temps too
|
||||||
// request different temp
|
// 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)
|
apsResult.tempBasalRequested(true).rate(1.1).duration(30)
|
||||||
Assert.assertEquals(false, apsResult.isChangeRequested)
|
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)
|
apsResult.tempBasalRequested(true).rate(0.5).duration(30)
|
||||||
Assert.assertEquals(true, apsResult.isChangeRequested)
|
Assert.assertEquals(true, apsResult.isChangeRequested)
|
||||||
}
|
}
|
||||||
|
@ -164,7 +164,7 @@ class APSResultTest : TestBaseWithProfile() {
|
||||||
it.constraintChecker = constraintChecker
|
it.constraintChecker = constraintChecker
|
||||||
it.sp = sp
|
it.sp = sp
|
||||||
it.activePlugin = activePluginProvider
|
it.activePlugin = activePluginProvider
|
||||||
it.treatmentsPlugin = treatmentsPlugin
|
it.treatmentsPlugin = treatmentsInterface
|
||||||
it.profileFunction = profileFunction
|
it.profileFunction = profileFunction
|
||||||
it.resourceHelper = resourceHelper
|
it.resourceHelper = resourceHelper
|
||||||
}
|
}
|
||||||
|
@ -181,7 +181,7 @@ class APSResultTest : TestBaseWithProfile() {
|
||||||
it.constraintChecker = constraintChecker
|
it.constraintChecker = constraintChecker
|
||||||
it.sp = sp
|
it.sp = sp
|
||||||
it.activePlugin = activePluginProvider
|
it.activePlugin = activePluginProvider
|
||||||
it.treatmentsPlugin = treatmentsPlugin
|
it.treatmentsPlugin = treatmentsInterface
|
||||||
it.profileFunction = profileFunction
|
it.profileFunction = profileFunction
|
||||||
it.resourceHelper = resourceHelper
|
it.resourceHelper = resourceHelper
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,7 +76,7 @@ class SafetyPluginTest : TestBaseWithProfile() {
|
||||||
`when`(activePlugin.activePump).thenReturn(virtualPumpPlugin)
|
`when`(activePlugin.activePump).thenReturn(virtualPumpPlugin)
|
||||||
`when`(virtualPumpPlugin.pumpDescription).thenReturn(pumpDescription)
|
`when`(virtualPumpPlugin.pumpDescription).thenReturn(pumpDescription)
|
||||||
hardLimits = HardLimits(aapsLogger, rxBus, sp, resourceHelper, context, nsUpload)
|
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() {
|
@Test fun pumpDescriptionShouldLimitLoopInvocation() {
|
||||||
|
|
|
@ -20,7 +20,7 @@ class ActionProfileSwitchPercentTest : ActionsTestBase() {
|
||||||
@Before
|
@Before
|
||||||
fun setup() {
|
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.startprofileforever)).thenReturn("Start profile %d%%")
|
||||||
`when`(resourceHelper.gs(R.string.startprofile)).thenReturn("Start profile %d%% for %d min")
|
`when`(resourceHelper.gs(R.string.startprofile)).thenReturn("Start profile %d%% for %d min")
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ class ActionProfileSwitchPercentTest : ActionsTestBase() {
|
||||||
Assert.assertTrue(result.success)
|
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() {
|
@Test fun hasDialogTest() {
|
||||||
|
|
|
@ -26,7 +26,7 @@ class ActionProfileSwitchTest : ActionsTestBase() {
|
||||||
private val stringJson = "{\"data\":{\"profileToSwitchTo\":\"Test\"},\"type\":\"info.nightscout.androidaps.plugins.general.automation.actions.ActionProfileSwitch\"}"
|
private val stringJson = "{\"data\":{\"profileToSwitchTo\":\"Test\"},\"type\":\"info.nightscout.androidaps.plugins.general.automation.actions.ActionProfileSwitch\"}"
|
||||||
|
|
||||||
@Before fun setUp() {
|
@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(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(ArgumentMatchers.eq(R.string.changengetoprofilename), ArgumentMatchers.anyString())).thenReturn("Change profile to %s")
|
||||||
`when`(resourceHelper.gs(R.string.alreadyset)).thenReturn("Already set")
|
`when`(resourceHelper.gs(R.string.alreadyset)).thenReturn("Already set")
|
||||||
|
@ -97,7 +97,7 @@ class ActionProfileSwitchTest : ActionsTestBase() {
|
||||||
Assert.assertEquals("OK", result.comment)
|
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() {
|
@Test fun hasDialogTest() {
|
||||||
|
|
|
@ -12,7 +12,6 @@ import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
import org.mockito.Mockito
|
import org.mockito.Mockito
|
||||||
import org.mockito.Mockito.`when`
|
import org.mockito.Mockito.`when`
|
||||||
import org.powermock.api.mockito.PowerMockito
|
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest
|
import org.powermock.core.classloader.annotations.PrepareForTest
|
||||||
import org.powermock.modules.junit4.PowerMockRunner
|
import org.powermock.modules.junit4.PowerMockRunner
|
||||||
|
|
||||||
|
@ -45,13 +44,13 @@ class ActionStartTempTargetTest : ActionsTestBase() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun doActionTest() {
|
@Test fun doActionTest() {
|
||||||
`when`(activePlugin.activeTreatments).thenReturn(treatmentsPlugin)
|
`when`(activePlugin.activeTreatments).thenReturn(treatmentsInterface)
|
||||||
sut.doAction(object : Callback() {
|
sut.doAction(object : Callback() {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
Assert.assertTrue(result.success)
|
Assert.assertTrue(result.success)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
Mockito.verify(treatmentsPlugin, Mockito.times(1)).addToHistoryTempTarget(anyObject())
|
Mockito.verify(treatmentsInterface, Mockito.times(1)).addToHistoryTempTarget(anyObject())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun hasDialogTest() {
|
@Test fun hasDialogTest() {
|
||||||
|
|
|
@ -38,13 +38,13 @@ class ActionStopTempTargetTest : ActionsTestBase() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun doActionTest() {
|
@Test fun doActionTest() {
|
||||||
`when`(activePlugin.activeTreatments).thenReturn(treatmentsPlugin)
|
`when`(activePlugin.activeTreatments).thenReturn(treatmentsInterface)
|
||||||
sut.doAction(object : Callback() {
|
sut.doAction(object : Callback() {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
Assert.assertTrue(result.success)
|
Assert.assertTrue(result.success)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
Mockito.verify(treatmentsPlugin, Mockito.times(1)).addToHistoryTempTarget(anyObject())
|
Mockito.verify(treatmentsInterface, Mockito.times(1)).addToHistoryTempTarget(anyObject())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun hasDialogTest() {
|
@Test fun hasDialogTest() {
|
||||||
|
|
|
@ -30,7 +30,7 @@ class TriggerBolusAgoTest : TriggerTestBase() {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun shouldRunTest() {
|
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
|
`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)
|
var t = TriggerBolusAgo(injector).setValue(110).comparator(Comparator.Compare.IS_EQUAL)
|
||||||
Assert.assertEquals(110, t.minutesAgo.value)
|
Assert.assertEquals(110, t.minutesAgo.value)
|
||||||
|
@ -53,7 +53,7 @@ class TriggerBolusAgoTest : TriggerTestBase() {
|
||||||
Assert.assertTrue(t.shouldRun())
|
Assert.assertTrue(t.shouldRun())
|
||||||
t = TriggerBolusAgo(injector).setValue(390).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
t = TriggerBolusAgo(injector).setValue(390).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
|
||||||
Assert.assertTrue(t.shouldRun())
|
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)
|
t = TriggerBolusAgo(injector).comparator(Comparator.Compare.IS_NOT_AVAILABLE)
|
||||||
Assert.assertTrue(t.shouldRun())
|
Assert.assertTrue(t.shouldRun())
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,12 +28,12 @@ class TriggerTempTargetTest : TriggerTestBase() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun shouldRunTest() {
|
@Test fun shouldRunTest() {
|
||||||
`when`(treatmentsPlugin.tempTargetFromHistory).thenReturn(null)
|
`when`(treatmentsInterface.tempTargetFromHistory).thenReturn(null)
|
||||||
var t: TriggerTempTarget = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.EXISTS)
|
var t: TriggerTempTarget = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.EXISTS)
|
||||||
Assert.assertFalse(t.shouldRun())
|
Assert.assertFalse(t.shouldRun())
|
||||||
t = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.NOT_EXISTS)
|
t = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.NOT_EXISTS)
|
||||||
Assert.assertTrue(t.shouldRun())
|
Assert.assertTrue(t.shouldRun())
|
||||||
PowerMockito.`when`(treatmentsPlugin.tempTargetFromHistory).thenReturn(TempTarget())
|
PowerMockito.`when`(treatmentsInterface.tempTargetFromHistory).thenReturn(TempTarget())
|
||||||
t = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.NOT_EXISTS)
|
t = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.NOT_EXISTS)
|
||||||
Assert.assertFalse(t.shouldRun())
|
Assert.assertFalse(t.shouldRun())
|
||||||
t = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.EXISTS)
|
t = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.EXISTS)
|
||||||
|
|
|
@ -45,7 +45,7 @@ open class TriggerTestBase : TestBaseWithProfile() {
|
||||||
it.profileFunction = profileFunction
|
it.profileFunction = profileFunction
|
||||||
it.sp = sp
|
it.sp = sp
|
||||||
it.locationDataContainer = locationDataContainer
|
it.locationDataContainer = locationDataContainer
|
||||||
it.treatmentsPlugin = treatmentsPlugin
|
it.treatmentsInterface = treatmentsInterface
|
||||||
it.activePlugin = activePlugin
|
it.activePlugin = activePlugin
|
||||||
it.iobCobCalculatorPlugin = iobCobCalculatorPlugin
|
it.iobCobCalculatorPlugin = iobCobCalculatorPlugin
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,16 +154,16 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
||||||
}.`when`(commandQueue).extendedBolus(ArgumentMatchers.anyDouble(), ArgumentMatchers.anyInt(), ArgumentMatchers.any(Callback::class.java))
|
}.`when`(commandQueue).extendedBolus(ArgumentMatchers.anyDouble(), ArgumentMatchers.anyInt(), ArgumentMatchers.any(Callback::class.java))
|
||||||
|
|
||||||
`when`(activePlugin.activePump).thenReturn(virtualPumpPlugin)
|
`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.shortStatus(ArgumentMatchers.anyBoolean())).thenReturn("Virtual Pump")
|
||||||
`when`(virtualPumpPlugin.isSuspended()).thenReturn(false)
|
`when`(virtualPumpPlugin.isSuspended()).thenReturn(false)
|
||||||
`when`(virtualPumpPlugin.pumpDescription).thenReturn(PumpDescription())
|
`when`(virtualPumpPlugin.pumpDescription).thenReturn(PumpDescription())
|
||||||
`when`(virtualPumpPlugin.model()).thenReturn(PumpType.GenericAAPS)
|
`when`(virtualPumpPlugin.model()).thenReturn(PumpType.GenericAAPS)
|
||||||
|
|
||||||
`when`(treatmentsPlugin.lastCalculationTreatments).thenReturn(IobTotal(0))
|
`when`(treatmentsInterface.lastCalculationTreatments).thenReturn(IobTotal(0))
|
||||||
`when`(treatmentsPlugin.lastCalculationTempBasals).thenReturn(IobTotal(0))
|
`when`(treatmentsInterface.lastCalculationTempBasals).thenReturn(IobTotal(0))
|
||||||
`when`(treatmentsPlugin.service).thenReturn(treatmentService)
|
`when`(treatmentsInterface.service).thenReturn(treatmentService)
|
||||||
|
|
||||||
`when`(activePlugin.activeProfileInterface).thenReturn(localProfilePlugin)
|
`when`(activePlugin.activeProfileInterface).thenReturn(localProfilePlugin)
|
||||||
|
|
||||||
|
|
|
@ -107,8 +107,8 @@ class CommandQueueTest : TestBaseWithProfile() {
|
||||||
`when`(context.getSystemService(Context.POWER_SERVICE)).thenReturn(powerManager)
|
`when`(context.getSystemService(Context.POWER_SERVICE)).thenReturn(powerManager)
|
||||||
`when`(lazyActivePlugin.get()).thenReturn(activePlugin)
|
`when`(lazyActivePlugin.get()).thenReturn(activePlugin)
|
||||||
`when`(activePlugin.activePump).thenReturn(testPumpPlugin)
|
`when`(activePlugin.activePump).thenReturn(testPumpPlugin)
|
||||||
`when`(activePlugin.activeTreatments).thenReturn(treatmentsPlugin)
|
`when`(activePlugin.activeTreatments).thenReturn(treatmentsInterface)
|
||||||
`when`(treatmentsPlugin.lastBolusTime).thenReturn(Calendar.getInstance().also { it.set(2000, 0, 1) }.timeInMillis)
|
`when`(treatmentsInterface.lastBolusTime).thenReturn(Calendar.getInstance().also { it.set(2000, 0, 1) }.timeInMillis)
|
||||||
`when`(profileFunction.getProfile()).thenReturn(validProfile)
|
`when`(profileFunction.getProfile()).thenReturn(validProfile)
|
||||||
|
|
||||||
val bolusConstraint = Constraint(0.0)
|
val bolusConstraint = Constraint(0.0)
|
||||||
|
|
|
@ -72,8 +72,8 @@ class QueueThreadTest : TestBaseWithProfile() {
|
||||||
Mockito.`when`(context.getSystemService(Context.POWER_SERVICE)).thenReturn(powerManager)
|
Mockito.`when`(context.getSystemService(Context.POWER_SERVICE)).thenReturn(powerManager)
|
||||||
Mockito.`when`(lazyActivePlugin.get()).thenReturn(activePlugin)
|
Mockito.`when`(lazyActivePlugin.get()).thenReturn(activePlugin)
|
||||||
Mockito.`when`(activePlugin.activePump).thenReturn(pumpPlugin)
|
Mockito.`when`(activePlugin.activePump).thenReturn(pumpPlugin)
|
||||||
Mockito.`when`(activePlugin.activeTreatments).thenReturn(treatmentsPlugin)
|
Mockito.`when`(activePlugin.activeTreatments).thenReturn(treatmentsInterface)
|
||||||
Mockito.`when`(treatmentsPlugin.lastBolusTime).thenReturn(Calendar.getInstance().also { it.set(2000, 0, 1) }.timeInMillis)
|
Mockito.`when`(treatmentsInterface.lastBolusTime).thenReturn(Calendar.getInstance().also { it.set(2000, 0, 1) }.timeInMillis)
|
||||||
Mockito.`when`(profileFunction.getProfile()).thenReturn(validProfile)
|
Mockito.`when`(profileFunction.getProfile()).thenReturn(validProfile)
|
||||||
|
|
||||||
val bolusConstraint = Constraint(0.0)
|
val bolusConstraint = Constraint(0.0)
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
package info.nightscout.androidaps.interfaces
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.db.Treatment
|
||||||
|
|
||||||
|
interface TreatmentServiceInterface {
|
||||||
|
|
||||||
|
fun getTreatmentDataFromTime(mills: Long, ascending: Boolean): List<Treatment>
|
||||||
|
fun getTreatmentDataFromTime(from: Long, to: Long, ascending: Boolean): List<Treatment>
|
||||||
|
fun getTreatmentData(): List<Treatment>
|
||||||
|
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
|
||||||
|
}
|
|
@ -21,6 +21,8 @@ import info.nightscout.androidaps.plugins.treatments.TreatmentUpdateReturn;
|
||||||
*/
|
*/
|
||||||
public interface TreatmentsInterface {
|
public interface TreatmentsInterface {
|
||||||
|
|
||||||
|
TreatmentServiceInterface getService();
|
||||||
|
|
||||||
void updateTotalIOBTreatments();
|
void updateTotalIOBTreatments();
|
||||||
|
|
||||||
void updateTotalIOBTempBasals();
|
void updateTotalIOBTempBasals();
|
||||||
|
@ -40,6 +42,7 @@ public interface TreatmentsInterface {
|
||||||
List<Treatment> getTreatmentsFromHistoryAfterTimestamp(long timestamp);
|
List<Treatment> getTreatmentsFromHistoryAfterTimestamp(long timestamp);
|
||||||
|
|
||||||
long getLastBolusTime();
|
long getLastBolusTime();
|
||||||
|
long getLastBolusTime(boolean excludeSMB);
|
||||||
|
|
||||||
// real basals (not faked by extended bolus)
|
// real basals (not faked by extended bolus)
|
||||||
boolean isInHistoryRealTempBasalInProgress();
|
boolean isInHistoryRealTempBasalInProgress();
|
||||||
|
|
|
@ -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 +
|
||||||
|
']'
|
||||||
|
}
|
||||||
|
}
|
|
@ -20,12 +20,13 @@ import org.junit.Before
|
||||||
import org.mockito.Mock
|
import org.mockito.Mock
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest
|
import org.powermock.core.classloader.annotations.PrepareForTest
|
||||||
|
|
||||||
|
@Suppress("SpellCheckingInspection")
|
||||||
@PrepareForTest(FabricPrivacy::class)
|
@PrepareForTest(FabricPrivacy::class)
|
||||||
open class TestBaseWithProfile : TestBase() {
|
open class TestBaseWithProfile : TestBase() {
|
||||||
|
|
||||||
@Mock lateinit var activePluginProvider: ActivePluginProvider
|
@Mock lateinit var activePluginProvider: ActivePluginProvider
|
||||||
@Mock lateinit var resourceHelper: ResourceHelper
|
@Mock lateinit var resourceHelper: ResourceHelper
|
||||||
@Mock lateinit var treatmentsPlugin: TreatmentsInterface
|
@Mock lateinit var treatmentsInterface: TreatmentsInterface
|
||||||
@Mock lateinit var fabricPrivacy: FabricPrivacy
|
@Mock lateinit var fabricPrivacy: FabricPrivacy
|
||||||
@Mock lateinit var profileFunction: ProfileFunction
|
@Mock lateinit var profileFunction: ProfileFunction
|
||||||
@Mock lateinit var defaultValueHelper: DefaultValueHelper
|
@Mock lateinit var defaultValueHelper: DefaultValueHelper
|
||||||
|
@ -34,7 +35,7 @@ open class TestBaseWithProfile : TestBase() {
|
||||||
|
|
||||||
val rxBus = RxBusWrapper(aapsSchedulers)
|
val rxBus = RxBusWrapper(aapsSchedulers)
|
||||||
|
|
||||||
private val profileInjector = HasAndroidInjector {
|
val profileInjector = HasAndroidInjector {
|
||||||
AndroidInjector {
|
AndroidInjector {
|
||||||
if (it is Profile) {
|
if (it is Profile) {
|
||||||
it.aapsLogger = aapsLogger
|
it.aapsLogger = aapsLogger
|
||||||
|
@ -45,7 +46,7 @@ open class TestBaseWithProfile : TestBase() {
|
||||||
it.configInterface = configInterface
|
it.configInterface = configInterface
|
||||||
}
|
}
|
||||||
if (it is ProfileSwitch) {
|
if (it is ProfileSwitch) {
|
||||||
it.treatmentsPlugin = treatmentsPlugin
|
it.treatmentsPlugin = treatmentsInterface
|
||||||
it.aapsLogger = aapsLogger
|
it.aapsLogger = aapsLogger
|
||||||
it.rxBus = rxBus
|
it.rxBus = rxBus
|
||||||
it.resourceHelper = resourceHelper
|
it.resourceHelper = resourceHelper
|
||||||
|
@ -62,11 +63,10 @@ open class TestBaseWithProfile : TestBase() {
|
||||||
|
|
||||||
private lateinit var validProfileJSON: String
|
private lateinit var validProfileJSON: String
|
||||||
lateinit var validProfile: Profile
|
lateinit var validProfile: Profile
|
||||||
private val testProfileName = "someProfile"
|
@Suppress("PropertyName") val TESTPROFILENAME = "someProfile"
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun prepareMock() {
|
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\"}"
|
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)
|
validProfile = Profile(profileInjector, JSONObject(validProfileJSON), Constants.MGDL)
|
||||||
}
|
}
|
||||||
|
@ -74,8 +74,8 @@ open class TestBaseWithProfile : TestBase() {
|
||||||
fun getValidProfileStore(): ProfileStore {
|
fun getValidProfileStore(): ProfileStore {
|
||||||
val json = JSONObject()
|
val json = JSONObject()
|
||||||
val store = JSONObject()
|
val store = JSONObject()
|
||||||
store.put(testProfileName, JSONObject(validProfileJSON))
|
store.put(TESTPROFILENAME, JSONObject(validProfileJSON))
|
||||||
json.put("defaultProfile", testProfileName)
|
json.put("defaultProfile", TESTPROFILENAME)
|
||||||
json.put("store", store)
|
json.put("store", store)
|
||||||
return ProfileStore(profileInjector, json)
|
return ProfileStore(profileInjector, json)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package info.nightscout.androidaps.danars.comm
|
||||||
|
|
||||||
import dagger.android.AndroidInjector
|
import dagger.android.AndroidInjector
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
|
import info.nightscout.androidaps.dana.comm.RecordTypes
|
||||||
import info.nightscout.androidaps.danars.DanaRSTestBase
|
import info.nightscout.androidaps.danars.DanaRSTestBase
|
||||||
import info.nightscout.androidaps.interfaces.DatabaseHelperInterface
|
import info.nightscout.androidaps.interfaces.DatabaseHelperInterface
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
||||||
|
@ -48,8 +49,11 @@ class DanaRSPacketHistoryAlarmTest : DanaRSTestBase() {
|
||||||
putByteToArray(array, 9, 100) // value
|
putByteToArray(array, 9, 100) // value
|
||||||
|
|
||||||
packet.handleMessage(array)
|
packet.handleMessage(array)
|
||||||
Assert.assertEquals(info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_ALARM, packet.danaRHistoryRecord.recordCode)
|
Assert.assertEquals(RecordTypes.RECORD_TYPE_ALARM, packet.danaRHistoryRecord.recordCode)
|
||||||
val date = Calendar.getInstance().also { it.set(2019, 2, 4, 20, 11, 35) }
|
val date = GregorianCalendar().also {
|
||||||
|
it.clear()
|
||||||
|
it.set(2019, 1, 4, 20, 11, 35)
|
||||||
|
}
|
||||||
Assert.assertEquals(date.timeInMillis, packet.danaRHistoryRecord.recordDate)
|
Assert.assertEquals(date.timeInMillis, packet.danaRHistoryRecord.recordDate)
|
||||||
Assert.assertEquals("Occlusion", packet.danaRHistoryRecord.recordAlarm)
|
Assert.assertEquals("Occlusion", packet.danaRHistoryRecord.recordAlarm)
|
||||||
Assert.assertEquals(3.56, packet.danaRHistoryRecord.recordValue, 0.01)
|
Assert.assertEquals(3.56, packet.danaRHistoryRecord.recordValue, 0.01)
|
||||||
|
|
Loading…
Reference in a new issue