From 2de2d4f4f09cb16f3a68e3fbd0aad96f63259e11 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Sat, 13 Feb 2021 21:16:31 +0100 Subject: [PATCH 01/28] system carb timer --- app/src/main/AndroidManifest.xml | 1 + .../nightscout/androidaps/utils/CarbTimer.kt | 91 +++++++++++++++++++ .../androidaps/utils/wizard/BolusWizard.kt | 68 +------------- 3 files changed, 97 insertions(+), 63 deletions(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/utils/CarbTimer.kt diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index cb897b727c..42a8bc1042 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -25,6 +25,7 @@ + diff --git a/app/src/main/java/info/nightscout/androidaps/utils/CarbTimer.kt b/app/src/main/java/info/nightscout/androidaps/utils/CarbTimer.kt new file mode 100644 index 0000000000..5c592d035f --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/utils/CarbTimer.kt @@ -0,0 +1,91 @@ +package info.nightscout.androidaps.utils + +import android.content.Context +import android.content.Intent +import android.provider.AlarmClock +import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.Constants +import info.nightscout.androidaps.R +import info.nightscout.androidaps.plugins.general.automation.AutomationEvent +import info.nightscout.androidaps.plugins.general.automation.AutomationPlugin +import info.nightscout.androidaps.plugins.general.automation.actions.ActionAlarm +import info.nightscout.androidaps.plugins.general.automation.elements.Comparator +import info.nightscout.androidaps.plugins.general.automation.elements.InputDelta +import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerBg +import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector +import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerDelta +import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerTime +import info.nightscout.androidaps.utils.resources.ResourceHelper +import info.nightscout.androidaps.utils.sharedPreferences.SP +import java.text.DecimalFormat +import javax.inject.Inject +import javax.inject.Singleton + +@Singleton +class CarbTimer @Inject constructor( + private val sp: SP, + private val context: Context, + private val injector: HasAndroidInjector, + private val resourceHelper: ResourceHelper, + private val automationPlugin: AutomationPlugin +) { + + fun scheduleReminder(time: Long) { + if (sp.getBoolean(R.string.key_raise_notifications_as_android_notifications, true)) { + Intent(AlarmClock.ACTION_SET_TIMER).apply { + val length: Int = ((time - DateUtil.now()) / 1000).toInt() + flags = flags or Intent.FLAG_ACTIVITY_NEW_TASK + putExtra(AlarmClock.EXTRA_LENGTH, length) + putExtra(AlarmClock.EXTRA_SKIP_UI, true) + putExtra(AlarmClock.EXTRA_MESSAGE, resourceHelper.gs(R.string.timetoeat)) + context.startActivity(this) + } + } else { + AutomationEvent(injector).apply { + title = resourceHelper.gs(R.string.timetoeat) + readOnly = true + systemAction = true + autoRemove = true + trigger = TriggerConnector(injector, TriggerConnector.Type.AND).apply { + list.add(TriggerTime(injector, time)) + } + actions.add(ActionAlarm(injector, resourceHelper.gs(R.string.timetoeat))) + automationPlugin.addIfNotExists(this) + } + } + } + + fun scheduleEatReminder() { + val event = AutomationEvent(injector).apply { + title = resourceHelper.gs(R.string.bolusadvisor) + readOnly = true + systemAction = true + autoRemove = true + trigger = TriggerConnector(injector, TriggerConnector.Type.OR).apply { + + // Bg under 180 mgdl and dropping by 15 mgdl + list.add(TriggerConnector(injector, TriggerConnector.Type.AND).apply { + list.add(TriggerBg(injector, 180.0, Constants.MGDL, Comparator.Compare.IS_LESSER)) + list.add(TriggerDelta(injector, InputDelta(injector, -15.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.DELTA), Constants.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER)) + list.add(TriggerDelta(injector, InputDelta(injector, -8.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.SHORT_AVERAGE), Constants.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER)) + }) + // Bg under 160 mgdl and dropping by 9 mgdl + list.add(TriggerConnector(injector, TriggerConnector.Type.AND).apply { + list.add(TriggerBg(injector, 160.0, Constants.MGDL, Comparator.Compare.IS_LESSER)) + list.add(TriggerDelta(injector, InputDelta(injector, -9.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.DELTA), Constants.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER)) + list.add(TriggerDelta(injector, InputDelta(injector, -5.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.SHORT_AVERAGE), Constants.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER)) + }) + // Bg under 145 mgdl and dropping + list.add(TriggerConnector(injector, TriggerConnector.Type.AND).apply { + list.add(TriggerBg(injector, 145.0, Constants.MGDL, Comparator.Compare.IS_LESSER)) + list.add(TriggerDelta(injector, InputDelta(injector, 0.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.DELTA), Constants.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER)) + list.add(TriggerDelta(injector, InputDelta(injector, 0.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.SHORT_AVERAGE), Constants.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER)) + }) + } + actions.add(ActionAlarm(injector, resourceHelper.gs(R.string.time_to_eat))) + } + + automationPlugin.addIfNotExists(event) + } + +} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/utils/wizard/BolusWizard.kt b/app/src/main/java/info/nightscout/androidaps/utils/wizard/BolusWizard.kt index e32f62e61b..b324ad318e 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/wizard/BolusWizard.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/wizard/BolusWizard.kt @@ -6,7 +6,6 @@ import android.text.Spanned import com.google.common.base.Joiner import dagger.android.HasAndroidInjector import info.nightscout.androidaps.Config -import info.nightscout.androidaps.Constants import info.nightscout.androidaps.R import info.nightscout.androidaps.activities.ErrorHelperActivity import info.nightscout.androidaps.data.DetailedBolusInfo @@ -22,18 +21,10 @@ import info.nightscout.androidaps.logging.UserEntryLogger import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker -import info.nightscout.androidaps.plugins.general.automation.AutomationEvent -import info.nightscout.androidaps.plugins.general.automation.AutomationPlugin -import info.nightscout.androidaps.plugins.general.automation.actions.ActionAlarm -import info.nightscout.androidaps.plugins.general.automation.elements.Comparator -import info.nightscout.androidaps.plugins.general.automation.elements.InputDelta -import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerBg -import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector -import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerDelta -import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerTime import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin import info.nightscout.androidaps.queue.Callback +import info.nightscout.androidaps.utils.CarbTimer import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.HtmlHelper import info.nightscout.androidaps.utils.Round @@ -44,7 +35,6 @@ import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP import org.json.JSONException import org.json.JSONObject -import java.text.DecimalFormat import java.util.* import javax.inject.Inject import kotlin.math.abs @@ -63,10 +53,10 @@ class BolusWizard @Inject constructor( @Inject lateinit var commandQueue: CommandQueueProvider @Inject lateinit var loopPlugin: LoopPlugin @Inject lateinit var iobCobCalculatorPlugin: IobCobCalculatorPlugin - @Inject lateinit var automationPlugin: AutomationPlugin @Inject lateinit var dateUtil: DateUtil @Inject lateinit var config: Config @Inject lateinit var uel: UserEntryLogger + @Inject lateinit var carbTimer: CarbTimer init { injector.androidInjector().inject(this) @@ -368,7 +358,7 @@ class BolusWizard @Inject constructor( i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) ctx.startActivity(i) } else - scheduleEatReminder() + carbTimer.scheduleEatReminder() } }) } @@ -449,57 +439,9 @@ class BolusWizard @Inject constructor( } } if (useAlarm && carbs > 0 && carbTime > 0) { - scheduleReminder(dateUtil._now() + T.mins(carbTime.toLong()).msecs()) + carbTimer.scheduleReminder(dateUtil._now() + T.mins(carbTime.toLong()).msecs()) } } }) } - - private fun scheduleEatReminder() { - val event = AutomationEvent(injector).apply { - title = resourceHelper.gs(R.string.bolusadvisor) - readOnly = true - systemAction = true - autoRemove = true - trigger = TriggerConnector(injector, TriggerConnector.Type.OR).apply { - - // Bg under 180 mgdl and dropping by 15 mgdl - list.add(TriggerConnector(injector, TriggerConnector.Type.AND).apply { - list.add(TriggerBg(injector, 180.0, Constants.MGDL, Comparator.Compare.IS_LESSER)) - list.add(TriggerDelta(injector, InputDelta(injector, -15.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.DELTA), Constants.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER)) - list.add(TriggerDelta(injector, InputDelta(injector, -8.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.SHORT_AVERAGE), Constants.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER)) - }) - // Bg under 160 mgdl and dropping by 9 mgdl - list.add(TriggerConnector(injector, TriggerConnector.Type.AND).apply { - list.add(TriggerBg(injector, 160.0, Constants.MGDL, Comparator.Compare.IS_LESSER)) - list.add(TriggerDelta(injector, InputDelta(injector, -9.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.DELTA), Constants.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER)) - list.add(TriggerDelta(injector, InputDelta(injector, -5.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.SHORT_AVERAGE), Constants.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER)) - }) - // Bg under 145 mgdl and dropping - list.add(TriggerConnector(injector, TriggerConnector.Type.AND).apply { - list.add(TriggerBg(injector, 145.0, Constants.MGDL, Comparator.Compare.IS_LESSER)) - list.add(TriggerDelta(injector, InputDelta(injector, 0.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.DELTA), Constants.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER)) - list.add(TriggerDelta(injector, InputDelta(injector, 0.0, -360.0, 360.0, 1.0, DecimalFormat("0"), InputDelta.DeltaType.SHORT_AVERAGE), Constants.MGDL, Comparator.Compare.IS_EQUAL_OR_LESSER)) - }) - } - actions.add(ActionAlarm(injector, resourceHelper.gs(R.string.time_to_eat))) - } - - automationPlugin.addIfNotExists(event) - } - - private fun scheduleReminder(time: Long) { - val event = AutomationEvent(injector).apply { - title = resourceHelper.gs(R.string.timetoeat) - readOnly = true - systemAction = true - autoRemove = true - trigger = TriggerConnector(injector, TriggerConnector.Type.AND).apply { - list.add(TriggerTime(injector, time)) - } - actions.add(ActionAlarm(injector, resourceHelper.gs(R.string.timetoeat))) - } - - automationPlugin.addIfNotExists(event) - } -} +} \ No newline at end of file From a15377b48d2e907248396b76c6e6e2b0283d0520 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Sat, 13 Feb 2021 21:45:14 +0100 Subject: [PATCH 02/28] carb timer for carbs dialog --- .../nightscout/androidaps/dialogs/CarbsDialog.kt | 13 ++++++++----- app/src/main/res/layout/dialog_carbs.xml | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/CarbsDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/CarbsDialog.kt index 59de46fc32..c2f0986820 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/CarbsDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/CarbsDialog.kt @@ -23,11 +23,7 @@ import info.nightscout.androidaps.plugins.general.nsclient.NSUpload import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin import info.nightscout.androidaps.plugins.treatments.CarbsGenerator import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin -import info.nightscout.androidaps.utils.DateUtil -import info.nightscout.androidaps.utils.DecimalFormatter -import info.nightscout.androidaps.utils.DefaultValueHelper -import info.nightscout.androidaps.utils.HtmlHelper -import info.nightscout.androidaps.utils.ToastUtils +import info.nightscout.androidaps.utils.* import info.nightscout.androidaps.utils.alertDialogs.OKDialog import info.nightscout.androidaps.utils.extensions.formatColor import info.nightscout.androidaps.utils.resources.ResourceHelper @@ -48,6 +44,7 @@ class CarbsDialog : DialogFragmentWithDate() { @Inject lateinit var nsUpload: NSUpload @Inject lateinit var carbsGenerator: CarbsGenerator @Inject lateinit var uel: UserEntryLogger + @Inject lateinit var carbTimer: CarbTimer companion object { @@ -176,6 +173,7 @@ class CarbsDialog : DialogFragmentWithDate() { val hypoTT = defaultValueHelper.determineHypoTT() val actions: LinkedList = LinkedList() val unitLabel = if (units == Constants.MMOL) resourceHelper.gs(R.string.mmol) else resourceHelper.gs(R.string.mgdl) + val useAlarm = binding.alarmCheckBox.isChecked val activitySelected = binding.activityTt.isChecked if (activitySelected) @@ -192,6 +190,8 @@ class CarbsDialog : DialogFragmentWithDate() { val time = eventTime + timeOffset * 1000 * 60 if (timeOffset != 0) actions.add(resourceHelper.gs(R.string.time) + ": " + dateUtil.dateAndTimeString(time)) + if (useAlarm && carbs > 0 && timeOffset > 0) + actions.add(resourceHelper.gs(R.string.alarminxmin, timeOffset).formatColor(resourceHelper, R.color.info)) val duration = binding.duration.value.toInt() if (duration > 0) actions.add(resourceHelper.gs(R.string.duration) + ": " + duration + resourceHelper.gs(R.string.shorthour)) @@ -257,6 +257,9 @@ class CarbsDialog : DialogFragmentWithDate() { nsUpload.uploadEvent(CareportalEvent.NOTE, DateUtil.now() - 2000, resourceHelper.gs(R.string.generated_ecarbs_note, carbsAfterConstraints, duration, timeOffset)) } } + if (useAlarm && carbs > 0 && timeOffset > 0) { + carbTimer.scheduleReminder(dateUtil._now() + T.mins(timeOffset.toLong()).msecs()) + } }, null) } } else diff --git a/app/src/main/res/layout/dialog_carbs.xml b/app/src/main/res/layout/dialog_carbs.xml index 66c58a61bf..410a3a99c1 100644 --- a/app/src/main/res/layout/dialog_carbs.xml +++ b/app/src/main/res/layout/dialog_carbs.xml @@ -107,6 +107,21 @@ android:text="@string/unit_minute_short" android:textAppearance="?android:attr/textAppearanceSmall" /> + + + + + Date: Sat, 13 Feb 2021 21:51:37 +0100 Subject: [PATCH 03/28] small cleanups carb timer --- app/src/main/res/layout/dialog_carbs.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/src/main/res/layout/dialog_carbs.xml b/app/src/main/res/layout/dialog_carbs.xml index 410a3a99c1..01aaca4def 100644 --- a/app/src/main/res/layout/dialog_carbs.xml +++ b/app/src/main/res/layout/dialog_carbs.xml @@ -120,8 +120,7 @@ android:layout_height="wrap_content" android:layout_gravity="center" android:src="@drawable/ic_access_alarm_24dp" /> - - + Date: Sat, 13 Feb 2021 22:41:33 +0100 Subject: [PATCH 04/28] use system countdown for simple reminder all the time --- .../nightscout/androidaps/utils/CarbTimer.kt | 33 ++++--------------- app/src/main/res/layout/dialog_carbs.xml | 2 +- 2 files changed, 8 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/utils/CarbTimer.kt b/app/src/main/java/info/nightscout/androidaps/utils/CarbTimer.kt index 5c592d035f..77ce2b3ec3 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/CarbTimer.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/CarbTimer.kt @@ -14,45 +14,26 @@ import info.nightscout.androidaps.plugins.general.automation.elements.InputDelta import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerBg import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerDelta -import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerTime import info.nightscout.androidaps.utils.resources.ResourceHelper -import info.nightscout.androidaps.utils.sharedPreferences.SP import java.text.DecimalFormat import javax.inject.Inject import javax.inject.Singleton @Singleton class CarbTimer @Inject constructor( - private val sp: SP, private val context: Context, private val injector: HasAndroidInjector, private val resourceHelper: ResourceHelper, private val automationPlugin: AutomationPlugin ) { - fun scheduleReminder(time: Long) { - if (sp.getBoolean(R.string.key_raise_notifications_as_android_notifications, true)) { - Intent(AlarmClock.ACTION_SET_TIMER).apply { - val length: Int = ((time - DateUtil.now()) / 1000).toInt() - flags = flags or Intent.FLAG_ACTIVITY_NEW_TASK - putExtra(AlarmClock.EXTRA_LENGTH, length) - putExtra(AlarmClock.EXTRA_SKIP_UI, true) - putExtra(AlarmClock.EXTRA_MESSAGE, resourceHelper.gs(R.string.timetoeat)) - context.startActivity(this) - } - } else { - AutomationEvent(injector).apply { - title = resourceHelper.gs(R.string.timetoeat) - readOnly = true - systemAction = true - autoRemove = true - trigger = TriggerConnector(injector, TriggerConnector.Type.AND).apply { - list.add(TriggerTime(injector, time)) - } - actions.add(ActionAlarm(injector, resourceHelper.gs(R.string.timetoeat))) - automationPlugin.addIfNotExists(this) - } - } + fun scheduleReminder(time: Long) = Intent(AlarmClock.ACTION_SET_TIMER).apply { + val length: Int = ((time - DateUtil.now()) / 1000).toInt() + flags = flags or Intent.FLAG_ACTIVITY_NEW_TASK + putExtra(AlarmClock.EXTRA_LENGTH, length) + putExtra(AlarmClock.EXTRA_SKIP_UI, true) + putExtra(AlarmClock.EXTRA_MESSAGE, resourceHelper.gs(R.string.timetoeat)) + context.startActivity(this) } fun scheduleEatReminder() { diff --git a/app/src/main/res/layout/dialog_carbs.xml b/app/src/main/res/layout/dialog_carbs.xml index 01aaca4def..97f185ebdb 100644 --- a/app/src/main/res/layout/dialog_carbs.xml +++ b/app/src/main/res/layout/dialog_carbs.xml @@ -120,7 +120,7 @@ android:layout_height="wrap_content" android:layout_gravity="center" android:src="@drawable/ic_access_alarm_24dp" /> - + Date: Mon, 15 Feb 2021 23:55:57 +0100 Subject: [PATCH 05/28] layout CarbDialog alarm and use timer for automation alarms --- .../general/automation/actions/ActionAlarm.kt | 18 +- .../nightscout/androidaps/utils/CarbTimer.kt | 17 +- .../nightscout/androidaps/utils/TimerUtil.kt | 25 ++ app/src/main/res/layout/dialog_carbs.xml | 234 ++++++++++-------- 4 files changed, 174 insertions(+), 120 deletions(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/utils/TimerUtil.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionAlarm.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionAlarm.kt index 45480a4c3f..93411a1275 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionAlarm.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionAlarm.kt @@ -1,19 +1,20 @@ package info.nightscout.androidaps.plugins.general.automation.actions import android.content.Context -import android.content.Intent import android.widget.LinearLayout import androidx.annotation.DrawableRes import dagger.android.HasAndroidInjector import info.nightscout.androidaps.R -import info.nightscout.androidaps.activities.ErrorHelperActivity import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.general.automation.elements.InputString import info.nightscout.androidaps.plugins.general.automation.elements.LabelWithElement import info.nightscout.androidaps.plugins.general.automation.elements.LayoutBuilder import info.nightscout.androidaps.queue.Callback +import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.JsonHelper +import info.nightscout.androidaps.utils.T +import info.nightscout.androidaps.utils.TimerUtil import info.nightscout.androidaps.utils.resources.ResourceHelper import org.json.JSONObject import javax.inject.Inject @@ -23,26 +24,23 @@ class ActionAlarm(injector: HasAndroidInjector) : Action(injector) { @Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var rxBus: RxBusWrapper @Inject lateinit var context: Context + @Inject lateinit var timerUtil: TimerUtil var text = InputString(injector) constructor(injector: HasAndroidInjector, text: String) : this(injector) { this.text = InputString(injector, text) } + override fun friendlyName(): Int = R.string.alarm override fun shortDescription(): String = resourceHelper.gs(R.string.alarm_message, text.value) @DrawableRes override fun icon(): Int = R.drawable.ic_access_alarm_24dp - override fun isValid(): Boolean = text.value.isNotEmpty() + override fun isValid(): Boolean = true // empty alarm will show app name override fun doAction(callback: Callback) { - val i = Intent(context, ErrorHelperActivity::class.java) - i.putExtra("soundid", R.raw.modern_alarm) - i.putExtra("status", text.value) - i.putExtra("title", resourceHelper.gs(R.string.alarm)) - i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - context.startActivity(i) - + timerUtil.scheduleReminder(DateUtil.now() + T.secs(10L).msecs(), text.value.takeIf { it.isNotBlank() } + ?: resourceHelper.gs(R.string.app_name)) callback.result(PumpEnactResult(injector).success(true).comment(R.string.ok))?.run() } diff --git a/app/src/main/java/info/nightscout/androidaps/utils/CarbTimer.kt b/app/src/main/java/info/nightscout/androidaps/utils/CarbTimer.kt index 77ce2b3ec3..c029b01af2 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/CarbTimer.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/CarbTimer.kt @@ -1,8 +1,5 @@ package info.nightscout.androidaps.utils -import android.content.Context -import android.content.Intent -import android.provider.AlarmClock import dagger.android.HasAndroidInjector import info.nightscout.androidaps.Constants import info.nightscout.androidaps.R @@ -21,20 +18,14 @@ import javax.inject.Singleton @Singleton class CarbTimer @Inject constructor( - private val context: Context, private val injector: HasAndroidInjector, private val resourceHelper: ResourceHelper, - private val automationPlugin: AutomationPlugin + private val automationPlugin: AutomationPlugin, + private val timerUtil: TimerUtil ) { - fun scheduleReminder(time: Long) = Intent(AlarmClock.ACTION_SET_TIMER).apply { - val length: Int = ((time - DateUtil.now()) / 1000).toInt() - flags = flags or Intent.FLAG_ACTIVITY_NEW_TASK - putExtra(AlarmClock.EXTRA_LENGTH, length) - putExtra(AlarmClock.EXTRA_SKIP_UI, true) - putExtra(AlarmClock.EXTRA_MESSAGE, resourceHelper.gs(R.string.timetoeat)) - context.startActivity(this) - } + fun scheduleReminder(time: Long, text: String? = null) = + timerUtil.scheduleReminder(time, text ?: resourceHelper.gs(R.string.timetoeat)) fun scheduleEatReminder() { val event = AutomationEvent(injector).apply { diff --git a/app/src/main/java/info/nightscout/androidaps/utils/TimerUtil.kt b/app/src/main/java/info/nightscout/androidaps/utils/TimerUtil.kt new file mode 100644 index 0000000000..4f0ce09609 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/utils/TimerUtil.kt @@ -0,0 +1,25 @@ +package info.nightscout.androidaps.utils + +import android.content.Context +import android.content.Intent +import android.provider.AlarmClock +import info.nightscout.androidaps.R +import info.nightscout.androidaps.utils.resources.ResourceHelper +import javax.inject.Inject +import javax.inject.Singleton + +@Singleton +class TimerUtil @Inject constructor( + private val context: Context, + private val resourceHelper: ResourceHelper, +) { + + fun scheduleReminder(time: Long, text: String? = null) = Intent(AlarmClock.ACTION_SET_TIMER).apply { + val length: Int = ((time - DateUtil.now()) / 1000).toInt() + flags = flags or Intent.FLAG_ACTIVITY_NEW_TASK + putExtra(AlarmClock.EXTRA_LENGTH, length) + putExtra(AlarmClock.EXTRA_SKIP_UI, true) + putExtra(AlarmClock.EXTRA_MESSAGE, text ?: resourceHelper.gs(R.string.app_name)) + context.startActivity(this) + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_carbs.xml b/app/src/main/res/layout/dialog_carbs.xml index 97f185ebdb..6b7ffdde26 100644 --- a/app/src/main/res/layout/dialog_carbs.xml +++ b/app/src/main/res/layout/dialog_carbs.xml @@ -75,121 +75,161 @@ - + android:paddingEnd="5dp"> - + - + - + - + - + + - + - + - + - + + - + - + - + - + - + - + - + + + + + + + + + + + + + + + + + + + + + Date: Tue, 16 Feb 2021 19:03:38 +0100 Subject: [PATCH 06/28] fix tests and switch icon and checkbox --- .../nightscout/androidaps/utils/TimerUtil.kt | 16 +++++++++------- app/src/main/res/layout/dialog_carbs.xml | 13 ++++++------- .../automation/actions/ActionAlarmTest.kt | 5 ++++- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/utils/TimerUtil.kt b/app/src/main/java/info/nightscout/androidaps/utils/TimerUtil.kt index 4f0ce09609..b62f00df54 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/TimerUtil.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/TimerUtil.kt @@ -14,12 +14,14 @@ class TimerUtil @Inject constructor( private val resourceHelper: ResourceHelper, ) { - fun scheduleReminder(time: Long, text: String? = null) = Intent(AlarmClock.ACTION_SET_TIMER).apply { - val length: Int = ((time - DateUtil.now()) / 1000).toInt() - flags = flags or Intent.FLAG_ACTIVITY_NEW_TASK - putExtra(AlarmClock.EXTRA_LENGTH, length) - putExtra(AlarmClock.EXTRA_SKIP_UI, true) - putExtra(AlarmClock.EXTRA_MESSAGE, text ?: resourceHelper.gs(R.string.app_name)) - context.startActivity(this) + fun scheduleReminder(time: Long, text: String? = null) { + Intent(AlarmClock.ACTION_SET_TIMER).apply { + val length: Int = ((time - DateUtil.now()) / 1000).toInt() + flags = flags or Intent.FLAG_ACTIVITY_NEW_TASK + putExtra(AlarmClock.EXTRA_LENGTH, length) + putExtra(AlarmClock.EXTRA_SKIP_UI, true) + putExtra(AlarmClock.EXTRA_MESSAGE, text ?: resourceHelper.gs(R.string.app_name)) + context.startActivity(this) + } } } \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_carbs.xml b/app/src/main/res/layout/dialog_carbs.xml index 6b7ffdde26..f0f306c6ff 100644 --- a/app/src/main/res/layout/dialog_carbs.xml +++ b/app/src/main/res/layout/dialog_carbs.xml @@ -100,6 +100,12 @@ android:textAppearance="@style/TextAppearance.AppCompat.Small" android:textStyle="bold" /> + + - - Date: Wed, 17 Feb 2021 09:35:48 +0100 Subject: [PATCH 07/28] MDIPlugin -> kt --- .../plugins/pump/mdi/MDIPlugin.java | 280 ------------------ .../androidaps/plugins/pump/mdi/MDIPlugin.kt | 145 +++++++++ 2 files changed, 145 insertions(+), 280 deletions(-) delete mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/pump/mdi/MDIPlugin.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/pump/mdi/MDIPlugin.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/mdi/MDIPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/mdi/MDIPlugin.java deleted file mode 100644 index 143d60d606..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/mdi/MDIPlugin.java +++ /dev/null @@ -1,280 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.mdi; - -import androidx.annotation.NonNull; - -import org.json.JSONException; -import org.json.JSONObject; - -import javax.inject.Inject; -import javax.inject.Singleton; - -import dagger.android.HasAndroidInjector; -import info.nightscout.androidaps.R; -import info.nightscout.androidaps.data.DetailedBolusInfo; -import info.nightscout.androidaps.data.Profile; -import info.nightscout.androidaps.data.PumpEnactResult; -import info.nightscout.androidaps.interfaces.CommandQueueProvider; -import info.nightscout.androidaps.interfaces.PluginDescription; -import info.nightscout.androidaps.interfaces.PluginType; -import info.nightscout.androidaps.interfaces.PumpDescription; -import info.nightscout.androidaps.interfaces.PumpInterface; -import info.nightscout.androidaps.interfaces.PumpPluginBase; -import info.nightscout.androidaps.logging.AAPSLogger; -import info.nightscout.androidaps.logging.LTag; -import info.nightscout.androidaps.plugins.common.ManufacturerType; -import info.nightscout.androidaps.plugins.pump.common.defs.PumpType; -import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; -import info.nightscout.androidaps.utils.DateUtil; -import info.nightscout.androidaps.utils.InstanceId; -import info.nightscout.androidaps.utils.TimeChangeType; -import info.nightscout.androidaps.utils.resources.ResourceHelper; - - -/** - * Created by mike on 05.08.2016. - */ -@Singleton -public class MDIPlugin extends PumpPluginBase implements PumpInterface { - - private final TreatmentsPlugin treatmentsPlugin; - private final PumpDescription pumpDescription = new PumpDescription(); - - @Inject - public MDIPlugin( - HasAndroidInjector injector, - AAPSLogger aapsLogger, - ResourceHelper resourceHelper, - CommandQueueProvider commandQueue, - TreatmentsPlugin treatmentsPlugin - ) { - super(new PluginDescription() - .mainType(PluginType.PUMP) - .pluginIcon(R.drawable.ic_ict) - .pluginName(R.string.mdi) - .description(R.string.description_pump_mdi), - injector, aapsLogger, resourceHelper, commandQueue - ); - this.treatmentsPlugin = treatmentsPlugin; - - pumpDescription.isBolusCapable = true; - pumpDescription.bolusStep = 0.5d; - - pumpDescription.isExtendedBolusCapable = false; - pumpDescription.isTempBasalCapable = false; - pumpDescription.isSetBasalProfileCapable = false; - pumpDescription.isRefillingCapable = false; - pumpDescription.isBatteryReplaceable = false; - } - - @Override - public boolean isFakingTempsByExtendedBoluses() { - return false; - } - - @NonNull @Override - public PumpEnactResult loadTDDs() { - //no result, could read DB in the future? - return new PumpEnactResult(getInjector()); - } - - @Override - public boolean isInitialized() { - return true; - } - - @Override - public boolean isSuspended() { - return false; - } - - @Override - public boolean isBusy() { - return false; - } - - @Override - public boolean isConnected() { - return true; - } - - @Override - public boolean isConnecting() { - return false; - } - - @Override - public boolean isHandshakeInProgress() { - return false; - } - - @Override - public void connect(@NonNull String reason) { - } - - @Override - public void disconnect(@NonNull String reason) { - } - - @Override public int waitForDisconnectionInSeconds() { - return 0; - } - - @Override - public void stopConnecting() { - } - - @Override - public void getPumpStatus(@NonNull String reason) { - } - - @NonNull @Override - public PumpEnactResult setNewBasalProfile(@NonNull Profile profile) { - // Do nothing here. we are using ConfigBuilderPlugin.getPlugin().getActiveProfile().getProfile(); - PumpEnactResult result = new PumpEnactResult(getInjector()); - result.success = true; - return result; - } - - @Override - public boolean isThisProfileSet(@NonNull Profile profile) { - return false; - } - - @Override - public long lastDataTime() { - return System.currentTimeMillis(); - } - - @Override - public double getBaseBasalRate() { - return 0d; - } - - @Override - public double getReservoirLevel() { - return -1; - } - - @Override - public int getBatteryLevel() { - return -1; - } - - @NonNull @Override - public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) { - PumpEnactResult result = new PumpEnactResult(getInjector()); - result.success = true; - result.bolusDelivered = detailedBolusInfo.insulin; - result.carbsDelivered = detailedBolusInfo.carbs; - result.comment = getResourceHelper().gs(R.string.virtualpump_resultok); - treatmentsPlugin.addToHistoryTreatment(detailedBolusInfo, false); - return result; - } - - @Override - public void stopBolusDelivering() { - } - - @NonNull @Override - public PumpEnactResult setTempBasalAbsolute(double absoluteRate, int durationInMinutes, @NonNull Profile profile, boolean enforceNew) { - PumpEnactResult result = new PumpEnactResult(getInjector()); - result.success = false; - result.comment = getResourceHelper().gs(R.string.pumperror); - getAapsLogger().debug(LTag.PUMPBTCOMM, "Setting temp basal absolute: " + result); - return result; - } - - @NonNull @Override - public PumpEnactResult setTempBasalPercent(int percent, int durationInMinutes, @NonNull Profile profile, boolean enforceNew) { - PumpEnactResult result = new PumpEnactResult(getInjector()); - result.success = false; - result.comment = getResourceHelper().gs(R.string.pumperror); - getAapsLogger().debug(LTag.PUMPBTCOMM, "Settings temp basal percent: " + result); - return result; - } - - @NonNull @Override - public PumpEnactResult setExtendedBolus(double insulin, int durationInMinutes) { - PumpEnactResult result = new PumpEnactResult(getInjector()); - result.success = false; - result.comment = getResourceHelper().gs(R.string.pumperror); - getAapsLogger().debug(LTag.PUMPBTCOMM, "Setting extended bolus: " + result); - return result; - } - - @NonNull @Override - public PumpEnactResult cancelTempBasal(boolean force) { - PumpEnactResult result = new PumpEnactResult(getInjector()); - result.success = false; - result.comment = getResourceHelper().gs(R.string.pumperror); - getAapsLogger().debug(LTag.PUMPBTCOMM, "Cancel temp basal: " + result); - return result; - } - - @NonNull @Override - public PumpEnactResult cancelExtendedBolus() { - PumpEnactResult result = new PumpEnactResult(getInjector()); - result.success = false; - result.comment = getResourceHelper().gs(R.string.pumperror); - getAapsLogger().debug(LTag.PUMPBTCOMM, "Canceling extended bolus: " + result); - return result; - } - - @NonNull @Override - public JSONObject getJSONStatus(@NonNull Profile profile, @NonNull String profileName, @NonNull String version) { - long now = System.currentTimeMillis(); - JSONObject pump = new JSONObject(); - JSONObject status = new JSONObject(); - JSONObject extended = new JSONObject(); - try { - status.put("status", "normal"); - extended.put("Version", version); - extended.put("ActiveProfile", profileName); - status.put("timestamp", DateUtil.toISOString(now)); - - pump.put("status", status); - pump.put("extended", extended); - pump.put("clock", DateUtil.toISOString(now)); - } catch (JSONException e) { - getAapsLogger().error("Exception: ", e); - } - return pump; - } - - @NonNull @Override - public ManufacturerType manufacturer() { - return ManufacturerType.AndroidAPS; - } - - @NonNull @Override - public PumpType model() { - return PumpType.MDI; - } - - @NonNull @Override - public String serialNumber() { - return InstanceId.INSTANCE.instanceId(); - } - - @NonNull @Override - public PumpDescription getPumpDescription() { - return pumpDescription; - } - - @NonNull @Override - public String shortStatus(boolean veryShort) { - return model().getModel(); - } - - @Override - public boolean canHandleDST() { - return true; - } - - @Override - public void timezoneOrDSTChanged(@NonNull TimeChangeType changeType) { - - } - - -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/mdi/MDIPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/mdi/MDIPlugin.kt new file mode 100644 index 0000000000..582a29eb15 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/mdi/MDIPlugin.kt @@ -0,0 +1,145 @@ +package info.nightscout.androidaps.plugins.pump.mdi + +import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.R +import info.nightscout.androidaps.data.DetailedBolusInfo +import info.nightscout.androidaps.data.Profile +import info.nightscout.androidaps.data.PumpEnactResult +import info.nightscout.androidaps.interfaces.* +import info.nightscout.androidaps.logging.AAPSLogger +import info.nightscout.androidaps.logging.LTag +import info.nightscout.androidaps.plugins.common.ManufacturerType +import info.nightscout.androidaps.plugins.pump.common.defs.PumpType +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin +import info.nightscout.androidaps.utils.DateUtil +import info.nightscout.androidaps.utils.InstanceId.instanceId +import info.nightscout.androidaps.utils.resources.ResourceHelper +import org.json.JSONException +import org.json.JSONObject +import javax.inject.Inject +import javax.inject.Singleton + +@Singleton +class MDIPlugin @Inject constructor( + injector: HasAndroidInjector, + aapsLogger: AAPSLogger, + resourceHelper: ResourceHelper, + commandQueue: CommandQueueProvider, + private val treatmentsPlugin: TreatmentsPlugin +) : PumpPluginBase(PluginDescription() + .mainType(PluginType.PUMP) + .pluginIcon(R.drawable.ic_ict) + .pluginName(R.string.mdi) + .description(R.string.description_pump_mdi), + injector, aapsLogger, resourceHelper, commandQueue +), PumpInterface { + + override val pumpDescription = PumpDescription() + + init { + pumpDescription.isBolusCapable = true + pumpDescription.bolusStep = 0.5 + pumpDescription.isExtendedBolusCapable = false + pumpDescription.isTempBasalCapable = false + pumpDescription.isSetBasalProfileCapable = false + pumpDescription.isRefillingCapable = false + pumpDescription.isBatteryReplaceable = false + } + + override val isFakingTempsByExtendedBoluses: Boolean = false + + override fun loadTDDs(): PumpEnactResult = PumpEnactResult(injector) + override val isInitialized: Boolean = true + override val isSuspended: Boolean = false + override val isBusy: Boolean = false + override val isConnected: Boolean = true + override val isConnecting: Boolean = false + override val isHandshakeInProgress: Boolean = false + override fun connect(reason: String) {} + override fun disconnect(reason: String) {} + override fun waitForDisconnectionInSeconds(): Int = 0 + override fun stopConnecting() {} + override fun getPumpStatus(reason: String) {} + override fun setNewBasalProfile(profile: Profile): PumpEnactResult = PumpEnactResult(injector).success(true) + override fun isThisProfileSet(profile: Profile): Boolean = false + override fun lastDataTime(): Long = System.currentTimeMillis() + override val baseBasalRate: Double = 0.0 + override val reservoirLevel: Double = -1.0 + override val batteryLevel: Int = -1 + + override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult { + val result = PumpEnactResult(injector) + result.success = true + result.bolusDelivered = detailedBolusInfo.insulin + result.carbsDelivered = detailedBolusInfo.carbs + result.comment = resourceHelper.gs(R.string.virtualpump_resultok) + treatmentsPlugin.addToHistoryTreatment(detailedBolusInfo, false) + return result + } + + override fun stopBolusDelivering() {} + override fun setTempBasalAbsolute(absoluteRate: Double, durationInMinutes: Int, profile: Profile, enforceNew: Boolean): PumpEnactResult { + val result = PumpEnactResult(injector) + result.success = false + result.comment = resourceHelper.gs(R.string.pumperror) + aapsLogger.debug(LTag.PUMPBTCOMM, "Setting temp basal absolute: $result") + return result + } + + override fun setTempBasalPercent(percent: Int, durationInMinutes: Int, profile: Profile, enforceNew: Boolean): PumpEnactResult { + val result = PumpEnactResult(injector) + result.success = false + result.comment = resourceHelper.gs(R.string.pumperror) + aapsLogger.debug(LTag.PUMPBTCOMM, "Settings temp basal percent: $result") + return result + } + + override fun setExtendedBolus(insulin: Double, durationInMinutes: Int): PumpEnactResult { + val result = PumpEnactResult(injector) + result.success = false + result.comment = resourceHelper.gs(R.string.pumperror) + aapsLogger.debug(LTag.PUMPBTCOMM, "Setting extended bolus: $result") + return result + } + + override fun cancelTempBasal(enforceNew: Boolean): PumpEnactResult { + val result = PumpEnactResult(injector) + result.success = false + result.comment = resourceHelper.gs(R.string.pumperror) + aapsLogger.debug(LTag.PUMPBTCOMM, "Cancel temp basal: $result") + return result + } + + override fun cancelExtendedBolus(): PumpEnactResult { + val result = PumpEnactResult(injector) + result.success = false + result.comment = resourceHelper.gs(R.string.pumperror) + aapsLogger.debug(LTag.PUMPBTCOMM, "Canceling extended bolus: $result") + return result + } + + override fun getJSONStatus(profile: Profile, profileName: String, version: String): JSONObject { + val now = System.currentTimeMillis() + val pump = JSONObject() + val status = JSONObject() + val extended = JSONObject() + try { + status.put("status", "normal") + extended.put("Version", version) + extended.put("ActiveProfile", profileName) + status.put("timestamp", DateUtil.toISOString(now)) + pump.put("status", status) + pump.put("extended", extended) + pump.put("clock", DateUtil.toISOString(now)) + } catch (e: JSONException) { + aapsLogger.error("Exception: ", e) + } + return pump + } + + override fun manufacturer(): ManufacturerType = ManufacturerType.AndroidAPS + override fun model(): PumpType = PumpType.MDI + override fun serialNumber(): String = instanceId() + override fun shortStatus(veryShort: Boolean): String =model().model + override fun canHandleDST(): Boolean = true +} \ No newline at end of file From cae9588950547ddf4381d8ffc87019f3b99aeba6 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Wed, 17 Feb 2021 11:56:49 +0100 Subject: [PATCH 08/28] 2.8.2.1-dev-b --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 45e91a54d6..2d81b4f539 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -117,7 +117,7 @@ android { targetSdkVersion 28 multiDexEnabled true versionCode 1500 - version "2.8.2.1-dev-a" + version "2.8.2.1-dev-b" buildConfigField "String", "VERSION", '"' + version + '"' buildConfigField "String", "BUILDVERSION", '"' + generateGitBuild() + '-' + generateDate() + '"' buildConfigField "String", "REMOTE", '"' + generateGitRemote() + '"' From 531c74de6a94686cc0bb89399c4df5d93c4b7baa Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Wed, 17 Feb 2021 19:28:43 +0100 Subject: [PATCH 09/28] use fun instead of val in pump interface --- .../androidaps/plugins/aps/loop/LoopPlugin.kt | 12 ++-- .../general/actions/ActionsFragment.kt | 10 ++-- .../general/overview/OverviewFragment.kt | 18 +++--- .../smsCommunicator/SmsCommunicatorPlugin.kt | 6 +- .../general/wear/ActionStringHandler.kt | 4 +- .../androidaps/plugins/pump/mdi/MDIPlugin.kt | 16 ++--- .../plugins/pump/virtual/VirtualPumpPlugin.kt | 12 ++-- .../androidaps/queue/QueueThread.kt | 9 ++- .../androidaps/receivers/KeepAliveReceiver.kt | 6 +- .../androidaps/setupwizard/SWDefinition.kt | 10 ++-- .../nightscout/androidaps/TestPumpPlugin.kt | 20 ++++--- .../SmsCommunicatorPluginTest.kt | 59 +++++++++---------- .../androidaps/interfaces/PumpInterface.kt | 12 ++-- .../androidaps/danars/DanaRSPlugin.kt | 19 +++--- .../danars/services/DanaRSService.kt | 22 ++++--- 15 files changed, 119 insertions(+), 116 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.kt index 91ced93606..74ca108a37 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.kt @@ -196,7 +196,7 @@ open class LoopPlugin @Inject constructor( val apsMode = sp.getString(R.string.key_aps_mode, "open") val pump = activePlugin.activePump var isLGS = false - if (!isSuspended && !pump.isSuspended) if (closedLoopEnabled.value()) if (maxIobAllowed == hardLimits.MAXIOB_LGS || apsMode == "lgs") isLGS = true + if (!isSuspended && !pump.isSuspended()) if (closedLoopEnabled.value()) if (maxIobAllowed == hardLimits.MAXIOB_LGS || apsMode == "lgs") isLGS = true return isLGS } @@ -317,7 +317,7 @@ open class LoopPlugin @Inject constructor( rxBus.send(EventLoopSetLastRunGui(resourceHelper.gs(R.string.loopsuspended))) return } - if (pump.isSuspended) { + if (pump.isSuspended()) { aapsLogger.debug(LTag.APS, resourceHelper.gs(R.string.pumpsuspended)) rxBus.send(EventLoopSetLastRunGui(resourceHelper.gs(R.string.pumpsuspended))) return @@ -511,12 +511,12 @@ open class LoopPlugin @Inject constructor( return } val pump = activePlugin.activePump - if (!pump.isInitialized) { + if (!pump.isInitialized()) { aapsLogger.debug(LTag.APS, "applyAPSRequest: " + resourceHelper.gs(R.string.pumpNotInitialized)) callback?.result(PumpEnactResult(injector).comment(resourceHelper.gs(R.string.pumpNotInitialized)).enacted(false).success(false))?.run() return } - if (pump.isSuspended) { + if (pump.isSuspended()) { aapsLogger.debug(LTag.APS, "applyAPSRequest: " + resourceHelper.gs(R.string.pumpsuspended)) callback?.result(PumpEnactResult(injector).comment(resourceHelper.gs(R.string.pumpsuspended)).enacted(false).success(false))?.run() return @@ -578,12 +578,12 @@ open class LoopPlugin @Inject constructor( .enacted(false).success(false))?.run() return } - if (!pump.isInitialized) { + if (!pump.isInitialized()) { aapsLogger.debug(LTag.APS, "applySMBRequest: " + resourceHelper.gs(R.string.pumpNotInitialized)) callback?.result(PumpEnactResult(injector).comment(resourceHelper.gs(R.string.pumpNotInitialized)).enacted(false).success(false))?.run() return } - if (pump.isSuspended) { + if (pump.isSuspended()) { aapsLogger.debug(LTag.APS, "applySMBRequest: " + resourceHelper.gs(R.string.pumpsuspended)) callback?.result(PumpEnactResult(injector).comment(resourceHelper.gs(R.string.pumpsuspended)).enacted(false).success(false))?.run() return diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt index f658956b51..b0a28f92b2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt @@ -256,10 +256,10 @@ class ActionsFragment : DaggerFragment() { profileSwitch?.visibility = ( activePlugin.activeProfileInterface.profile != null && pump.pumpDescription.isSetBasalProfileCapable && - pump.isInitialized && - !pump.isSuspended).toVisibility() + pump.isInitialized() && + !pump.isSuspended()).toVisibility() - if (!pump.pumpDescription.isExtendedBolusCapable || !pump.isInitialized || pump.isSuspended || pump.isFakingTempsByExtendedBoluses) { + if (!pump.pumpDescription.isExtendedBolusCapable || !pump.isInitialized() || pump.isSuspended() || pump.isFakingTempsByExtendedBoluses) { extendedBolus?.visibility = View.GONE extendedBolusCancel?.visibility = View.GONE } else { @@ -275,7 +275,7 @@ class ActionsFragment : DaggerFragment() { } } - if (!pump.pumpDescription.isTempBasalCapable || !pump.isInitialized || pump.isSuspended) { + if (!pump.pumpDescription.isTempBasalCapable || !pump.isInitialized() || pump.isSuspended()) { setTempBasal?.visibility = View.GONE cancelTempBasal?.visibility = View.GONE } else { @@ -292,7 +292,7 @@ class ActionsFragment : DaggerFragment() { } val activeBgSource = activePlugin.activeBgSource historyBrowser?.visibility = (profile != null).toVisibility() - fill?.visibility = (pump.pumpDescription.isRefillingCapable && pump.isInitialized && !pump.isSuspended).toVisibility() + fill?.visibility = (pump.pumpDescription.isRefillingCapable && pump.isInitialized() && !pump.isSuspended()).toVisibility() pumpBatteryChange?.visibility = (pump.pumpDescription.isBatteryReplaceable || (pump is OmnipodErosPumpPlugin && pump.isUseRileyLinkBatteryLevel && pump.isBatteryChangeLoggingEnabled)).toVisibility() tempTarget?.visibility = (profile != null && config.APS).toVisibility() tddStats?.visibility = pump.pumpDescription.supportsTDDs.toVisibility() diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt index 0a427d0da0..7dd0ea848a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt @@ -446,7 +446,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList // QuickWizard button val quickWizardEntry = quickWizard.getActive() - if (quickWizardEntry != null && lastBG != null && profile != null && pump.isInitialized && !pump.isSuspended) { + if (quickWizardEntry != null && lastBG != null && profile != null && pump.isInitialized() && !pump.isSuspended()) { binding.buttonsLayout.quickWizardButton.visibility = View.VISIBLE val wizard = quickWizardEntry.doCalc(profile, profileName, lastBG, false) binding.buttonsLayout.quickWizardButton.text = quickWizardEntry.buttonText() + "\n" + resourceHelper.gs(R.string.format_carbs, quickWizardEntry.carbs()) + @@ -463,7 +463,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList (lastRun.lastOpenModeAccept == 0L || lastRun.lastOpenModeAccept < lastRun.lastAPSRun) &&// never accepted or before last result lastRun.constraintsProcessed?.isChangeRequested == true // change is requested - if (showAcceptButton && pump.isInitialized && !pump.isSuspended && loopPlugin.isEnabled(PluginType.LOOP)) { + if (showAcceptButton && pump.isInitialized() && !pump.isSuspended() && loopPlugin.isEnabled(PluginType.LOOP)) { binding.buttonsLayout.acceptTempButton.visibility = View.VISIBLE binding.buttonsLayout.acceptTempButton.text = "${resourceHelper.gs(R.string.setbasalquestion)}\n${lastRun!!.constraintsProcessed}" } else { @@ -471,10 +471,10 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList } // **** Various treatment buttons **** - binding.buttonsLayout.carbsButton.visibility = ((!activePlugin.activePump.pumpDescription.storesCarbInfo || pump.isInitialized && !pump.isSuspended) && profile != null && sp.getBoolean(R.string.key_show_carbs_button, true)).toVisibility() - binding.buttonsLayout.treatmentButton.visibility = (pump.isInitialized && !pump.isSuspended && profile != null && sp.getBoolean(R.string.key_show_treatment_button, false)).toVisibility() - binding.buttonsLayout.wizardButton.visibility = (pump.isInitialized && !pump.isSuspended && profile != null && sp.getBoolean(R.string.key_show_wizard_button, true)).toVisibility() - binding.buttonsLayout.insulinButton.visibility = (pump.isInitialized && !pump.isSuspended && profile != null && sp.getBoolean(R.string.key_show_insulin_button, true)).toVisibility() + binding.buttonsLayout.carbsButton.visibility = ((!activePlugin.activePump.pumpDescription.storesCarbInfo || pump.isInitialized() && !pump.isSuspended()) && profile != null && sp.getBoolean(R.string.key_show_carbs_button, true)).toVisibility() + binding.buttonsLayout.treatmentButton.visibility = (pump.isInitialized() && !pump.isSuspended() && profile != null && sp.getBoolean(R.string.key_show_treatment_button, false)).toVisibility() + binding.buttonsLayout.wizardButton.visibility = (pump.isInitialized() && !pump.isSuspended() && profile != null && sp.getBoolean(R.string.key_show_wizard_button, true)).toVisibility() + binding.buttonsLayout.insulinButton.visibility = (pump.isInitialized() && !pump.isSuspended() && profile != null && sp.getBoolean(R.string.key_show_insulin_button, true)).toVisibility() // **** Calibration & CGM buttons **** val xDripIsBgSource = xdripPlugin.isEnabled(PluginType.BGSOURCE) @@ -633,7 +633,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList binding.infoLayout.apsModeText.visibility = View.VISIBLE } - pump.isSuspended -> { + pump.isSuspended() -> { binding.infoLayout.apsMode.setImageResource(if (pump.pumpDescription.pumpType == PumpType.Insulet_Omnipod) { // For Omnipod, indicate the pump as disconnected when it's suspended. // The only way to 'reconnect' it, is through the Omnipod tab @@ -898,8 +898,8 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList menuChartSettings[g + 1][OverviewMenus.CharType.BGI.ordinal] -> useBGIForScale = true menuChartSettings[g + 1][OverviewMenus.CharType.DEVSLOPE.ordinal] -> useDSForScale = true } - var alignIobScale = menuChartSettings[g + 1][OverviewMenus.CharType.ABS.ordinal] && menuChartSettings[g + 1][OverviewMenus.CharType.IOB.ordinal] - var alignDevBgiScale = menuChartSettings[g + 1][OverviewMenus.CharType.DEV.ordinal] && menuChartSettings[g + 1][OverviewMenus.CharType.BGI.ordinal] + val alignIobScale = menuChartSettings[g + 1][OverviewMenus.CharType.ABS.ordinal] && menuChartSettings[g + 1][OverviewMenus.CharType.IOB.ordinal] + val alignDevBgiScale = menuChartSettings[g + 1][OverviewMenus.CharType.DEV.ordinal] && menuChartSettings[g + 1][OverviewMenus.CharType.BGI.ordinal] if (menuChartSettings[g + 1][OverviewMenus.CharType.ABS.ordinal]) secondGraphData.addAbsIob(fromTime, now, useABSForScale, 1.0) if (menuChartSettings[g + 1][OverviewMenus.CharType.IOB.ordinal]) secondGraphData.addIob(fromTime, now, useIobForScale, 1.0, menuChartSettings[g + 1][OverviewMenus.CharType.PRE.ordinal], alignIobScale) 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 9f22e361b0..92761bfa74 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 @@ -38,12 +38,12 @@ import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.receivers.BundleStore import info.nightscout.androidaps.receivers.DataReceiver import info.nightscout.androidaps.utils.* -import io.reactivex.rxkotlin.plusAssign import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.rx.AapsSchedulers import info.nightscout.androidaps.utils.sharedPreferences.SP import info.nightscout.androidaps.utils.textValidator.ValidatingEditTextPreference import io.reactivex.disposables.CompositeDisposable +import io.reactivex.rxkotlin.plusAssign import org.apache.commons.lang3.StringUtils import java.text.Normalizer import java.util.* @@ -270,7 +270,7 @@ class SmsCommunicatorPlugin @Inject constructor( "BOLUS" -> if (!remoteCommandsAllowed) sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.smscommunicator_remotecommandnotallowed))) else if (divided.size == 2 && DateUtil.now() - lastRemoteBolusTime < minDistance) sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.smscommunicator_remotebolusnotallowed))) - else if (divided.size == 2 && pump.isSuspended) sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.pumpsuspended))) + else if (divided.size == 2 && pump.isSuspended()) sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.pumpsuspended))) else if (divided.size == 2 || divided.size == 3) processBOLUS(divided, receivedSms) else sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.wrongformat))) "CARBS" -> @@ -729,7 +729,7 @@ class SmsCommunicatorPlugin @Inject constructor( receivedSms.processed = true messageToConfirm = AuthRequest(injector, receivedSms, reply, passCode, object : SmsAction(extended, duration) { override fun run() { - uel.log("SMS EXTENDED", reply) + uel.log("SMS EXTENDED", reply) commandQueue.extendedBolus(aDouble(), secondInteger(), object : Callback() { override fun run() { if (result.success) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/ActionStringHandler.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/ActionStringHandler.kt index 7a4e014024..2fbdbe6360 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/ActionStringHandler.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/ActionStringHandler.kt @@ -50,7 +50,7 @@ import javax.inject.Singleton class ActionStringHandler @Inject constructor( private val sp: SP, private val rxBus: RxBusWrapper, - private val aapsSchedulers: AapsSchedulers, + aapsSchedulers: AapsSchedulers, private val resourceHelper: ResourceHelper, private val injector: HasAndroidInjector, private val context: Context, @@ -262,7 +262,7 @@ class ActionStringHandler @Inject constructor( rAction = "statusmessage" rMessage = "OLD DATA - " //if pump is not busy: try to fetch data - if (activePump.isBusy) { + if (activePump.isBusy()) { rMessage += resourceHelper.gs(R.string.pumpbusy) } else { rMessage += "trying to fetch data from pump." diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/mdi/MDIPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/mdi/MDIPlugin.kt index 582a29eb15..ea7b47f332 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/mdi/MDIPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/mdi/MDIPlugin.kt @@ -49,12 +49,12 @@ class MDIPlugin @Inject constructor( override val isFakingTempsByExtendedBoluses: Boolean = false override fun loadTDDs(): PumpEnactResult = PumpEnactResult(injector) - override val isInitialized: Boolean = true - override val isSuspended: Boolean = false - override val isBusy: Boolean = false - override val isConnected: Boolean = true - override val isConnecting: Boolean = false - override val isHandshakeInProgress: Boolean = false + override fun isInitialized(): Boolean = true + override fun isSuspended(): Boolean = false + override fun isBusy(): Boolean = false + override fun isConnected(): Boolean = true + override fun isConnecting(): Boolean = false + override fun isHandshakeInProgress(): Boolean = false override fun connect(reason: String) {} override fun disconnect(reason: String) {} override fun waitForDisconnectionInSeconds(): Int = 0 @@ -63,7 +63,7 @@ class MDIPlugin @Inject constructor( override fun setNewBasalProfile(profile: Profile): PumpEnactResult = PumpEnactResult(injector).success(true) override fun isThisProfileSet(profile: Profile): Boolean = false override fun lastDataTime(): Long = System.currentTimeMillis() - override val baseBasalRate: Double = 0.0 + override val baseBasalRate: Double = 0.0 override val reservoirLevel: Double = -1.0 override val batteryLevel: Int = -1 @@ -140,6 +140,6 @@ class MDIPlugin @Inject constructor( override fun manufacturer(): ManufacturerType = ManufacturerType.AndroidAPS override fun model(): PumpType = PumpType.MDI override fun serialNumber(): String = instanceId() - override fun shortStatus(veryShort: Boolean): String =model().model + override fun shortStatus(veryShort: Boolean): String = model().model override fun canHandleDST(): Boolean = true } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.kt index 48a9bbc942..50af5cb9f0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.kt @@ -133,12 +133,12 @@ class VirtualPumpPlugin @Inject constructor( return PumpEnactResult(injector) } - override val isInitialized: Boolean = true - override val isSuspended: Boolean = false - override val isBusy: Boolean = false - override val isConnected: Boolean = true - override val isConnecting: Boolean = false - override val isHandshakeInProgress: Boolean = false + override fun isInitialized(): Boolean = true + override fun isSuspended(): Boolean = false + override fun isBusy(): Boolean = false + override fun isConnected(): Boolean = true + override fun isConnecting(): Boolean = false + override fun isHandshakeInProgress(): Boolean = false override fun connect(reason: String) { //if (!Config.NSCLIENT) NSUpload.uploadDeviceStatus() diff --git a/app/src/main/java/info/nightscout/androidaps/queue/QueueThread.kt b/app/src/main/java/info/nightscout/androidaps/queue/QueueThread.kt index 740f3f2839..c1b4fa7aa5 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/QueueThread.kt +++ b/app/src/main/java/info/nightscout/androidaps/queue/QueueThread.kt @@ -31,7 +31,6 @@ class QueueThread internal constructor( var waitingForDisconnect = false private var mWakeLock: PowerManager.WakeLock? = null - init { mWakeLock = (context.getSystemService(Context.POWER_SERVICE) as PowerManager).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, resourceHelper.gs(R.string.app_name) + ":QueueThread") } @@ -46,7 +45,7 @@ class QueueThread internal constructor( while (true) { val secondsElapsed = (System.currentTimeMillis() - connectionStartTime) / 1000 val pump = activePlugin.activePump - if (!pump.isConnected && secondsElapsed > Constants.PUMP_MAX_CONNECTION_TIME_IN_SECONDS) { + if (!pump.isConnected() && secondsElapsed > Constants.PUMP_MAX_CONNECTION_TIME_IN_SECONDS) { rxBus.send(EventDismissBolusProgressIfRunning(null)) rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.connectiontimedout))) aapsLogger.debug(LTag.PUMPQUEUE, "timed out") @@ -86,19 +85,19 @@ class QueueThread internal constructor( return } } - if (pump.isHandshakeInProgress) { + if (pump.isHandshakeInProgress()) { aapsLogger.debug(LTag.PUMPQUEUE, "handshaking $secondsElapsed") rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.HANDSHAKING, secondsElapsed.toInt())) SystemClock.sleep(100) continue } - if (pump.isConnecting) { + if (pump.isConnecting()) { aapsLogger.debug(LTag.PUMPQUEUE, "connecting $secondsElapsed") rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.CONNECTING, secondsElapsed.toInt())) SystemClock.sleep(1000) continue } - if (!pump.isConnected) { + if (!pump.isConnected()) { aapsLogger.debug(LTag.PUMPQUEUE, "connect") rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.CONNECTING, secondsElapsed.toInt())) pump.connect("Connection needed") diff --git a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.kt b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.kt index d97ab4f7a9..eb20d8acb4 100644 --- a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.kt +++ b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.kt @@ -29,6 +29,7 @@ import javax.inject.Inject import kotlin.math.abs class KeepAliveReceiver : DaggerBroadcastReceiver() { + @Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var rxBus: RxBusWrapper @Inject lateinit var activePlugin: ActivePluginProvider @@ -44,6 +45,7 @@ class KeepAliveReceiver : DaggerBroadcastReceiver() { @Inject lateinit var dateUtil: DateUtil companion object { + private val KEEP_ALIVE_MILLISECONDS = T.mins(5).msecs() private val STATUS_UPDATE_FREQUENCY = T.mins(15).msecs() private val IOB_UPDATE_FREQUENCY_IN_MINS = 5L @@ -128,10 +130,10 @@ class KeepAliveReceiver : DaggerBroadcastReceiver() { } if (!pump.isThisProfileSet(profile) && !commandQueue.isRunning(Command.CommandType.BASAL_PROFILE)) { rxBus.send(EventProfileNeedsUpdate()) - } else if (isStatusOutdated && !pump.isBusy) { + } else if (isStatusOutdated && !pump.isBusy()) { lastReadStatus = System.currentTimeMillis() commandQueue.readStatus("KeepAlive. Status outdated.", null) - } else if (isBasalOutdated && !pump.isBusy) { + } else if (isBasalOutdated && !pump.isBusy()) { lastReadStatus = System.currentTimeMillis() commandQueue.readStatus("KeepAlive. Basal outdated.", null) } diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt index baf7bad0ba..55ed268dfe 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt @@ -217,9 +217,11 @@ class SWDefinition @Inject constructor( .updateDelay(5) .label(R.string.treatmentssafety_maxcarbs_title) .comment(R.string.common_values)) - .validator { sp.contains(R.string.key_age) - && sp.getDouble(R.string.key_treatmentssafety_maxbolus, 0.0) > 0 - && sp.getDouble(R.string.key_treatmentssafety_maxcarbs, 0.0) > 0 } + .validator { + sp.contains(R.string.key_age) + && sp.getDouble(R.string.key_treatmentssafety_maxbolus, 0.0) > 0 + && sp.getDouble(R.string.key_treatmentssafety_maxcarbs, 0.0) > 0 + } private val screenInsulin = SWScreen(injector, R.string.configbuilder_insulin) .skippable(false) .add(SWPlugin(injector, this) @@ -303,7 +305,7 @@ class SWDefinition @Inject constructor( // For Omnipod, consider the pump initialized when a RL has been configured successfully // Users will be prompted to activate a Pod after completing the setup wizard. - return activePump.isInitialized || (activePump is OmnipodErosPumpPlugin && activePump.isRileyLinkReady) + return activePump.isInitialized() || (activePump is OmnipodErosPumpPlugin && activePump.isRileyLinkReady) } private val screenAps = SWScreen(injector, R.string.configbuilder_aps) diff --git a/app/src/test/java/info/nightscout/androidaps/TestPumpPlugin.kt b/app/src/test/java/info/nightscout/androidaps/TestPumpPlugin.kt index 936fb4345b..cd124fc675 100644 --- a/app/src/test/java/info/nightscout/androidaps/TestPumpPlugin.kt +++ b/app/src/test/java/info/nightscout/androidaps/TestPumpPlugin.kt @@ -14,27 +14,29 @@ import org.json.JSONObject @Suppress("MemberVisibilityCanBePrivate") class TestPumpPlugin(val injector: HasAndroidInjector) : PumpInterface { - override var isConnected = false - override var isConnecting = false - override var isHandshakeInProgress = false + var connected = false + + override fun isConnected() = connected + override fun isConnecting() = false + override fun isHandshakeInProgress() = false val lastData = 0L val baseBasal = 0.0 override val pumpDescription = PumpDescription() - override val isInitialized: Boolean = true - override val isSuspended: Boolean = false - override val isBusy: Boolean = false + override fun isInitialized(): Boolean = true + override fun isSuspended(): Boolean = false + override fun isBusy(): Boolean = false override fun connect(reason: String) { - isConnected = true + connected = true } override fun disconnect(reason: String) { - isConnected = false + connected = false } override fun stopConnecting() { - isConnected = false + connected = false } override fun waitForDisconnectionInSeconds(): Int = 0 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 53e38361b8..38558f5e84 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 @@ -1,3 +1,5 @@ +@file:Suppress("SpellCheckingInspection") + package info.nightscout.androidaps.plugins.general.smsCommunicator import android.content.Context @@ -155,9 +157,9 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { `when`(activePlugin.activeTreatments).thenReturn(treatmentsPlugin) `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.model()).thenReturn(PumpType.GenericAAPS); + `when`(virtualPumpPlugin.model()).thenReturn(PumpType.GenericAAPS) `when`(treatmentsPlugin.lastCalculationTreatments).thenReturn(IobTotal(0)) `when`(treatmentsPlugin.lastCalculationTempBasals).thenReturn(IobTotal(0)) @@ -187,7 +189,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { `when`(resourceHelper.gs(R.string.smscommunicator_loopisdisabled)).thenReturn("Loop is disabled") `when`(resourceHelper.gs(R.string.smscommunicator_loopisenabled)).thenReturn("Loop is enabled") `when`(resourceHelper.gs(R.string.wrongformat)).thenReturn("Wrong format") - `when`(resourceHelper.gs(ArgumentMatchers.eq(R.string.wrongTbrDuration), ArgumentMatchers.any())).thenAnswer({ i: InvocationOnMock -> "TBR duration must be a multiple of " + i.getArguments()[1] + " minutes and greater than 0." }) + `when`(resourceHelper.gs(ArgumentMatchers.eq(R.string.wrongTbrDuration), ArgumentMatchers.any())).thenAnswer { i: InvocationOnMock -> "TBR duration must be a multiple of " + i.arguments[1] + " minutes and greater than 0." } `when`(resourceHelper.gs(R.string.smscommunicator_loophasbeendisabled)).thenReturn("Loop has been disabled") `when`(resourceHelper.gs(R.string.smscommunicator_loophasbeenenabled)).thenReturn("Loop has been enabled") `when`(resourceHelper.gs(R.string.smscommunicator_tempbasalcanceled)).thenReturn("Temp basal canceled") @@ -241,8 +243,8 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { @Test fun processSettingsTest() { // called from constructor - Assert.assertEquals("1234", smsCommunicatorPlugin.allowedNumbers.get(0)) - Assert.assertEquals("5678", smsCommunicatorPlugin.allowedNumbers.get(1)) + Assert.assertEquals("1234", smsCommunicatorPlugin.allowedNumbers[0]) + Assert.assertEquals("5678", smsCommunicatorPlugin.allowedNumbers[1]) Assert.assertEquals(2, smsCommunicatorPlugin.allowedNumbers.size) } @@ -259,17 +261,16 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { smsCommunicatorPlugin.messageToConfirm = null } - @Test fun _isAllowedNumberTest() { + @Test fun isAllowedNumberTest() { Assert.assertTrue(smsCommunicatorPlugin.isAllowedNumber("5678")) Assert.assertFalse(smsCommunicatorPlugin.isAllowedNumber("56")) } @Test fun processSmsTest() { - var sms: Sms // SMS from not allowed number should be ignored smsCommunicatorPlugin.messages = ArrayList() - sms = Sms("12", "aText") + var sms = Sms("12", "aText") smsCommunicatorPlugin.processSms(sms) Assert.assertTrue(sms.ignored) Assert.assertEquals("aText", smsCommunicatorPlugin.messages[0].text) @@ -348,7 +349,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { //LOOP DISABLE : from enabled hasBeenRun = false PowerMockito.`when`(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true) - PowerMockito.doAnswer(Answer { _: InvocationOnMock? -> + PowerMockito.doAnswer(Answer { hasBeenRun = true null } as Answer<*>).`when`(loopPlugin).setPluginEnabled(PluginType.LOOP, false) @@ -376,7 +377,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { //LOOP ENABLE : from disabled hasBeenRun = false PowerMockito.`when`(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(false) - PowerMockito.doAnswer(Answer { _: InvocationOnMock? -> + PowerMockito.doAnswer(Answer { hasBeenRun = true null } as Answer<*>).`when`(loopPlugin).setPluginEnabled(PluginType.LOOP, true) @@ -660,11 +661,10 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { } @Test fun processProfileTest() { - var sms: Sms //PROFILE smsCommunicatorPlugin.messages = ArrayList() - sms = Sms("1234", "PROFILE") + var sms = Sms("1234", "PROFILE") smsCommunicatorPlugin.processSms(sms) Assert.assertEquals("PROFILE", smsCommunicatorPlugin.messages[0].text) Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.messages[1].text) @@ -699,7 +699,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { sms = Sms("1234", "PROFILE LIST") smsCommunicatorPlugin.processSms(sms) Assert.assertEquals("PROFILE LIST", smsCommunicatorPlugin.messages[0].text) - Assert.assertEquals("1. " + TESTPROFILENAME, smsCommunicatorPlugin.messages[1].text) + Assert.assertEquals("1. $TESTPROFILENAME", smsCommunicatorPlugin.messages[1].text) //PROFILE 2 (non existing) smsCommunicatorPlugin.messages = ArrayList() @@ -742,11 +742,10 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { } @Test fun processBasalTest() { - var sms: Sms //BASAL smsCommunicatorPlugin.messages = ArrayList() - sms = Sms("1234", "BASAL") + var sms = Sms("1234", "BASAL") smsCommunicatorPlugin.processSms(sms) Assert.assertEquals("BASAL", smsCommunicatorPlugin.messages[0].text) Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.messages[1].text) @@ -817,7 +816,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { smsCommunicatorPlugin.processSms(sms) Assert.assertEquals("BASAL 1 0", smsCommunicatorPlugin.messages[0].text) Assert.assertEquals("TBR duration must be a multiple of 30 minutes and greater than 0.", smsCommunicatorPlugin.messages[1].text) - `when`(constraintChecker.applyBasalConstraints(anyObject(), anyObject())).thenReturn(Constraint(1.0)) + `when`(constraintChecker.applyBasalConstraints(anyObject(), anyObject())).thenReturn(Constraint(1.0)) //BASAL 1 20 smsCommunicatorPlugin.messages = ArrayList() @@ -825,7 +824,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { smsCommunicatorPlugin.processSms(sms) Assert.assertEquals("BASAL 1 20", smsCommunicatorPlugin.messages[0].text) Assert.assertEquals("TBR duration must be a multiple of 30 minutes and greater than 0.", smsCommunicatorPlugin.messages[1].text) - `when`(constraintChecker.applyBasalConstraints(anyObject(), anyObject())).thenReturn(Constraint(1.0)) + `when`(constraintChecker.applyBasalConstraints(anyObject(), anyObject())).thenReturn(Constraint(1.0)) //BASAL 1 30 smsCommunicatorPlugin.messages = ArrayList() @@ -840,11 +839,10 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { } @Test fun processExtendedTest() { - var sms: Sms //EXTENDED smsCommunicatorPlugin.messages = ArrayList() - sms = Sms("1234", "EXTENDED") + var sms = Sms("1234", "EXTENDED") smsCommunicatorPlugin.processSms(sms) Assert.assertEquals("EXTENDED", smsCommunicatorPlugin.messages[0].text) Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.messages[1].text) @@ -874,7 +872,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { smsCommunicatorPlugin.processSms(sms) Assert.assertEquals("EXTENDED a%", smsCommunicatorPlugin.messages[0].text) Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages[1].text) - `when`(constraintChecker.applyExtendedBolusConstraints(anyObject())).thenReturn(Constraint(1.0)) + `when`(constraintChecker.applyExtendedBolusConstraints(anyObject())).thenReturn(Constraint(1.0)) //EXTENDED 1 0 smsCommunicatorPlugin.messages = ArrayList() @@ -896,11 +894,10 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { } @Test fun processBolusTest() { - var sms: Sms //BOLUS smsCommunicatorPlugin.messages = ArrayList() - sms = Sms("1234", "BOLUS") + var sms = Sms("1234", "BOLUS") smsCommunicatorPlugin.processSms(sms) Assert.assertEquals("BOLUS", smsCommunicatorPlugin.messages[0].text) Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.messages[1].text) @@ -912,7 +909,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { smsCommunicatorPlugin.processSms(sms) Assert.assertEquals("BOLUS", smsCommunicatorPlugin.messages[0].text) Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages[1].text) - `when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(Constraint(1.0)) + `when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(Constraint(1.0)) PowerMockito.`when`(DateUtil.now()).thenReturn(1000L) `when`(sp.getLong(R.string.key_smscommunicator_remotebolusmindistance, T.msecs(Constants.remoteBolusMinDistance).mins())).thenReturn(15L) //BOLUS 1 @@ -921,7 +918,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { smsCommunicatorPlugin.processSms(sms) Assert.assertEquals("BOLUS 1", smsCommunicatorPlugin.messages[0].text) Assert.assertEquals("Remote bolus not available. Try again later.", smsCommunicatorPlugin.messages[1].text) - `when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(Constraint(0.0)) + `when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(Constraint(0.0)) PowerMockito.`when`(DateUtil.now()).thenReturn(Constants.remoteBolusMinDistance + 1002L) //BOLUS 0 @@ -937,8 +934,8 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { smsCommunicatorPlugin.processSms(sms) Assert.assertEquals("BOLUS a", smsCommunicatorPlugin.messages[0].text) Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages[1].text) - `when`(constraintChecker.applyExtendedBolusConstraints(anyObject())).thenReturn(Constraint(1.0)) - `when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(Constraint(1.0)) + `when`(constraintChecker.applyExtendedBolusConstraints(anyObject())).thenReturn(Constraint(1.0)) + `when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(Constraint(1.0)) //BOLUS 1 smsCommunicatorPlugin.messages = ArrayList() @@ -953,13 +950,13 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { //BOLUS 1 (Suspended pump) smsCommunicatorPlugin.lastRemoteBolusTime = 0 - PowerMockito.`when`(virtualPumpPlugin.isSuspended).thenReturn(true) + PowerMockito.`when`(virtualPumpPlugin.isSuspended()).thenReturn(true) smsCommunicatorPlugin.messages = ArrayList() sms = Sms("1234", "BOLUS 1") smsCommunicatorPlugin.processSms(sms) Assert.assertEquals("BOLUS 1", smsCommunicatorPlugin.messages[0].text) Assert.assertEquals("Pump suspended", smsCommunicatorPlugin.messages[1].text) - PowerMockito.`when`(virtualPumpPlugin.isSuspended).thenReturn(false) + PowerMockito.`when`(virtualPumpPlugin.isSuspended()).thenReturn(false) //BOLUS 1 a smsCommunicatorPlugin.messages = ArrayList() @@ -982,11 +979,10 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { } @Test fun processCalTest() { - var sms: Sms //CAL smsCommunicatorPlugin.messages = ArrayList() - sms = Sms("1234", "CAL") + var sms = Sms("1234", "CAL") smsCommunicatorPlugin.processSms(sms) Assert.assertEquals("CAL", smsCommunicatorPlugin.messages[0].text) Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.messages[1].text) @@ -1019,12 +1015,11 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { } @Test fun processCarbsTest() { - var sms: Sms PowerMockito.`when`(DateUtil.now()).thenReturn(1000000L) `when`(sp.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)).thenReturn(false) //CAL smsCommunicatorPlugin.messages = ArrayList() - sms = Sms("1234", "CARBS") + var sms = Sms("1234", "CARBS") smsCommunicatorPlugin.processSms(sms) Assert.assertEquals("CARBS", smsCommunicatorPlugin.messages[0].text) Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.messages[1].text) diff --git a/core/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.kt b/core/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.kt index cac4d2e29d..a57003433a 100644 --- a/core/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.kt +++ b/core/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.kt @@ -16,12 +16,12 @@ import org.json.JSONObject */ interface PumpInterface { - val isInitialized: Boolean // true if pump status has been read and is ready to accept commands - val isSuspended: Boolean // true if suspended (not delivering insulin) - val isBusy: Boolean // if true pump is not ready to accept commands right now - val isConnected: Boolean // true if BT connection is established - val isConnecting: Boolean // true if BT connection is in progress - val isHandshakeInProgress: Boolean // true if BT is connected but initial handshake is still in progress + fun isInitialized(): Boolean // true if pump status has been read and is ready to accept commands + fun isSuspended(): Boolean // true if suspended (not delivering insulin) + fun isBusy(): Boolean // if true pump is not ready to accept commands right now + fun isConnected(): Boolean // true if BT connection is established + fun isConnecting(): Boolean // true if BT connection is in progress + fun isHandshakeInProgress(): Boolean // true if BT is connected but initial handshake is still in progress @JvmDefault fun finishHandshaking() {} // set initial handshake completed fun connect(reason: String) fun disconnect(reason: String) diff --git a/danars/src/main/java/info/nightscout/androidaps/danars/DanaRSPlugin.kt b/danars/src/main/java/info/nightscout/androidaps/danars/DanaRSPlugin.kt index 06f6e57e9c..f14a280848 100644 --- a/danars/src/main/java/info/nightscout/androidaps/danars/DanaRSPlugin.kt +++ b/danars/src/main/java/info/nightscout/androidaps/danars/DanaRSPlugin.kt @@ -141,9 +141,9 @@ class DanaRSPlugin @Inject constructor( } } - override val isConnected: Boolean = danaRSService?.isConnected ?: false - override val isConnecting: Boolean = danaRSService?.isConnecting ?: false - override val isHandshakeInProgress: Boolean = false + override fun isConnected(): Boolean = danaRSService?.isConnected ?: false + override fun isConnecting(): Boolean = danaRSService?.isConnecting ?: false + override fun isHandshakeInProgress(): Boolean = false override fun disconnect(reason: String) { aapsLogger.debug(LTag.PUMP, "RS disconnect from: $reason") @@ -195,18 +195,18 @@ class DanaRSPlugin @Inject constructor( } // Pump interface - override val isInitialized: Boolean = + override fun isInitialized(): Boolean = danaPump.lastConnection > 0 && danaPump.maxBasal > 0 && danaPump.isRSPasswordOK - override val isSuspended: Boolean = + override fun isSuspended(): Boolean = danaPump.pumpSuspended || danaPump.errorState != DanaPump.ErrorState.NONE - override val isBusy: Boolean = + override fun isBusy(): Boolean = danaRSService?.isConnected ?: false || danaRSService?.isConnecting ?: false override fun setNewBasalProfile(profile: Profile): PumpEnactResult { val result = PumpEnactResult(injector) - if (!isInitialized) { + if (!isInitialized()) { aapsLogger.error("setNewBasalProfile not initialized") val notification = Notification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED, resourceHelper.gs(R.string.pumpNotInitializedProfileNotSet), Notification.URGENT) rxBus.send(EventNewNotification(notification)) @@ -233,7 +233,7 @@ class DanaRSPlugin @Inject constructor( } override fun isThisProfileSet(profile: Profile): Boolean { - if (!isInitialized) return true // TODO: not sure what's better. so far TRUE to prevent too many SMS + if (!isInitialized()) return true // TODO: not sure what's better. so far TRUE to prevent too many SMS if (danaPump.pumpProfiles == null) return true // TODO: not sure what's better. so far TRUE to prevent too many SMS val basalValues = if (danaPump.basal48Enable) 48 else 24 val basalIncrement = if (danaPump.basal48Enable) 30 * 60 else 60 * 60 @@ -410,8 +410,7 @@ class DanaRSPlugin @Inject constructor( aapsLogger.debug(LTag.PUMP, "setTempBasalPercent: Correct value already set") return result } - val connectionOK: Boolean - connectionOK = if (durationInMinutes == 15 || durationInMinutes == 30) { + val connectionOK: Boolean = if (durationInMinutes == 15 || durationInMinutes == 30) { danaRSService?.tempBasalShortDuration(percentAfterConstraint, durationInMinutes) ?: false } else { diff --git a/danars/src/main/java/info/nightscout/androidaps/danars/services/DanaRSService.kt b/danars/src/main/java/info/nightscout/androidaps/danars/services/DanaRSService.kt index 1c9890995c..6cebbe7889 100644 --- a/danars/src/main/java/info/nightscout/androidaps/danars/services/DanaRSService.kt +++ b/danars/src/main/java/info/nightscout/androidaps/danars/services/DanaRSService.kt @@ -176,14 +176,18 @@ class DanaRSService : DaggerService() { rxBus.send(EventInitializationChanged()) return } else { - if (danaPump.usingUTC) { - sendMessage(DanaRS_Packet_Option_Set_Pump_UTC_And_TimeZone(injector, DateUtil.now(), offset)) - } else if (danaPump.protocol >= 6) { // can set seconds - sendMessage(DanaRS_Packet_Option_Set_Pump_Time(injector, DateUtil.now())) - } else { - waitForWholeMinute() // Dana can set only whole minute - // add 10sec to be sure we are over minute (will be cut off anyway) - sendMessage(DanaRS_Packet_Option_Set_Pump_Time(injector, DateUtil.now() + T.secs(10).msecs())) + when { + danaPump.usingUTC -> { + sendMessage(DanaRS_Packet_Option_Set_Pump_UTC_And_TimeZone(injector, DateUtil.now(), offset)) + } + danaPump.protocol >= 6 -> { // can set seconds + sendMessage(DanaRS_Packet_Option_Set_Pump_Time(injector, DateUtil.now())) + } + else -> { + waitForWholeMinute() // Dana can set only whole minute + // add 10sec to be sure we are over minute (will be cut off anyway) + sendMessage(DanaRS_Packet_Option_Set_Pump_Time(injector, DateUtil.now() + T.secs(10).msecs())) + } } if (danaPump.usingUTC) sendMessage(DanaRS_Packet_Option_Get_Pump_UTC_And_TimeZone(injector)) else sendMessage(DanaRS_Packet_Option_Get_Pump_Time(injector)) @@ -211,7 +215,7 @@ class DanaRSService : DaggerService() { } fun loadEvents(): PumpEnactResult { - if (!danaRSPlugin.isInitialized) { + if (!danaRSPlugin.isInitialized()) { val result = PumpEnactResult(injector).success(false) result.comment = "pump not initialized" return result From 2b3fcc60f0a4dad6bb212d58b5958e5d14268185 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Wed, 17 Feb 2021 20:15:45 +0100 Subject: [PATCH 10/28] more CommandQueue tests --- .../nightscout/androidaps/TestPumpPlugin.kt | 3 +- .../androidaps/queue/CommandQueueTest.kt | 36 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/app/src/test/java/info/nightscout/androidaps/TestPumpPlugin.kt b/app/src/test/java/info/nightscout/androidaps/TestPumpPlugin.kt index cd124fc675..97727ab5af 100644 --- a/app/src/test/java/info/nightscout/androidaps/TestPumpPlugin.kt +++ b/app/src/test/java/info/nightscout/androidaps/TestPumpPlugin.kt @@ -15,6 +15,7 @@ import org.json.JSONObject class TestPumpPlugin(val injector: HasAndroidInjector) : PumpInterface { var connected = false + var isProfileSet = true override fun isConnected() = connected override fun isConnecting() = false @@ -42,7 +43,7 @@ class TestPumpPlugin(val injector: HasAndroidInjector) : PumpInterface { override fun waitForDisconnectionInSeconds(): Int = 0 override fun getPumpStatus(reason: String) {} override fun setNewBasalProfile(profile: Profile): PumpEnactResult = PumpEnactResult(injector) - override fun isThisProfileSet(profile: Profile): Boolean = true + override fun isThisProfileSet(profile: Profile): Boolean = isProfileSet override fun lastDataTime(): Long = lastData override val baseBasalRate: Double = baseBasal override val reservoirLevel: Double = 0.0 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 3518805b82..90a77637f9 100644 --- a/app/src/test/java/info/nightscout/androidaps/queue/CommandQueueTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/queue/CommandQueueTest.kt @@ -344,6 +344,42 @@ class CommandQueueTest : TestBaseWithProfile() { Assert.assertEquals(1, commandQueue.size()) } + @Test + fun isProfileSetCommandInQueue() { + // given + Assert.assertEquals(0, commandQueue.size()) + + // when + testPumpPlugin.isProfileSet = true + commandQueue.setProfile(validProfile, object : Callback() { + override fun run() { + Assert.assertTrue(result.success) + Assert.assertFalse(result.enacted) + } + }) + + // then + // the same profile -> ignore + Assert.assertEquals(0, commandQueue.size()) + // different should be added + testPumpPlugin.isProfileSet = false + commandQueue.setProfile(validProfile, object : Callback() { + override fun run() { + Assert.assertTrue(result.success) + Assert.assertTrue(result.enacted) + } + }) + Assert.assertEquals(1, commandQueue.size()) + // next should be ignored + commandQueue.setProfile(validProfile, object : Callback() { + override fun run() { + Assert.assertTrue(result.success) + } + }) + Assert.assertEquals(1, commandQueue.size()) + testPumpPlugin.isProfileSet = true + } + @Test fun isStopCommandInQueue() { // given From 1e95be1f34479b1b9cc0a23a90d201e7a7582856 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 18 Feb 2021 00:04:44 +0100 Subject: [PATCH 11/28] jacoco.includeNoLocationClasses --- app/build.gradle | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/build.gradle b/app/build.gradle index 2d81b4f539..e9440c8b2c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -20,6 +20,10 @@ jacoco { toolVersion = "0.8.3" } +tasks.withType(Test) { + jacoco.includeNoLocationClasses = true +} + repositories { mavenCentral() google() From 73da2a1a3fe61e8a86193a1e40804bf6be6047aa Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 18 Feb 2021 08:15:42 +0100 Subject: [PATCH 12/28] add jacoco to core --- app/build.gradle | 12 +----------- build.gradle | 2 ++ core/build.gradle | 1 + 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index e9440c8b2c..3ea69de937 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,13 +1,3 @@ -buildscript { - repositories { - maven { url "https://plugins.gradle.org/m2/" } // jacoco 0.2 - } - - dependencies { - //classpath 'com.dicedmelon.gradle:jacoco-android:0.1.4' - classpath 'com.hiya:jacoco-android:0.2' - } -} apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' @@ -17,7 +7,7 @@ apply plugin: 'com.hiya.jacoco-android' apply plugin: 'com.google.firebase.crashlytics' jacoco { - toolVersion = "0.8.3" + toolVersion = "0.8.6" } tasks.withType(Test) { diff --git a/build.gradle b/build.gradle index 8e5b1e8207..a3026de30d 100644 --- a/build.gradle +++ b/build.gradle @@ -42,6 +42,7 @@ buildscript { includeModule("org.jetbrains.trove4j", "trove4j") } } + maven { url "https://plugins.gradle.org/m2/" } // jacoco 0.2 } dependencies { classpath 'com.android.tools.build:gradle:4.0.1' @@ -52,6 +53,7 @@ buildscript { // in the individual module build.gradle files classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + classpath 'com.hiya:jacoco-android:0.2' } } diff --git a/core/build.gradle b/core/build.gradle index 71ce3bd0da..f77ee5261c 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -2,6 +2,7 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' apply plugin: 'kotlin-parcelize' +apply plugin: 'com.hiya.jacoco-android' android { compileSdkVersion 28 From 6d32516aec828603c847a9bc2a8cfcdb506a78b9 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 18 Feb 2021 17:01:41 +0100 Subject: [PATCH 13/28] move test to core --- .../androidaps/utils/RoundTest.java | 41 ------------------- core/build.gradle | 6 +++ .../nightscout/androidaps/utils/RoundTest.kt | 35 ++++++++++++++++ 3 files changed, 41 insertions(+), 41 deletions(-) delete mode 100644 app/src/test/java/info/nightscout/androidaps/utils/RoundTest.java create mode 100644 core/src/test/java/info/nightscout/androidaps/utils/RoundTest.kt diff --git a/app/src/test/java/info/nightscout/androidaps/utils/RoundTest.java b/app/src/test/java/info/nightscout/androidaps/utils/RoundTest.java deleted file mode 100644 index 568b67057e..0000000000 --- a/app/src/test/java/info/nightscout/androidaps/utils/RoundTest.java +++ /dev/null @@ -1,41 +0,0 @@ -package info.nightscout.androidaps.utils; - -import org.junit.Test; - -import static org.junit.Assert.*; - -public class RoundTest { - - public RoundTest(){ - super(); - } - - @Test - public void roundToTest() throws Exception { - assertEquals( 0.55d, Round.roundTo(0.54d, 0.05d), 0.00000000000000000001d ); - assertEquals( -3.26d, Round.roundTo(-3.2553715764602713d, 0.01d), 0.00000000000000000001d ); - assertEquals( 0.816d, Round.roundTo(0.8156666666666667d, 0.001d), 0.00000000000000000001d ); - assertEquals( 0.235d, Round.roundTo(0.235d, 0.001d), 0.00000000000000000001d ); - assertEquals( 0.3d, Round.roundTo(0.3d, 0.1d), 0.00000000000000001d ); - assertEquals( 0.0017d, Round.roundTo(0.0016960652144170627d, 0.0001d), 0.00000000000000000001d ); - assertEquals( 0.0078d, Round.roundTo(0.007804436682291013d, 0.0001d), 0.00000000000000000001d ); - assertEquals( 0.6d, Round.roundTo(0.6d, 0.05d), 0.00000000000000000001d ); - assertEquals( 1d, Round.roundTo(1.49d, 1d), 0.00000000000000000001d ); - assertEquals( 0d, Round.roundTo(0d, 1d), 0.00000000000000000001d ); - } - - @Test - public void floorToTest() throws Exception { - assertEquals( 0.5d, Round.floorTo(0.54d, 0.05d), 0.00000001d ); - assertEquals( 1d, Round.floorTo(1.59d, 1d), 0.00000001d ); - assertEquals( 0d, Round.floorTo(0d, 1d), 0.00000001d ); - } - - @Test - public void ceilToTest() throws Exception { - assertEquals( 0.6d, Round.ceilTo(0.54d, 0.1d), 0.00000001d ); - assertEquals( 2d, Round.ceilTo(1.49999d, 1d), 0.00000001d ); - assertEquals( 0d, Round.ceilTo(0d, 1d), 0.00000001d ); - } - -} \ No newline at end of file diff --git a/core/build.gradle b/core/build.gradle index f77ee5261c..c9a18bd8ce 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -36,6 +36,12 @@ android { ext.enableCrashlytics = false } } + flavorDimensions "standard" + productFlavors { + full { + dimension "standard" + } + } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 diff --git a/core/src/test/java/info/nightscout/androidaps/utils/RoundTest.kt b/core/src/test/java/info/nightscout/androidaps/utils/RoundTest.kt new file mode 100644 index 0000000000..ad86a4755b --- /dev/null +++ b/core/src/test/java/info/nightscout/androidaps/utils/RoundTest.kt @@ -0,0 +1,35 @@ +package info.nightscout.androidaps.utils + +import org.junit.Assert +import org.junit.Test + +class RoundTest { + + @Test + fun roundToTest() { + Assert.assertEquals(0.55, Round.roundTo(0.54, 0.05), 0.00000000000000000001) + Assert.assertEquals(-3.26, Round.roundTo(-3.2553715764602713, 0.01), 0.00000000000000000001) + Assert.assertEquals(0.816, Round.roundTo(0.8156666666666667, 0.001), 0.00000000000000000001) + Assert.assertEquals(0.235, Round.roundTo(0.235, 0.001), 0.00000000000000000001) + Assert.assertEquals(0.3, Round.roundTo(0.3, 0.1), 0.00000000000000001) + Assert.assertEquals(0.0017, Round.roundTo(0.0016960652144170627, 0.0001), 0.00000000000000000001) + Assert.assertEquals(0.0078, Round.roundTo(0.007804436682291013, 0.0001), 0.00000000000000000001) + Assert.assertEquals(0.6, Round.roundTo(0.6, 0.05), 0.00000000000000000001) + Assert.assertEquals(1.0, Round.roundTo(1.49, 1.0), 0.00000000000000000001) + Assert.assertEquals(0.0, Round.roundTo(0.0, 1.0), 0.00000000000000000001) + } + + @Test + fun floorToTest() { + Assert.assertEquals(0.5, Round.floorTo(0.54, 0.05), 0.00000001) + Assert.assertEquals(1.0, Round.floorTo(1.59, 1.0), 0.00000001) + Assert.assertEquals(0.0, Round.floorTo(0.0, 1.0), 0.00000001) + } + + @Test + fun ceilToTest() { + Assert.assertEquals(0.6, Round.ceilTo(0.54, 0.1), 0.00000001) + Assert.assertEquals(2.0, Round.ceilTo(1.49999, 1.0), 0.00000001) + Assert.assertEquals(0.0, Round.ceilTo(0.0, 1.0), 0.00000001) + } +} \ No newline at end of file From 8562a3e481b16dd1a1d703f8f7c5f2eedf8abe45 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 18 Feb 2021 18:12:39 +0100 Subject: [PATCH 14/28] more test to core --- app/src/main/res/values/colors.xml | 3 - .../utils/DecimalFormatterTest.java | 42 ---- .../androidaps/utils/JsonHelperTest.java | 93 --------- .../androidaps/utils/StringUtilsTest.java | 22 -- .../nightscout/androidaps/utils/TTest.java | 49 ----- core/build.gradle | 11 + core/core_dependencies.gradle | 6 + .../layout/maintenance_import_list_item.xml | 7 +- core/src/main/res/values/colors.xml | 4 + .../info/nightscout/androidaps/TestBase.kt | 40 ++++ .../androidaps/utils/CryptoUtilTest.kt | 195 +++++++++--------- .../androidaps/utils/DateUtilTest.kt | 2 +- .../androidaps/utils/DecimalFormatterTest.kt | 30 +++ .../androidaps/utils/JsonHelperTest.kt | 82 ++++++++ .../nightscout/androidaps/utils/RoundTest.kt | 5 + .../androidaps/utils/StringUtilsTest.kt | 18 ++ .../info/nightscout/androidaps/utils/TTest.kt | 40 ++++ 17 files changed, 339 insertions(+), 310 deletions(-) delete mode 100644 app/src/test/java/info/nightscout/androidaps/utils/DecimalFormatterTest.java delete mode 100644 app/src/test/java/info/nightscout/androidaps/utils/JsonHelperTest.java delete mode 100644 app/src/test/java/info/nightscout/androidaps/utils/StringUtilsTest.java delete mode 100644 app/src/test/java/info/nightscout/androidaps/utils/TTest.java create mode 100644 core/src/test/java/info/nightscout/androidaps/TestBase.kt rename {app => core}/src/test/java/info/nightscout/androidaps/utils/CryptoUtilTest.kt (96%) rename {app => core}/src/test/java/info/nightscout/androidaps/utils/DateUtilTest.kt (98%) create mode 100644 core/src/test/java/info/nightscout/androidaps/utils/DecimalFormatterTest.kt create mode 100644 core/src/test/java/info/nightscout/androidaps/utils/JsonHelperTest.kt create mode 100644 core/src/test/java/info/nightscout/androidaps/utils/StringUtilsTest.kt create mode 100644 core/src/test/java/info/nightscout/androidaps/utils/TTest.kt diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index c45b97d50c..3ca653f8ca 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -65,7 +65,4 @@ #2E2E2E - #FFFFFF - #BBBBBB - diff --git a/app/src/test/java/info/nightscout/androidaps/utils/DecimalFormatterTest.java b/app/src/test/java/info/nightscout/androidaps/utils/DecimalFormatterTest.java deleted file mode 100644 index a7112fae48..0000000000 --- a/app/src/test/java/info/nightscout/androidaps/utils/DecimalFormatterTest.java +++ /dev/null @@ -1,42 +0,0 @@ -package info.nightscout.androidaps.utils; - -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.modules.junit4.PowerMockRunner; - -@RunWith(PowerMockRunner.class) -public class DecimalFormatterTest { - - @Test - public void to0DecimalTest() { - Assert.assertEquals("1", DecimalFormatter.to0Decimal(1.33d).replace(",", ".")); - Assert.assertEquals("1U", DecimalFormatter.to0Decimal(1.33d, "U").replace(",", ".")); - } - - @Test - public void to1DecimalTest() { - Assert.assertEquals("1.3", DecimalFormatter.to1Decimal(1.33d).replace(",", ".")); - Assert.assertEquals("1.3U", DecimalFormatter.to1Decimal(1.33d, "U").replace(",", ".")); - } - - @Test - public void to2DecimalTest() { - Assert.assertEquals("1.33", DecimalFormatter.to2Decimal(1.3333d).replace(",", ".")); - Assert.assertEquals("1.33U", DecimalFormatter.to2Decimal(1.3333d, "U").replace(",", ".")); - } - - @Test - public void to3DecimalTest() { - Assert.assertEquals("1.333", DecimalFormatter.to3Decimal(1.3333d).replace(",", ".")); - Assert.assertEquals("1.333U", DecimalFormatter.to3Decimal(1.3333d, "U").replace(",", ".")); - } - - @Test - public void toPumpSupportedBolus() { - } - - @Test - public void pumpSupportedBolusFormat() { - } -} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/utils/JsonHelperTest.java b/app/src/test/java/info/nightscout/androidaps/utils/JsonHelperTest.java deleted file mode 100644 index 359cc8de29..0000000000 --- a/app/src/test/java/info/nightscout/androidaps/utils/JsonHelperTest.java +++ /dev/null @@ -1,93 +0,0 @@ -package info.nightscout.androidaps.utils; - -import org.json.JSONException; -import org.json.JSONObject; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -/** - * Created by mike on 12.03.2018. - */ - -public class JsonHelperTest { - - private String jsonString = "{\"d\":\"3.0\",\"i\":\"4\",\"s\":\"5\",\"b\":\"true\",\"j\":{\"a\": \"1\"}}"; - - @Test - public void safeGetObjectTest() throws JSONException { - JSONObject object = new JSONObject(jsonString); - Object o = new Object(); - assertEquals(o, JsonHelper.safeGetObject(null, "x", o)); - assertEquals(o, JsonHelper.safeGetObject(object, "x", o)); - assertNotEquals(o, JsonHelper.safeGetObject(object, "d", o)); - } - - @Test - public void safeGetJSONObjectTest() throws JSONException { - JSONObject object = new JSONObject(jsonString); - JSONObject o = new JSONObject(); - assertEquals(o, JsonHelper.safeGetJSONObject(null, "x", o)); - assertTrue(JsonHelper.safeGetJSONObject(object, "j", o).has("a")); - assertEquals(o, JsonHelper.safeGetJSONObject(object, "d", o)); - } - - @Test - public void safeGetStringTest() throws JSONException { - JSONObject object = new JSONObject(jsonString); - Object o = new Object(); - assertNull(JsonHelper.safeGetString(null, "s")); - assertNull(JsonHelper.safeGetString(object, "notexisting")); - assertEquals("5", JsonHelper.safeGetString(object, "s")); - - assertEquals("default", JsonHelper.safeGetString(null, "notexisting", "default")); - assertEquals("default", JsonHelper.safeGetString(object, "notexisting", "default")); - assertEquals("5", JsonHelper.safeGetString(object, "s", "default")); - - assertEquals("default", JsonHelper.safeGetStringAllowNull(null, "notexisting", "default")); - assertEquals("default", JsonHelper.safeGetStringAllowNull(object, "notexisting", "default")); - assertNull(JsonHelper.safeGetStringAllowNull(object, "notexisting", null)); - assertEquals("5", JsonHelper.safeGetStringAllowNull(object, "s", "default")); - } - - @Test - public void safeGetDoubleTest() throws JSONException { - JSONObject object = new JSONObject(jsonString); - - assertEquals(0.0d, JsonHelper.safeGetDouble(object, "notexisting"), 0.0d); - assertEquals(0.0d, JsonHelper.safeGetDouble(null, "notexisting"), 0.0d); - assertEquals(3.0d, JsonHelper.safeGetDouble(object, "d"), 0.000001d); - - assertEquals(6d, JsonHelper.safeGetDouble(null, "notexisting", 6d), 0.0d); - assertEquals(6d, JsonHelper.safeGetDouble(object, "notexisting", 6d), 0.0d); - assertEquals(3d, JsonHelper.safeGetDouble(object, "d", 6d), 0.0d); - } - - @Test - public void safeGetLntTest() throws JSONException { - JSONObject object = new JSONObject(jsonString); - assertEquals(0, JsonHelper.safeGetInt(null, "notexisting")); - assertEquals(0, JsonHelper.safeGetInt(object, "notexisting")); - assertEquals(4, JsonHelper.safeGetInt(object, "i")); - } - - @Test - public void safeGetLongTest() throws JSONException { - JSONObject object = new JSONObject(jsonString); - assertEquals(0, JsonHelper.safeGetInt(null, "notexisting")); - assertEquals(0, JsonHelper.safeGetInt(object, "notexisting")); - assertEquals(4, JsonHelper.safeGetInt(object, "i")); - } - - @Test - public void safeGetBooleanTest() throws JSONException { - JSONObject object = new JSONObject(jsonString); - assertFalse(JsonHelper.safeGetBoolean(null, "notexisting")); - assertFalse(JsonHelper.safeGetBoolean(object, "notexisting")); - assertTrue(JsonHelper.safeGetBoolean(object, "b")); - } -} diff --git a/app/src/test/java/info/nightscout/androidaps/utils/StringUtilsTest.java b/app/src/test/java/info/nightscout/androidaps/utils/StringUtilsTest.java deleted file mode 100644 index dd95962964..0000000000 --- a/app/src/test/java/info/nightscout/androidaps/utils/StringUtilsTest.java +++ /dev/null @@ -1,22 +0,0 @@ -package info.nightscout.androidaps.utils; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -public class StringUtilsTest { - - @Test - public void removeSurroundingQuotesTest() { - String compareString = "test"; - - assertEquals(compareString, StringUtils.removeSurroundingQuotes(compareString)); - assertEquals(compareString, StringUtils.removeSurroundingQuotes("\"" + compareString + "\"")); - assertEquals("\"" + compareString, StringUtils.removeSurroundingQuotes("\"" + compareString)); - - compareString = "te\"st"; - assertEquals(compareString, StringUtils.removeSurroundingQuotes(compareString)); - assertEquals(compareString, StringUtils.removeSurroundingQuotes("\"" + compareString + "\"")); - assertEquals("\"" + compareString, StringUtils.removeSurroundingQuotes("\"" + compareString)); - } -} diff --git a/app/src/test/java/info/nightscout/androidaps/utils/TTest.java b/app/src/test/java/info/nightscout/androidaps/utils/TTest.java deleted file mode 100644 index fa5bcbd8ad..0000000000 --- a/app/src/test/java/info/nightscout/androidaps/utils/TTest.java +++ /dev/null @@ -1,49 +0,0 @@ -package info.nightscout.androidaps.utils; - -import org.junit.Assert; -import org.junit.Test; - -/** - * Created by mike on 26.03.2018. - */ - -//@RunWith(PowerMockRunner.class) -public class TTest { - - @Test - public void toUnits() { - Assert.assertEquals(1, T.msecs(1000).secs()); - Assert.assertEquals(1, T.secs(60).mins()); - Assert.assertEquals(1, T.mins(60).hours()); - Assert.assertEquals(1, T.hours(24).days()); - Assert.assertEquals(24, T.days(1).hours()); - Assert.assertEquals(60000, T.mins(1).msecs()); - } - - @Test - public void now() { - Assert.assertTrue(Math.abs(T.now().msecs() - System.currentTimeMillis()) < 5000); - } - - @Test - public void additions() { - long nowMsecs = System.currentTimeMillis(); - T now = T.msecs(nowMsecs); - - Assert.assertEquals(now.plus(T.secs(5)).msecs(), nowMsecs + 5 * 1000); - Assert.assertEquals(now.plus(T.mins(5)).msecs(), nowMsecs + 5 * 60 * 1000); - Assert.assertEquals(now.plus(T.hours(5)).msecs(), nowMsecs + 5 * 60 * 60 * 1000); - Assert.assertEquals(now.plus(T.days(5)).msecs(), nowMsecs + 5 * 24 * 60 * 60 * 1000); - } - - @Test - public void subtractions() { - long nowMsecs = System.currentTimeMillis(); - T now = T.msecs(nowMsecs); - - Assert.assertEquals(now.minus(T.secs(5)).msecs(), nowMsecs - 5 * 1000); - Assert.assertEquals(now.minus(T.mins(5)).msecs(), nowMsecs - 5 * 60 * 1000); - Assert.assertEquals(now.minus(T.hours(5)).msecs(), nowMsecs - 5 * 60 * 60 * 1000); - Assert.assertEquals(now.minus(T.days(5)).msecs(), nowMsecs - 5 * 24 * 60 * 60 * 1000); - } -} diff --git a/core/build.gradle b/core/build.gradle index c9a18bd8ce..a539c9528d 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -46,6 +46,17 @@ android { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } + testOptions { + unitTests { + returnDefaultValues = true + includeAndroidResources = true + + all { + maxParallelForks = 10 + forkEvery = 20 + } + } + } } diff --git a/core/core_dependencies.gradle b/core/core_dependencies.gradle index 283e90adab..dbbb926ca6 100644 --- a/core/core_dependencies.gradle +++ b/core/core_dependencies.gradle @@ -109,6 +109,12 @@ dependencies { api 'com.scottyab:rootbeer-lib:0.0.8' testImplementation "junit:junit:$junit_version" + testImplementation "org.mockito:mockito-core:${mockitoVersion}" + testImplementation "org.powermock:powermock-api-mockito2:${powermockVersion}" + testImplementation "org.powermock:powermock-module-junit4-rule-agent:${powermockVersion}" + testImplementation "org.powermock:powermock-module-junit4-rule:${powermockVersion}" + testImplementation "org.powermock:powermock-module-junit4:${powermockVersion}" androidTestImplementation "androidx.test.ext:junit:$androidx_junit" androidTestImplementation "androidx.test:rules:$androidx_rules" + testImplementation 'org.json:json:20201115' // Needed for JsonHelperTest } \ No newline at end of file diff --git a/core/src/main/res/layout/maintenance_import_list_item.xml b/core/src/main/res/layout/maintenance_import_list_item.xml index e36e36cd6f..f79758b19b 100644 --- a/core/src/main/res/layout/maintenance_import_list_item.xml +++ b/core/src/main/res/layout/maintenance_import_list_item.xml @@ -1,5 +1,6 @@ + app:tint="@color/importListFileName" /> + app:tint="@color/importListAdditionalInfo" /> + app:tint="@color/importListAdditionalInfo" /> #FF8C00 #FF5555 + + #BBBBBB + #FFFFFF + diff --git a/core/src/test/java/info/nightscout/androidaps/TestBase.kt b/core/src/test/java/info/nightscout/androidaps/TestBase.kt new file mode 100644 index 0000000000..573c9dcbcc --- /dev/null +++ b/core/src/test/java/info/nightscout/androidaps/TestBase.kt @@ -0,0 +1,40 @@ +package info.nightscout.androidaps + +import info.nightscout.androidaps.logging.AAPSLoggerTest +import info.nightscout.androidaps.utils.rx.AapsSchedulers +import info.nightscout.androidaps.utils.rx.TestAapsSchedulers +import org.junit.Before +import org.junit.Rule +import org.mockito.Mockito +import org.mockito.junit.MockitoJUnit +import org.mockito.junit.MockitoRule +import java.util.* + +@Suppress("SpellCheckingInspection") +open class TestBase { + + val aapsLogger = AAPSLoggerTest() + val aapsSchedulers: AapsSchedulers = TestAapsSchedulers() + + // Add a JUnit rule that will setup the @Mock annotated vars and log. + // Another possibility would be to add `MockitoAnnotations.initMocks(this) to the setup method. + @get:Rule + val mockitoRule: MockitoRule = MockitoJUnit.rule() + + @Before + fun setupLocale() { + Locale.setDefault(Locale.ENGLISH) + System.setProperty("disableFirebase", "true") + } + + // Workaround for Kotlin nullability. + // https://medium.com/@elye.project/befriending-kotlin-and-mockito-1c2e7b0ef791 + // https://stackoverflow.com/questions/30305217/is-it-possible-to-use-mockito-in-kotlin + fun anyObject(): T { + Mockito.any() + return uninitialized() + } + + @Suppress("Unchecked_Cast") + fun uninitialized(): T = null as T +} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/utils/CryptoUtilTest.kt b/core/src/test/java/info/nightscout/androidaps/utils/CryptoUtilTest.kt similarity index 96% rename from app/src/test/java/info/nightscout/androidaps/utils/CryptoUtilTest.kt rename to core/src/test/java/info/nightscout/androidaps/utils/CryptoUtilTest.kt index 9d6b3ad9cd..f79dc0b95d 100644 --- a/app/src/test/java/info/nightscout/androidaps/utils/CryptoUtilTest.kt +++ b/core/src/test/java/info/nightscout/androidaps/utils/CryptoUtilTest.kt @@ -1,97 +1,98 @@ -package info.nightscout.androidaps.utils - -import info.nightscout.androidaps.TestBase -import org.hamcrest.CoreMatchers.containsString -import org.hamcrest.CoreMatchers.not -import org.junit.Assert -import org.junit.Assume.assumeThat -import org.junit.Test -import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PowerMockIgnore -import org.powermock.modules.junit4.PowerMockRunner - -// https://stackoverflow.com/questions/52344522/joseexception-couldnt-create-aes-gcm-nopadding-cipher-illegal-key-size -// https://stackoverflow.com/questions/47708951/can-aes-256-work-on-android-devices-with-api-level-26 -// Java prior to Oracle Java 8u161 does not have policy for 256 bit AES - but Android support it -// when test is run in Vanilla JVM without policy - Invalid key size exception is thrown -fun assumeAES256isSupported(cryptoUtil: CryptoUtil) { - cryptoUtil.lastException?.message?.let { exceptionMessage -> - assumeThat("Upgrade your testing environment Java (OpenJDK or Java 8u161) and JAVA_HOME - AES 256 is supported by Android so this exception should not happen!", exceptionMessage, not(containsString("key size"))) - } -} - -@PowerMockIgnore("javax.crypto.*") -@RunWith(PowerMockRunner::class) -class CryptoUtilTest: TestBase() { - - var cryptoUtil: CryptoUtil = CryptoUtil(aapsLogger) - - @Test - fun testFixedSaltCrypto() { - val salt = byteArrayOf( - -33, -29, 16, -19, 99, -111, -3, 2, 116, 106, 47, 38, -54, 11, -77, 28, - 111, -15, -65, -110, 4, -32, -29, -70, -95, -88, -53, 19, 87, -103, 123, -15) - - val password = "thisIsFixedPassword" - val payload = "FIXED-PAYLOAD" - - val encrypted = cryptoUtil.encrypt(password, salt, payload) - assumeAES256isSupported(cryptoUtil) - Assert.assertNotNull(encrypted) - - val decrypted = cryptoUtil.decrypt(password, salt, encrypted!!) - assumeAES256isSupported(cryptoUtil) - Assert.assertEquals(decrypted, payload) - } - - @Test - fun testStandardCrypto() { - val salt = cryptoUtil.mineSalt() - - val password = "topSikret" - val payload = "{what:payloadYouWantToProtect}" - - val encrypted = cryptoUtil.encrypt(password, salt, payload) - assumeAES256isSupported(cryptoUtil) - Assert.assertNotNull(encrypted) - - val decrypted = cryptoUtil.decrypt(password, salt, encrypted!!) - assumeAES256isSupported(cryptoUtil) - Assert.assertEquals(decrypted, payload) - } - - @Test - fun testHashVector() { - val payload = "{what:payloadYouWantToProtect}" - val hash = cryptoUtil.sha256(payload) - Assert.assertEquals(hash, "a1aafe3ed6cc127e6d102ddbc40a205147230e9cfd178daf108c83543bbdcd13") - } - - @Test - fun testHmac() { - val payload = "{what:payloadYouWantToProtect}" - val password = "topSikret" - val expectedHmac = "ea2213953d0f2e55047cae2d23fb4f0de1b805d55e6271efa70d6b85fb692bea" // generated using other HMAC tool - val hash = cryptoUtil.hmac256(payload, password) - Assert.assertEquals(hash, expectedHmac) - } - - @Test - fun testPlainPasswordCheck() { - Assert.assertTrue(cryptoUtil.checkPassword("same", "same")) - Assert.assertFalse(cryptoUtil.checkPassword("same", "other")) - } - - @Test - fun testHashedPasswordCheck() { - Assert.assertTrue(cryptoUtil.checkPassword("givenSecret", cryptoUtil.hashPassword("givenSecret"))) - Assert.assertFalse(cryptoUtil.checkPassword("givenSecret", cryptoUtil.hashPassword("otherSecret"))) - - Assert.assertTrue(cryptoUtil.checkPassword("givenHashToCheck", "hmac:7fe5f9c7b4b97c5d32d5cfad9d07473543a9938dc07af48a46dbbb49f4f68c12:a0c7cee14312bbe31b51359a67f0d2dfdf46813f319180269796f1f617a64be1")) - Assert.assertFalse(cryptoUtil.checkPassword("givenMashToCheck", "hmac:7fe5f9c7b4b97c5d32d5cfad9d07473543a9938dc07af48a46dbbb49f4f68c12:a0c7cee14312bbe31b51359a67f0d2dfdf46813f319180269796f1f617a64be1")) - Assert.assertFalse(cryptoUtil.checkPassword("givenHashToCheck", "hmac:0fe5f9c7b4b97c5d32d5cfad9d07473543a9938dc07af48a46dbbb49f4f68c12:a0c7cee14312bbe31b51359a67f0d2dfdf46813f319180269796f1f617a64be1")) - Assert.assertFalse(cryptoUtil.checkPassword("givenHashToCheck", "hmac:7fe5f9c7b4b97c5d32d5cfad9d07473543a9938dc07af48a46dbbb49f4f68c12:b0c7cee14312bbe31b51359a67f0d2dfdf46813f319180269796f1f617a64be1")) - } - -} - +package info.nightscout.androidaps.utils + +import info.nightscout.androidaps.TestBase +import org.hamcrest.CoreMatchers.containsString +import org.hamcrest.CoreMatchers.not +import org.junit.Assert +import org.junit.Assume.assumeThat +import org.junit.Test +import org.junit.runner.RunWith +import org.powermock.core.classloader.annotations.PowerMockIgnore +import org.powermock.modules.junit4.PowerMockRunner + +// https://stackoverflow.com/questions/52344522/joseexception-couldnt-create-aes-gcm-nopadding-cipher-illegal-key-size +// https://stackoverflow.com/questions/47708951/can-aes-256-work-on-android-devices-with-api-level-26 +// Java prior to Oracle Java 8u161 does not have policy for 256 bit AES - but Android support it +// when test is run in Vanilla JVM without policy - Invalid key size exception is thrown +fun assumeAES256isSupported(cryptoUtil: CryptoUtil) { + cryptoUtil.lastException?.message?.let { exceptionMessage -> + assumeThat("Upgrade your testing environment Java (OpenJDK or Java 8u161) and JAVA_HOME - AES 256 is supported by Android so this exception should not happen!", exceptionMessage, not(containsString("key size"))) + } +} + +@Suppress("SpellCheckingInspection") +@PowerMockIgnore("javax.crypto.*") +@RunWith(PowerMockRunner::class) +class CryptoUtilTest: TestBase() { + + private var cryptoUtil: CryptoUtil = CryptoUtil(aapsLogger) + + @Test + fun testFixedSaltCrypto() { + val salt = byteArrayOf( + -33, -29, 16, -19, 99, -111, -3, 2, 116, 106, 47, 38, -54, 11, -77, 28, + 111, -15, -65, -110, 4, -32, -29, -70, -95, -88, -53, 19, 87, -103, 123, -15) + + val password = "thisIsFixedPassword" + val payload = "FIXED-PAYLOAD" + + val encrypted = cryptoUtil.encrypt(password, salt, payload) + assumeAES256isSupported(cryptoUtil) + Assert.assertNotNull(encrypted) + + val decrypted = cryptoUtil.decrypt(password, salt, encrypted!!) + assumeAES256isSupported(cryptoUtil) + Assert.assertEquals(decrypted, payload) + } + + @Test + fun testStandardCrypto() { + val salt = cryptoUtil.mineSalt() + + val password = "topSikret" + val payload = "{what:payloadYouWantToProtect}" + + val encrypted = cryptoUtil.encrypt(password, salt, payload) + assumeAES256isSupported(cryptoUtil) + Assert.assertNotNull(encrypted) + + val decrypted = cryptoUtil.decrypt(password, salt, encrypted!!) + assumeAES256isSupported(cryptoUtil) + Assert.assertEquals(decrypted, payload) + } + + @Test + fun testHashVector() { + val payload = "{what:payloadYouWantToProtect}" + val hash = cryptoUtil.sha256(payload) + Assert.assertEquals(hash, "a1aafe3ed6cc127e6d102ddbc40a205147230e9cfd178daf108c83543bbdcd13") + } + + @Test + fun testHmac() { + val payload = "{what:payloadYouWantToProtect}" + val password = "topSikret" + val expectedHmac = "ea2213953d0f2e55047cae2d23fb4f0de1b805d55e6271efa70d6b85fb692bea" // generated using other HMAC tool + val hash = cryptoUtil.hmac256(payload, password) + Assert.assertEquals(hash, expectedHmac) + } + + @Test + fun testPlainPasswordCheck() { + Assert.assertTrue(cryptoUtil.checkPassword("same", "same")) + Assert.assertFalse(cryptoUtil.checkPassword("same", "other")) + } + + @Test + fun testHashedPasswordCheck() { + Assert.assertTrue(cryptoUtil.checkPassword("givenSecret", cryptoUtil.hashPassword("givenSecret"))) + Assert.assertFalse(cryptoUtil.checkPassword("givenSecret", cryptoUtil.hashPassword("otherSecret"))) + + Assert.assertTrue(cryptoUtil.checkPassword("givenHashToCheck", "hmac:7fe5f9c7b4b97c5d32d5cfad9d07473543a9938dc07af48a46dbbb49f4f68c12:a0c7cee14312bbe31b51359a67f0d2dfdf46813f319180269796f1f617a64be1")) + Assert.assertFalse(cryptoUtil.checkPassword("givenMashToCheck", "hmac:7fe5f9c7b4b97c5d32d5cfad9d07473543a9938dc07af48a46dbbb49f4f68c12:a0c7cee14312bbe31b51359a67f0d2dfdf46813f319180269796f1f617a64be1")) + Assert.assertFalse(cryptoUtil.checkPassword("givenHashToCheck", "hmac:0fe5f9c7b4b97c5d32d5cfad9d07473543a9938dc07af48a46dbbb49f4f68c12:a0c7cee14312bbe31b51359a67f0d2dfdf46813f319180269796f1f617a64be1")) + Assert.assertFalse(cryptoUtil.checkPassword("givenHashToCheck", "hmac:7fe5f9c7b4b97c5d32d5cfad9d07473543a9938dc07af48a46dbbb49f4f68c12:b0c7cee14312bbe31b51359a67f0d2dfdf46813f319180269796f1f617a64be1")) + } + +} + diff --git a/app/src/test/java/info/nightscout/androidaps/utils/DateUtilTest.kt b/core/src/test/java/info/nightscout/androidaps/utils/DateUtilTest.kt similarity index 98% rename from app/src/test/java/info/nightscout/androidaps/utils/DateUtilTest.kt rename to core/src/test/java/info/nightscout/androidaps/utils/DateUtilTest.kt index 064b843234..8df098789e 100644 --- a/app/src/test/java/info/nightscout/androidaps/utils/DateUtilTest.kt +++ b/core/src/test/java/info/nightscout/androidaps/utils/DateUtilTest.kt @@ -2,7 +2,7 @@ package info.nightscout.androidaps.utils import android.content.Context import info.nightscout.androidaps.TestBase -import info.nightscout.androidaps.R +import info.nightscout.androidaps.core.R import info.nightscout.androidaps.utils.resources.ResourceHelper import org.junit.Assert import org.junit.Test diff --git a/core/src/test/java/info/nightscout/androidaps/utils/DecimalFormatterTest.kt b/core/src/test/java/info/nightscout/androidaps/utils/DecimalFormatterTest.kt new file mode 100644 index 0000000000..35049e7fb8 --- /dev/null +++ b/core/src/test/java/info/nightscout/androidaps/utils/DecimalFormatterTest.kt @@ -0,0 +1,30 @@ +package info.nightscout.androidaps.utils + +import org.junit.Assert +import org.junit.Test +import org.junit.runner.RunWith +import org.powermock.modules.junit4.PowerMockRunner + +@RunWith(PowerMockRunner::class) +class DecimalFormatterTest { + + @Test fun to0DecimalTest() { + Assert.assertEquals("1", DecimalFormatter.to0Decimal(1.33).replace(",", ".")) + Assert.assertEquals("1U", DecimalFormatter.to0Decimal(1.33, "U").replace(",", ".")) + } + + @Test fun to1DecimalTest() { + Assert.assertEquals("1.3", DecimalFormatter.to1Decimal(1.33).replace(",", ".")) + Assert.assertEquals("1.3U", DecimalFormatter.to1Decimal(1.33, "U").replace(",", ".")) + } + + @Test fun to2DecimalTest() { + Assert.assertEquals("1.33", DecimalFormatter.to2Decimal(1.3333).replace(",", ".")) + Assert.assertEquals("1.33U", DecimalFormatter.to2Decimal(1.3333, "U").replace(",", ".")) + } + + @Test fun to3DecimalTest() { + Assert.assertEquals("1.333", DecimalFormatter.to3Decimal(1.3333).replace(",", ".")) + Assert.assertEquals("1.333U", DecimalFormatter.to3Decimal(1.3333, "U").replace(",", ".")) + } +} \ No newline at end of file diff --git a/core/src/test/java/info/nightscout/androidaps/utils/JsonHelperTest.kt b/core/src/test/java/info/nightscout/androidaps/utils/JsonHelperTest.kt new file mode 100644 index 0000000000..c2863ff4a3 --- /dev/null +++ b/core/src/test/java/info/nightscout/androidaps/utils/JsonHelperTest.kt @@ -0,0 +1,82 @@ +package info.nightscout.androidaps.utils + +import org.json.JSONObject +import org.junit.Assert +import org.junit.Test +import org.junit.runner.RunWith +import org.powermock.modules.junit4.PowerMockRunner + +@Suppress("SpellCheckingInspection") +@RunWith(PowerMockRunner::class) +class JsonHelperTest { + + private val jsonString = "{\"d\":\"3.0\",\"i\":\"4\",\"s\":\"5\",\"b\":\"true\",\"j\":{\"a\": \"1\"}}" + + @Test + fun safeGetObjectTest() { + val json = JSONObject(jsonString) + val o = Any() + Assert.assertEquals(o, JsonHelper.safeGetObject(null, "x", o)) + Assert.assertEquals(o, JsonHelper.safeGetObject(json, "x", o)) + Assert.assertNotEquals(o, JsonHelper.safeGetObject(json, "d", o)) + } + + @Test + fun safeGetJSONObjectTest() { + val json = JSONObject(jsonString) + val o = JSONObject() + Assert.assertEquals(o, JsonHelper.safeGetJSONObject(null, "x", o)) + Assert.assertTrue(JsonHelper.safeGetJSONObject(json, "j", o)!!.has("a")) + Assert.assertEquals(o, JsonHelper.safeGetJSONObject(json, "d", o)) + } + + @Test + fun safeGetStringTest() { + val json = JSONObject(jsonString) + Assert.assertNull(JsonHelper.safeGetString(null, "s")) + Assert.assertNull(JsonHelper.safeGetString(json, "notexisting")) + Assert.assertEquals("5", JsonHelper.safeGetString(json, "s")) + Assert.assertEquals("default", JsonHelper.safeGetString(null, "notexisting", "default")) + Assert.assertEquals("default", JsonHelper.safeGetString(json, "notexisting", "default")) + Assert.assertEquals("5", JsonHelper.safeGetString(json, "s", "default")) + Assert.assertEquals("default", JsonHelper.safeGetStringAllowNull(null, "notexisting", "default")) + Assert.assertEquals("default", JsonHelper.safeGetStringAllowNull(json, "notexisting", "default")) + Assert.assertNull(JsonHelper.safeGetStringAllowNull(json, "notexisting", null)) + Assert.assertEquals("5", JsonHelper.safeGetStringAllowNull(json, "s", "default")) + } + + @Test + fun safeGetDoubleTest() { + val json = JSONObject(jsonString) + Assert.assertEquals(0.0, JsonHelper.safeGetDouble(json, "notexisting"), 0.0) + Assert.assertEquals(0.0, JsonHelper.safeGetDouble(null, "notexisting"), 0.0) + Assert.assertEquals(3.0, JsonHelper.safeGetDouble(json, "d"), 0.000001) + Assert.assertEquals(6.0, JsonHelper.safeGetDouble(null, "notexisting", 6.0), 0.0) + Assert.assertEquals(6.0, JsonHelper.safeGetDouble(json, "notexisting", 6.0), 0.0) + Assert.assertEquals(3.0, JsonHelper.safeGetDouble(json, "d", 6.0), 0.0) + } + + @Test + fun safeGetLntTest() { + val json = JSONObject(jsonString) + Assert.assertEquals(0, JsonHelper.safeGetInt(null, "notexisting").toLong()) + Assert.assertEquals(0, JsonHelper.safeGetInt(json, "notexisting").toLong()) + Assert.assertEquals(4, JsonHelper.safeGetInt(json, "i").toLong()) + } + + @Test + fun safeGetLongTest() { + val json = JSONObject(jsonString) + Assert.assertEquals(0, JsonHelper.safeGetInt(null, "notexisting").toLong()) + Assert.assertEquals(0, JsonHelper.safeGetInt(json, "notexisting").toLong()) + Assert.assertEquals(4, JsonHelper.safeGetInt(json, "i").toLong()) + } + + @Test + fun safeGetBooleanTest() { + val json = JSONObject(jsonString) + Assert.assertFalse(JsonHelper.safeGetBoolean(null, "notexisting")) + Assert.assertFalse(JsonHelper.safeGetBoolean(json, "notexisting")) + Assert.assertTrue(JsonHelper.safeGetBoolean(json, "b")) + } +} \ No newline at end of file diff --git a/core/src/test/java/info/nightscout/androidaps/utils/RoundTest.kt b/core/src/test/java/info/nightscout/androidaps/utils/RoundTest.kt index ad86a4755b..e798b28e35 100644 --- a/core/src/test/java/info/nightscout/androidaps/utils/RoundTest.kt +++ b/core/src/test/java/info/nightscout/androidaps/utils/RoundTest.kt @@ -32,4 +32,9 @@ class RoundTest { Assert.assertEquals(2.0, Round.ceilTo(1.49999, 1.0), 0.00000001) Assert.assertEquals(0.0, Round.ceilTo(0.0, 1.0), 0.00000001) } + + @Test + fun isSameTest() { + Assert.assertTrue(Round.isSame(0.54, 0.54)) + } } \ No newline at end of file diff --git a/core/src/test/java/info/nightscout/androidaps/utils/StringUtilsTest.kt b/core/src/test/java/info/nightscout/androidaps/utils/StringUtilsTest.kt new file mode 100644 index 0000000000..3bf95fa75e --- /dev/null +++ b/core/src/test/java/info/nightscout/androidaps/utils/StringUtilsTest.kt @@ -0,0 +1,18 @@ +package info.nightscout.androidaps.utils + +import org.junit.Assert +import org.junit.Test + +class StringUtilsTest { + + @Test fun removeSurroundingQuotesTest() { + var compareString = "test" + Assert.assertEquals(compareString, StringUtils.removeSurroundingQuotes(compareString)) + Assert.assertEquals(compareString, StringUtils.removeSurroundingQuotes("\"" + compareString + "\"")) + Assert.assertEquals("\"" + compareString, StringUtils.removeSurroundingQuotes("\"" + compareString)) + compareString = "te\"st" + Assert.assertEquals(compareString, StringUtils.removeSurroundingQuotes(compareString)) + Assert.assertEquals(compareString, StringUtils.removeSurroundingQuotes("\"" + compareString + "\"")) + Assert.assertEquals("\"" + compareString, StringUtils.removeSurroundingQuotes("\"" + compareString)) + } +} \ No newline at end of file diff --git a/core/src/test/java/info/nightscout/androidaps/utils/TTest.kt b/core/src/test/java/info/nightscout/androidaps/utils/TTest.kt new file mode 100644 index 0000000000..7893ffda67 --- /dev/null +++ b/core/src/test/java/info/nightscout/androidaps/utils/TTest.kt @@ -0,0 +1,40 @@ +package info.nightscout.androidaps.utils + +import org.junit.Assert +import org.junit.Test +import kotlin.math.abs + +@Suppress("SpellCheckingInspection") +class TTest { + + @Test fun toUnits() { + Assert.assertEquals(1, T.msecs(1000).secs()) + Assert.assertEquals(1, T.secs(60).mins()) + Assert.assertEquals(1, T.mins(60).hours()) + Assert.assertEquals(1, T.hours(24).days()) + Assert.assertEquals(24, T.days(1).hours()) + Assert.assertEquals(60000, T.mins(1).msecs()) + } + + @Test fun now() { + Assert.assertTrue(abs(T.now().msecs() - System.currentTimeMillis()) < 5000) + } + + @Test fun additions() { + val nowMsecs = System.currentTimeMillis() + val now = T.msecs(nowMsecs) + Assert.assertEquals(now.plus(T.secs(5)).msecs(), nowMsecs + 5 * 1000) + Assert.assertEquals(now.plus(T.mins(5)).msecs(), nowMsecs + 5 * 60 * 1000) + Assert.assertEquals(now.plus(T.hours(5)).msecs(), nowMsecs + 5 * 60 * 60 * 1000) + Assert.assertEquals(now.plus(T.days(5)).msecs(), nowMsecs + 5 * 24 * 60 * 60 * 1000) + } + + @Test fun subtractions() { + val nowMsecs = System.currentTimeMillis() + val now = T.msecs(nowMsecs) + Assert.assertEquals(now.minus(T.secs(5)).msecs(), nowMsecs - 5 * 1000) + Assert.assertEquals(now.minus(T.mins(5)).msecs(), nowMsecs - 5 * 60 * 1000) + Assert.assertEquals(now.minus(T.hours(5)).msecs(), nowMsecs - 5 * 60 * 60 * 1000) + Assert.assertEquals(now.minus(T.days(5)).msecs(), nowMsecs - 5 * 24 * 60 * 60 * 1000) + } +} \ No newline at end of file From 6022bf8fb2fcb598381c1ffab967216b0eb2e073 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 18 Feb 2021 18:54:01 +0100 Subject: [PATCH 15/28] add jacoco to dana modules --- app/build.gradle | 39 ++----------- .../maintenance/EncryptedPrefsFormatTest.kt | 57 +++++++++++-------- core/build.gradle | 14 +---- core/core_dependencies.gradle | 10 ---- dana/build.gradle | 7 +-- danar/build.gradle | 7 +-- danars/build.gradle | 6 +- gradle/android_dependencies.gradle | 0 gradle/test_dependencies.gradle | 35 ++++++++++++ 9 files changed, 84 insertions(+), 91 deletions(-) create mode 100644 gradle/android_dependencies.gradle create mode 100644 gradle/test_dependencies.gradle diff --git a/app/build.gradle b/app/build.gradle index 3ea69de937..6fdc3c7d18 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -196,18 +196,6 @@ android { targetCompatibility JavaVersion.VERSION_1_8 } - testOptions { - unitTests { - returnDefaultValues = true - includeAndroidResources = true - - all { - maxParallelForks = 10 - forkEvery = 20 - } - } - } - useLibrary "org.apache.http.legacy" } @@ -235,27 +223,9 @@ dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') - testImplementation "junit:junit:$junit_version" - testImplementation 'org.json:json:20201115' - testImplementation "org.mockito:mockito-core:${mockitoVersion}" - testImplementation "org.powermock:powermock-api-mockito2:${powermockVersion}" - testImplementation "org.powermock:powermock-module-junit4-rule-agent:${powermockVersion}" - testImplementation "org.powermock:powermock-module-junit4-rule:${powermockVersion}" - testImplementation "org.powermock:powermock-module-junit4:${powermockVersion}" - testImplementation "joda-time:joda-time:$jodatime_version" - testImplementation('com.google.truth:truth:1.1.2') { - exclude group: "com.google.guava", module: "guava" - } - testImplementation "org.skyscreamer:jsonassert:1.5.0" - testImplementation "org.hamcrest:hamcrest-all:1.3" - - androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0-alpha04' - androidTestImplementation "androidx.test.ext:junit:$androidx_junit" - androidTestImplementation "androidx.test:rules:$androidx_rules" - /* Dagger2 - We are going to use dagger.android which includes - * support for Activity and fragment injection so we need to include - * the following dependencies */ + * support for Activity and fragment injection so we need to include + * the following dependencies */ annotationProcessor "com.google.dagger:dagger-compiler:$dagger_version" @@ -264,10 +234,11 @@ dependencies { /* Dagger2 - default dependency */ kapt "com.google.dagger:dagger-compiler:$dagger_version" - - androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0' } +apply from: "${project.rootDir}/gradle/test_dependencies.gradle" + + /* // Run 'adb' shell command to clear application data of main app for 'debug' variant task clearMainAppData(type: Exec) { diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/maintenance/EncryptedPrefsFormatTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/maintenance/EncryptedPrefsFormatTest.kt index 5438f15eac..22674da300 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/maintenance/EncryptedPrefsFormatTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/maintenance/EncryptedPrefsFormatTest.kt @@ -4,11 +4,11 @@ import info.nightscout.androidaps.TestBase import info.nightscout.androidaps.plugins.general.maintenance.formats.* import info.nightscout.androidaps.testing.utils.SingleStringStorage import info.nightscout.androidaps.utils.CryptoUtil -import info.nightscout.androidaps.utils.assumeAES256isSupported import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP import org.hamcrest.CoreMatchers import org.junit.Assert +import org.junit.Assume import org.junit.Before import org.junit.Test import org.junit.runner.RunWith @@ -20,6 +20,7 @@ import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner import java.io.File +@Suppress("SpellCheckingInspection") @PowerMockIgnore("javax.crypto.*") @RunWith(PowerMockRunner::class) @PrepareForTest(File::class) @@ -32,6 +33,16 @@ class EncryptedPrefsFormatTest : TestBase() { private var cryptoUtil: CryptoUtil = CryptoUtil(aapsLogger) + // https://stackoverflow.com/questions/52344522/joseexception-couldnt-create-aes-gcm-nopadding-cipher-illegal-key-size + // https://stackoverflow.com/questions/47708951/can-aes-256-work-on-android-devices-with-api-level-26 + // Java prior to Oracle Java 8u161 does not have policy for 256 bit AES - but Android support it + // when test is run in Vanilla JVM without policy - Invalid key size exception is thrown + private fun assumeAES256isSupported(cryptoUtil: CryptoUtil) { + cryptoUtil.lastException?.message?.let { exceptionMessage -> + Assume.assumeThat("Upgrade your testing environment Java (OpenJDK or Java 8u161) and JAVA_HOME - AES 256 is supported by Android so this exception should not happen!", exceptionMessage, CoreMatchers.not(CoreMatchers.containsString("key size"))) + } + } + @Before fun mock() { Mockito.`when`(resourceHelper.gs(ArgumentMatchers.anyInt())).thenReturn("mock translation") @@ -57,13 +68,13 @@ class EncryptedPrefsFormatTest : TestBase() { assumeAES256isSupported(cryptoUtil) - Assert.assertThat(prefs.values.size, CoreMatchers.`is`(2)) - Assert.assertThat(prefs.values["key1"], CoreMatchers.`is`("A")) - Assert.assertThat(prefs.values["keyB"], CoreMatchers.`is`("2")) + Assert.assertEquals(prefs.values.size, 2) + Assert.assertEquals(prefs.values["key1"], "A") + Assert.assertEquals(prefs.values["keyB"], "2") - Assert.assertThat(prefs.metadata[PrefsMetadataKey.FILE_FORMAT]?.status, CoreMatchers.`is`(PrefsStatus.OK)) - Assert.assertThat(prefs.metadata[PrefsMetadataKey.FILE_FORMAT]?.value, CoreMatchers.`is`(EncryptedPrefsFormat.FORMAT_KEY_ENC)) - Assert.assertThat(prefs.metadata[PrefsMetadataKey.ENCRYPTION]?.status, CoreMatchers.`is`(PrefsStatus.OK)) + Assert.assertEquals(prefs.metadata[PrefsMetadataKey.FILE_FORMAT]?.status, PrefsStatus.OK) + Assert.assertEquals(prefs.metadata[PrefsMetadataKey.FILE_FORMAT]?.value, EncryptedPrefsFormat.FORMAT_KEY_ENC) + Assert.assertEquals(prefs.metadata[PrefsMetadataKey.ENCRYPTION]?.status, PrefsStatus.OK) } @Test @@ -101,13 +112,13 @@ class EncryptedPrefsFormatTest : TestBase() { assumeAES256isSupported(cryptoUtil) - Assert.assertThat(prefsOut.values.size, CoreMatchers.`is`(2)) - Assert.assertThat(prefsOut.values["testpref1"], CoreMatchers.`is`("--1--")) - Assert.assertThat(prefsOut.values["testpref2"], CoreMatchers.`is`("another")) + Assert.assertEquals(prefsOut.values.size, 2) + Assert.assertEquals(prefsOut.values["testpref1"], "--1--") + Assert.assertEquals(prefsOut.values["testpref2"], "another") - Assert.assertThat(prefsOut.metadata[PrefsMetadataKey.FILE_FORMAT]?.status, CoreMatchers.`is`(PrefsStatus.OK)) - Assert.assertThat(prefsOut.metadata[PrefsMetadataKey.FILE_FORMAT]?.value, CoreMatchers.`is`(EncryptedPrefsFormat.FORMAT_KEY_ENC)) - Assert.assertThat(prefsOut.metadata[PrefsMetadataKey.ENCRYPTION]?.status, CoreMatchers.`is`(PrefsStatus.OK)) + Assert.assertEquals(prefsOut.metadata[PrefsMetadataKey.FILE_FORMAT]?.status, PrefsStatus.OK) + Assert.assertEquals(prefsOut.metadata[PrefsMetadataKey.FILE_FORMAT]?.value, EncryptedPrefsFormat.FORMAT_KEY_ENC) + Assert.assertEquals(prefsOut.metadata[PrefsMetadataKey.ENCRYPTION]?.status, PrefsStatus.OK) } @Test @@ -128,11 +139,11 @@ class EncryptedPrefsFormatTest : TestBase() { val encryptedFormat = EncryptedPrefsFormat(resourceHelper, cryptoUtil, storage) val prefs = encryptedFormat.loadPreferences(getMockedFile(), "it-is-NOT-right-secret") - Assert.assertThat(prefs.values.size, CoreMatchers.`is`(0)) + Assert.assertEquals(prefs.values.size, 0) - Assert.assertThat(prefs.metadata[PrefsMetadataKey.FILE_FORMAT]?.status, CoreMatchers.`is`(PrefsStatus.OK)) - Assert.assertThat(prefs.metadata[PrefsMetadataKey.FILE_FORMAT]?.value, CoreMatchers.`is`(EncryptedPrefsFormat.FORMAT_KEY_ENC)) - Assert.assertThat(prefs.metadata[PrefsMetadataKey.ENCRYPTION]?.status, CoreMatchers.`is`(PrefsStatus.ERROR)) + Assert.assertEquals(prefs.metadata[PrefsMetadataKey.FILE_FORMAT]?.status, PrefsStatus.OK) + Assert.assertEquals(prefs.metadata[PrefsMetadataKey.FILE_FORMAT]?.value, EncryptedPrefsFormat.FORMAT_KEY_ENC) + Assert.assertEquals(prefs.metadata[PrefsMetadataKey.ENCRYPTION]?.status, PrefsStatus.ERROR) } @Test @@ -158,10 +169,10 @@ class EncryptedPrefsFormatTest : TestBase() { assumeAES256isSupported(cryptoUtil) // contents were not tampered and we can decrypt them - Assert.assertThat(prefs.values.size, CoreMatchers.`is`(2)) + Assert.assertEquals(prefs.values.size, 2) // but checksum fails on metadata, so overall security fails - Assert.assertThat(prefs.metadata[PrefsMetadataKey.ENCRYPTION]?.status, CoreMatchers.`is`(PrefsStatus.ERROR)) + Assert.assertEquals(prefs.metadata[PrefsMetadataKey.ENCRYPTION]?.status, PrefsStatus.ERROR) } @Test @@ -182,8 +193,8 @@ class EncryptedPrefsFormatTest : TestBase() { val encryptedFormat = EncryptedPrefsFormat(resourceHelper, cryptoUtil, storage) val prefs = encryptedFormat.loadPreferences(getMockedFile(), "sikret") - Assert.assertThat(prefs.values.size, CoreMatchers.`is`(0)) - Assert.assertThat(prefs.metadata[PrefsMetadataKey.ENCRYPTION]?.status, CoreMatchers.`is`(PrefsStatus.ERROR)) + Assert.assertEquals(prefs.values.size, 0) + Assert.assertEquals(prefs.metadata[PrefsMetadataKey.ENCRYPTION]?.status, PrefsStatus.ERROR) } @Test @@ -197,8 +208,8 @@ class EncryptedPrefsFormatTest : TestBase() { val encryptedFormat = EncryptedPrefsFormat(resourceHelper, cryptoUtil, storage) val prefs = encryptedFormat.loadPreferences(getMockedFile(), "sikret") - Assert.assertThat(prefs.values.size, CoreMatchers.`is`(0)) - Assert.assertThat(prefs.metadata[PrefsMetadataKey.FILE_FORMAT]?.status, CoreMatchers.`is`(PrefsStatus.ERROR)) + Assert.assertEquals(prefs.values.size, 0) + Assert.assertEquals(prefs.metadata[PrefsMetadataKey.FILE_FORMAT]?.status, PrefsStatus.ERROR) } @Test(expected = PrefFormatError::class) diff --git a/core/build.gradle b/core/build.gradle index a539c9528d..20f8c6e5e6 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -46,17 +46,6 @@ android { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } - testOptions { - unitTests { - returnDefaultValues = true - includeAndroidResources = true - - all { - maxParallelForks = 10 - forkEvery = 20 - } - } - } } @@ -64,4 +53,5 @@ dependencies { implementation project(':database') } -apply from: 'core_dependencies.gradle' \ No newline at end of file +apply from: 'core_dependencies.gradle' +apply from: "${project.rootDir}/gradle/test_dependencies.gradle" \ No newline at end of file diff --git a/core/core_dependencies.gradle b/core/core_dependencies.gradle index dbbb926ca6..cf40da5288 100644 --- a/core/core_dependencies.gradle +++ b/core/core_dependencies.gradle @@ -107,14 +107,4 @@ dependencies { // Phone checker api 'com.scottyab:rootbeer-lib:0.0.8' - - testImplementation "junit:junit:$junit_version" - testImplementation "org.mockito:mockito-core:${mockitoVersion}" - testImplementation "org.powermock:powermock-api-mockito2:${powermockVersion}" - testImplementation "org.powermock:powermock-module-junit4-rule-agent:${powermockVersion}" - testImplementation "org.powermock:powermock-module-junit4-rule:${powermockVersion}" - testImplementation "org.powermock:powermock-module-junit4:${powermockVersion}" - androidTestImplementation "androidx.test.ext:junit:$androidx_junit" - androidTestImplementation "androidx.test:rules:$androidx_rules" - testImplementation 'org.json:json:20201115' // Needed for JsonHelperTest } \ No newline at end of file diff --git a/dana/build.gradle b/dana/build.gradle index 7339a7d833..0c70d57791 100644 --- a/dana/build.gradle +++ b/dana/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' +apply plugin: 'com.hiya.jacoco-android' android { compileSdkVersion 28 @@ -49,8 +50,6 @@ dependencies { annotationProcessor "com.google.dagger:dagger-android-processor:$dagger_version" kapt "com.google.dagger:dagger-android-processor:$dagger_version" kapt "com.google.dagger:dagger-compiler:$dagger_version" - - testImplementation "junit:junit:$junit_version" - androidTestImplementation "androidx.test.ext:junit:$androidx_junit" - androidTestImplementation "androidx.test:rules:$androidx_rules" } + +apply from: "${project.rootDir}/gradle/test_dependencies.gradle" diff --git a/danar/build.gradle b/danar/build.gradle index cc8e1bce41..2ef2c3a88c 100644 --- a/danar/build.gradle +++ b/danar/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' +apply plugin: 'com.hiya.jacoco-android' android { compileSdkVersion 28 @@ -51,8 +52,6 @@ dependencies { annotationProcessor "com.google.dagger:dagger-android-processor:$dagger_version" kapt "com.google.dagger:dagger-android-processor:$dagger_version" kapt "com.google.dagger:dagger-compiler:$dagger_version" - - testImplementation "junit:junit:$junit_version" - androidTestImplementation "androidx.test.ext:junit:$androidx_junit" - androidTestImplementation "androidx.test:rules:$androidx_rules" } + +apply from: "${project.rootDir}/gradle/test_dependencies.gradle" diff --git a/danars/build.gradle b/danars/build.gradle index 8b407ce390..30ee674f9f 100644 --- a/danars/build.gradle +++ b/danars/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' +apply plugin: 'com.hiya.jacoco-android' android { compileSdkVersion 28 @@ -52,9 +53,6 @@ dependencies { annotationProcessor "com.google.dagger:dagger-android-processor:$dagger_version" kapt "com.google.dagger:dagger-android-processor:$dagger_version" kapt "com.google.dagger:dagger-compiler:$dagger_version" - - testImplementation "junit:junit:$junit_version" - androidTestImplementation "androidx.test.ext:junit:$androidx_junit" - androidTestImplementation "androidx.test:rules:$androidx_rules" } +apply from: "${project.rootDir}/gradle/test_dependencies.gradle" diff --git a/gradle/android_dependencies.gradle b/gradle/android_dependencies.gradle new file mode 100644 index 0000000000..e69de29bb2 diff --git a/gradle/test_dependencies.gradle b/gradle/test_dependencies.gradle new file mode 100644 index 0000000000..3a484c419c --- /dev/null +++ b/gradle/test_dependencies.gradle @@ -0,0 +1,35 @@ +dependencies { + testImplementation "junit:junit:$junit_version" + testImplementation 'org.json:json:20201115' + testImplementation "org.mockito:mockito-core:${mockitoVersion}" + testImplementation "org.powermock:powermock-api-mockito2:${powermockVersion}" + testImplementation "org.powermock:powermock-module-junit4-rule-agent:${powermockVersion}" + testImplementation "org.powermock:powermock-module-junit4-rule:${powermockVersion}" + testImplementation "org.powermock:powermock-module-junit4:${powermockVersion}" + testImplementation "joda-time:joda-time:$jodatime_version" + testImplementation('com.google.truth:truth:1.1.2') { + exclude group: "com.google.guava", module: "guava" + } + testImplementation "org.skyscreamer:jsonassert:1.5.0" + testImplementation "org.hamcrest:hamcrest-all:1.3" + + androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0-alpha04' + androidTestImplementation "androidx.test.ext:junit:$androidx_junit" + androidTestImplementation "androidx.test:rules:$androidx_rules" + + androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0' +} + +android { + testOptions { + unitTests { + returnDefaultValues = true + includeAndroidResources = true + + all { + maxParallelForks = 10 + forkEvery = 20 + } + } + } +} \ No newline at end of file From 738964faef63ef7806106d821d757c0a00095417 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 18 Feb 2021 20:45:32 +0100 Subject: [PATCH 16/28] move RS tests --- .gitignore | 2 +- .../androidaps/TestBaseWithProfile.kt | 21 ++--- .../androidaps/dana/ExampleUnitTest.kt | 18 ---- danars/build.gradle | 8 +- .../info/nightscout/androidaps/TestBase.kt | 40 +++++++++ .../androidaps/TestBaseWithProfile.kt | 82 +++++++++++++++++++ .../androidaps/danars}/DanaRSPluginTest.kt | 11 ++- .../androidaps/danars}/DanaRSTestBase.kt | 8 +- .../DanaRSPacketBasalSetTemporaryBasalTest.kt | 3 +- .../comm/DanaRSPacketHistoryAlarmTest.kt | 6 +- .../DanaRSPacketNotifyDeliveryCompleteTest.kt | 6 +- .../DanaRSPacketOptionSetUserOptionTest.kt | 3 +- .../androidaps/danars/comm/DanaRSTestBase.kt | 2 + .../danars/comm/DanaRsMessageHashTableTest.kt | 5 +- ...naRsPacketApsBasalSetTemporaryBasalTest.kt | 6 +- .../comm/DanaRsPacketApsHistoryEventsTest.kt | 5 +- .../DanaRsPacketApsSetEventHistoryTest.kt | 25 +++--- .../comm/DanaRsPacketBasalGetBasalRateTest.kt | 5 +- ...anaRsPacketBasalGetProfileBasalRateTest.kt | 3 +- .../DanaRsPacketBasalGetProfileNumberTest.kt | 5 +- ...RsPacketBasalGetTemporaryBasalStateTest.kt | 5 +- .../comm/DanaRsPacketBasalSetBasalRateTest.kt | 5 +- ...sPacketBasalSetCancelTemporaryBasalTest.kt | 5 +- ...anaRsPacketBasalSetProfileBasalRateTest.kt | 11 ++- .../DanaRsPacketBasalSetProfileNumberTest.kt | 9 +- .../DanaRsPacketBasalSetSuspendOffTest.kt | 5 +- .../comm/DanaRsPacketBasalSetSuspendOnTest.kt | 5 +- .../DanaRsPacketBolusGetBolusOptionTest.kt | 3 +- ...acketBolusGetCalculationInformationTest.kt | 5 +- ...tCarbohydrateCalculationInformationTest.kt | 5 +- .../DanaRsPacketBolusGetCirCfArrayTest.kt | 3 +- .../comm/DanaRsPacketBolusGetDualBolusTest.kt | 3 +- ...aRsPacketBolusGetExtendedBolusStateTest.kt | 9 +- .../DanaRsPacketBolusGetExtendedBolusTest.kt | 11 ++- ...cketBolusGetExtendedMenuOptionStateTest.kt | 5 +- .../DanaRsPacketBolusGetInitialBolusTest.kt | 5 +- ...sPacketBolusGetStepBolusInformationTest.kt | 12 +-- .../DanaRsPacketBolusSetBolusOptionTest.kt | 9 +- .../DanaRsPacketBolusSetCirCfArrayTest.kt | 9 +- .../comm/DanaRsPacketBolusSetDualBolusTest.kt | 9 +- ...RsPacketBolusSetExtendedBolusCancelTest.kt | 3 +- .../DanaRsPacketBolusSetExtendedBolusTest.kt | 3 +- .../DanaRsPacketBolusSetInitialBolusTest.kt | 9 +- .../DanaRsPacketBolusSetStepBolusStartTest.kt | 9 +- .../DanaRsPacketBolusSetStepBolusStopTest.kt | 5 +- .../comm/DanaRsPacketEtcKeepConnectionTest.kt | 3 +- .../comm/DanaRsPacketEtcSetHistorySaveTest.kt | 11 ++- .../DanaRsPacketGeneralDeliveryStatusTest.kt | 5 +- ...naRsPacketGeneralGetMoreInformationTest.kt | 12 +-- .../DanaRsPacketGeneralGetPasswordTest.kt | 3 +- .../DanaRsPacketGeneralGetPumpCheckTest.kt | 3 +- ...PacketGeneralGetShippingInformationTest.kt | 3 +- ...naRsPacketGeneralGetShippingVerisonTest.kt | 3 +- ...sPacketGeneralGetTodayDeliveryTotalTest.kt | 3 +- ...sPacketGeneralGetUserTimeChangeFlagTest.kt | 3 +- ...cketGeneralInitialScreenInformationTest.kt | 3 +- ...RsPacketGeneralSetHistoryUploadModeTest.kt | 3 +- ...etGeneralSetUserTimeChangeFlagClearTest.kt | 3 +- .../comm/DanaRsPacketHistoryAllHistoryTest.kt | 3 +- .../comm/DanaRsPacketHistoryBasalTest.kt | 3 +- .../DanaRsPacketHistoryBloodGlucoseTest.kt | 3 +- .../comm/DanaRsPacketHistoryBolusTest.kt | 3 +- .../DanaRsPacketHistoryCarbohydrateTest.kt | 3 +- .../comm/DanaRsPacketHistoryDailyTest.kt | 3 +- .../comm/DanaRsPacketHistoryPrimeTest.kt | 3 +- .../comm/DanaRsPacketHistoryRefillTest.kt | 3 +- .../comm/DanaRsPacketHistorySuspendTest.kt | 3 +- .../comm/DanaRsPacketHistoryTemporaryTest.kt | 3 +- .../comm/DanaRsPacketNotifyAlarmTest.kt | 14 +--- ...naRsPacketNotifyDeliveryRateDisplayTest.kt | 6 +- .../DanaRsPacketNotifyMissedBolusAlarmTest.kt | 3 +- .../comm/DanaRsPacketOptionGetPumpTimeTest.kt | 3 +- .../DanaRsPacketOptionGetUserOptionTest.kt | 3 +- .../comm/DanaRsPacketOptionSetPumpTimeTest.kt | 23 +++--- .../comm/DanaRsPacketReviewBolusAvgTest.kt | 5 +- .../DanaRsPacketReviewGetPumpDecRatioTest.kt | 3 +- 76 files changed, 355 insertions(+), 219 deletions(-) delete mode 100644 dana/src/test/java/info/nightscout/androidaps/dana/ExampleUnitTest.kt create mode 100644 danars/src/test/java/info/nightscout/androidaps/TestBase.kt create mode 100644 danars/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt rename {app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS => danars/src/test/java/info/nightscout/androidaps/danars}/DanaRSPluginTest.kt (84%) rename {app/src/test/java/info/nightscout/androidaps/danars/comm => danars/src/test/java/info/nightscout/androidaps/danars}/DanaRSTestBase.kt (90%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Basal_Set_Temporary_BasalTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRSPacketBasalSetTemporaryBasalTest.kt (91%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_History_AlarmTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRSPacketHistoryAlarmTest.kt (87%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Notify_Delivery_CompleteTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRSPacketNotifyDeliveryCompleteTest.kt (94%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Option_Set_User_OptionTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRSPacketOptionSetUserOptionTest.kt (90%) create mode 100644 danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRSTestBase.kt rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRSMessageHashTableTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsMessageHashTableTest.kt (95%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_APS_Basal_Set_Temporary_BasalTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketApsBasalSetTemporaryBasalTest.kt (94%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_APS_History_EventsTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketApsHistoryEventsTest.kt (96%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_APS_Set_Event_HistoryTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketApsSetEventHistoryTest.kt (73%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Basal_Get_Basal_RateTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBasalGetBasalRateTest.kt (87%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Basal_Get_Profile_Basal_RateTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBasalGetProfileBasalRateTest.kt (94%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Basal_Get_Profile_NumberTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBasalGetProfileNumberTest.kt (85%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Basal_Get_Temporary_Basal_StateTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBasalGetTemporaryBasalStateTest.kt (89%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Basal_Set_Basal_RateTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBasalSetBasalRateTest.kt (89%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Basal_Set_Cancel_Temporary_BasalTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBasalSetCancelTemporaryBasalTest.kt (85%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Basal_Set_Profile_Basal_RateTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBasalSetProfileBasalRateTest.kt (77%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Basal_Set_Profile_NumberTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBasalSetProfileNumberTest.kt (80%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Basal_Set_Suspend_OffTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBasalSetSuspendOffTest.kt (86%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Basal_Set_Suspend_OnTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBasalSetSuspendOnTest.kt (86%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Get_Bolus_OptionTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetBolusOptionTest.kt (93%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Get_Calculation_InformationTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetCalculationInformationTest.kt (86%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_InformationTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetCarbohydrateCalculationInformationTest.kt (86%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Get_CIR_CF_ArrayTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetCirCfArrayTest.kt (91%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Get_Dual_BolusTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetDualBolusTest.kt (91%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus_StateTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetExtendedBolusStateTest.kt (79%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Get_Extended_BolusTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetExtendedBolusTest.kt (77%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Get_Extended_Menu_Option_StateTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetExtendedMenuOptionStateTest.kt (86%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Get_Initial_BolusTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetInitialBolusTest.kt (84%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_InformationTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetStepBolusInformationTest.kt (82%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Set_Bolus_OptionTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusSetBolusOptionTest.kt (81%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Set_CIR_CF_ArrayTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusSetCirCfArrayTest.kt (81%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Set_Dual_BolusTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusSetDualBolusTest.kt (81%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus_CancelTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusSetExtendedBolusCancelTest.kt (88%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Set_Extended_BolusTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusSetExtendedBolusTest.kt (91%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Set_Initial_BolusTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusSetInitialBolusTest.kt (77%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StartTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusSetStepBolusStartTest.kt (89%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StopTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusSetStepBolusStopTest.kt (94%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Etc_Keep_ConnectionTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketEtcKeepConnectionTest.kt (90%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Etc_Set_History_SaveTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketEtcSetHistorySaveTest.kt (75%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_General_Delivery_StatusTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketGeneralDeliveryStatusTest.kt (86%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_General_Get_More_InformationTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketGeneralGetMoreInformationTest.kt (81%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_General_Get_PasswordTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketGeneralGetPasswordTest.kt (90%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_General_Get_Pump_CheckTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketGeneralGetPumpCheckTest.kt (92%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_General_Get_Shipping_InformationTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketGeneralGetShippingInformationTest.kt (90%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_General_Get_Shipping_VerisonTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketGeneralGetShippingVerisonTest.kt (89%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_General_Get_Today_Delivery_TotalTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketGeneralGetTodayDeliveryTotalTest.kt (91%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_General_Get_User_Time_Change_FlagTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketGeneralGetUserTimeChangeFlagTest.kt (89%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_General_Initial_Screen_InformationTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketGeneralInitialScreenInformationTest.kt (90%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_General_Set_History_Upload_ModeTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketGeneralSetHistoryUploadModeTest.kt (89%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_General_Set_User_Time_Change_Flag_ClearTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketGeneralSetUserTimeChangeFlagClearTest.kt (89%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_History_All_HistoryTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketHistoryAllHistoryTest.kt (87%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_History_BasalTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketHistoryBasalTest.kt (87%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_History_Blood_GlucoseTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketHistoryBloodGlucoseTest.kt (87%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_History_BolusTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketHistoryBolusTest.kt (87%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_History_CarbohydrateTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketHistoryCarbohydrateTest.kt (87%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_History_DailyTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketHistoryDailyTest.kt (87%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_History_PrimeTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketHistoryPrimeTest.kt (87%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_History_RefillTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketHistoryRefillTest.kt (87%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_History_SuspendTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketHistorySuspendTest.kt (87%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_History_TemporaryTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketHistoryTemporaryTest.kt (87%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Notify_AlarmTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketNotifyAlarmTest.kt (75%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Notify_Delivery_Rate_DisplayTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketNotifyDeliveryRateDisplayTest.kt (87%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Notify_Missed_Bolus_AlarmTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketNotifyMissedBolusAlarmTest.kt (89%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Option_Get_Pump_TimeTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketOptionGetPumpTimeTest.kt (91%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Option_Get_User_OptionTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketOptionGetUserOptionTest.kt (90%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Option_Set_Pump_TimeTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketOptionSetPumpTimeTest.kt (60%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Review_Bolus_AvgTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketReviewBolusAvgTest.kt (87%) rename app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Review_Get_Pump_Dec_RatioTest.kt => danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketReviewGetPumpDecRatioTest.kt (88%) diff --git a/.gitignore b/.gitignore index affd38763c..74eb164a98 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ .gradle /local.properties .DS_Store -app/jacoco.exec +*/jacoco.exec /build /captures *.apk diff --git a/app/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt b/app/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt index 990a4f5b0a..10ffa5c70f 100644 --- a/app/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt +++ b/app/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt @@ -3,19 +3,18 @@ package info.nightscout.androidaps import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector import info.nightscout.androidaps.data.Profile -import info.nightscout.androidaps.interfaces.ProfileStore import info.nightscout.androidaps.db.ProfileSwitch -import info.nightscout.androidaps.interfaces.ActivePluginProvider -import info.nightscout.androidaps.plugins.bus.RxBusWrapper -import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.db.Treatment -import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin +import info.nightscout.androidaps.interfaces.ActivePluginProvider +import info.nightscout.androidaps.interfaces.ConfigInterface +import info.nightscout.androidaps.interfaces.ProfileFunction +import info.nightscout.androidaps.interfaces.ProfileStore +import info.nightscout.androidaps.interfaces.TreatmentsInterface +import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.DefaultValueHelper import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.resources.ResourceHelper -import info.nightscout.androidaps.utils.rx.AapsSchedulers -import info.nightscout.androidaps.utils.rx.TestAapsSchedulers import org.json.JSONObject import org.junit.Before import org.mockito.Mock @@ -23,13 +22,15 @@ import org.powermock.core.classloader.annotations.PrepareForTest @PrepareForTest(FabricPrivacy::class) open class TestBaseWithProfile : TestBase() { + @Mock lateinit var activePluginProvider: ActivePluginProvider @Mock lateinit var resourceHelper: ResourceHelper - @Mock lateinit var treatmentsPlugin: TreatmentsPlugin + @Mock lateinit var treatmentsPlugin: TreatmentsInterface @Mock lateinit var fabricPrivacy: FabricPrivacy @Mock lateinit var profileFunction: ProfileFunction @Mock lateinit var defaultValueHelper: DefaultValueHelper @Mock lateinit var dateUtil: DateUtil + @Mock lateinit var configInterface: ConfigInterface val rxBus = RxBusWrapper(aapsSchedulers) @@ -41,7 +42,7 @@ open class TestBaseWithProfile : TestBase() { it.resourceHelper = resourceHelper it.rxBus = rxBus it.fabricPrivacy = fabricPrivacy - it.configInterface = Config() + it.configInterface = configInterface } if (it is ProfileSwitch) { it.treatmentsPlugin = treatmentsPlugin @@ -61,7 +62,7 @@ open class TestBaseWithProfile : TestBase() { private lateinit var validProfileJSON: String lateinit var validProfile: Profile - val TESTPROFILENAME = "someProfile" + @Suppress("PropertyName") val TESTPROFILENAME = "someProfile" @Before fun prepareMock() { diff --git a/dana/src/test/java/info/nightscout/androidaps/dana/ExampleUnitTest.kt b/dana/src/test/java/info/nightscout/androidaps/dana/ExampleUnitTest.kt deleted file mode 100644 index a85dae0d49..0000000000 --- a/dana/src/test/java/info/nightscout/androidaps/dana/ExampleUnitTest.kt +++ /dev/null @@ -1,18 +0,0 @@ -package info.nightscout.androidaps.dana - -import org.junit.Test - -import org.junit.Assert.* - -/** - * Example local unit test, which will execute on the development machine (host). - * - * See [testing documentation](http://d.android.com/tools/testing). - */ -class ExampleUnitTest { - - @Test - fun addition_isCorrect() { - assertEquals(4, 2 + 2) - } -} diff --git a/danars/build.gradle b/danars/build.gradle index 30ee674f9f..a7c5ac60d6 100644 --- a/danars/build.gradle +++ b/danars/build.gradle @@ -7,7 +7,7 @@ android { compileSdkVersion 28 defaultConfig { - minSdkVersion 24 + minSdkVersion 26 targetSdkVersion 28 versionCode 1 versionName "1.0" @@ -35,6 +35,12 @@ android { ext.enableCrashlytics = false } } + flavorDimensions "standard" + productFlavors { + full { + dimension "standard" + } + } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 diff --git a/danars/src/test/java/info/nightscout/androidaps/TestBase.kt b/danars/src/test/java/info/nightscout/androidaps/TestBase.kt new file mode 100644 index 0000000000..573c9dcbcc --- /dev/null +++ b/danars/src/test/java/info/nightscout/androidaps/TestBase.kt @@ -0,0 +1,40 @@ +package info.nightscout.androidaps + +import info.nightscout.androidaps.logging.AAPSLoggerTest +import info.nightscout.androidaps.utils.rx.AapsSchedulers +import info.nightscout.androidaps.utils.rx.TestAapsSchedulers +import org.junit.Before +import org.junit.Rule +import org.mockito.Mockito +import org.mockito.junit.MockitoJUnit +import org.mockito.junit.MockitoRule +import java.util.* + +@Suppress("SpellCheckingInspection") +open class TestBase { + + val aapsLogger = AAPSLoggerTest() + val aapsSchedulers: AapsSchedulers = TestAapsSchedulers() + + // Add a JUnit rule that will setup the @Mock annotated vars and log. + // Another possibility would be to add `MockitoAnnotations.initMocks(this) to the setup method. + @get:Rule + val mockitoRule: MockitoRule = MockitoJUnit.rule() + + @Before + fun setupLocale() { + Locale.setDefault(Locale.ENGLISH) + System.setProperty("disableFirebase", "true") + } + + // Workaround for Kotlin nullability. + // https://medium.com/@elye.project/befriending-kotlin-and-mockito-1c2e7b0ef791 + // https://stackoverflow.com/questions/30305217/is-it-possible-to-use-mockito-in-kotlin + fun anyObject(): T { + Mockito.any() + return uninitialized() + } + + @Suppress("Unchecked_Cast") + fun uninitialized(): T = null as T +} \ 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 new file mode 100644 index 0000000000..e23ced876d --- /dev/null +++ b/danars/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt @@ -0,0 +1,82 @@ +package info.nightscout.androidaps + +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.data.Profile +import info.nightscout.androidaps.db.ProfileSwitch +import info.nightscout.androidaps.db.Treatment +import info.nightscout.androidaps.interfaces.ActivePluginProvider +import info.nightscout.androidaps.interfaces.ConfigInterface +import info.nightscout.androidaps.interfaces.ProfileFunction +import info.nightscout.androidaps.interfaces.ProfileStore +import info.nightscout.androidaps.interfaces.TreatmentsInterface +import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.utils.DateUtil +import info.nightscout.androidaps.utils.DefaultValueHelper +import info.nightscout.androidaps.utils.FabricPrivacy +import info.nightscout.androidaps.utils.resources.ResourceHelper +import org.json.JSONObject +import org.junit.Before +import org.mockito.Mock +import org.powermock.core.classloader.annotations.PrepareForTest + +@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 fabricPrivacy: FabricPrivacy + @Mock lateinit var profileFunction: ProfileFunction + @Mock lateinit var defaultValueHelper: DefaultValueHelper + @Mock lateinit var dateUtil: DateUtil + @Mock lateinit var configInterface: ConfigInterface + + val rxBus = RxBusWrapper(aapsSchedulers) + + private val profileInjector = HasAndroidInjector { + AndroidInjector { + if (it is Profile) { + it.aapsLogger = aapsLogger + it.activePlugin = activePluginProvider + it.resourceHelper = resourceHelper + it.rxBus = rxBus + it.fabricPrivacy = fabricPrivacy + it.configInterface = configInterface + } + if (it is ProfileSwitch) { + it.treatmentsPlugin = treatmentsPlugin + it.aapsLogger = aapsLogger + it.rxBus = rxBus + it.resourceHelper = resourceHelper + it.dateUtil = dateUtil + } + if (it is Treatment) { + it.activePlugin = activePluginProvider + it.profileFunction = profileFunction + it.defaultValueHelper = defaultValueHelper + it.resourceHelper = resourceHelper + } + } + } + + private lateinit var validProfileJSON: String + lateinit var validProfile: Profile + private 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) + } + + fun getValidProfileStore(): ProfileStore { + val json = JSONObject() + val store = JSONObject() + store.put(testProfileName, JSONObject(validProfileJSON)) + json.put("defaultProfile", testProfileName) + json.put("store", store) + return ProfileStore(profileInjector, json) + } +} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPluginTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/DanaRSPluginTest.kt similarity index 84% rename from app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPluginTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/DanaRSPluginTest.kt index eee474f841..70863cdf8d 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPluginTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/DanaRSPluginTest.kt @@ -1,13 +1,11 @@ -package info.nightscout.androidaps.plugins.pump.danaRS +package info.nightscout.androidaps.plugins.pump.danars import android.content.Context import dagger.android.AndroidInjector -import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.Config import info.nightscout.androidaps.Constants -import info.nightscout.androidaps.R import info.nightscout.androidaps.danars.DanaRSPlugin -import info.nightscout.androidaps.danars.comm.DanaRSTestBase +import info.nightscout.androidaps.danars.DanaRSTestBase +import info.nightscout.androidaps.danars.R import info.nightscout.androidaps.interfaces.CommandQueueProvider import info.nightscout.androidaps.interfaces.Constraint import info.nightscout.androidaps.interfaces.PluginType @@ -24,6 +22,7 @@ import org.mockito.Mockito import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner +@Suppress("SpellCheckingInspection") @RunWith(PowerMockRunner::class) @PrepareForTest(ConstraintChecker::class, RxBusWrapper::class, DetailedBolusInfoStorage::class) class DanaRSPluginTest : DanaRSTestBase() { @@ -65,6 +64,6 @@ class DanaRSPluginTest : DanaRSTestBase() { Mockito.`when`(resourceHelper.gs(eq(R.string.limitingbasalratio), anyObject(), anyObject())).thenReturn("limitingbasalratio") Mockito.`when`(resourceHelper.gs(eq(R.string.limitingpercentrate), anyObject(), anyObject())).thenReturn("limitingpercentrate") - danaRSPlugin = DanaRSPlugin(HasAndroidInjector { AndroidInjector { Unit } }, aapsLogger, aapsSchedulers, rxBus, context, resourceHelper, constraintChecker, profileFunction, activePluginProvider, sp, commandQueue, danaPump, detailedBolusInfoStorage, fabricPrivacy, dateUtil) + danaRSPlugin = DanaRSPlugin({ AndroidInjector { } }, aapsLogger, aapsSchedulers, rxBus, context, resourceHelper, constraintChecker, profileFunction, activePluginProvider, sp, commandQueue, danaPump, detailedBolusInfoStorage, fabricPrivacy, dateUtil) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRSTestBase.kt b/danars/src/test/java/info/nightscout/androidaps/danars/DanaRSTestBase.kt similarity index 90% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRSTestBase.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/DanaRSTestBase.kt index ed97c24a55..7984a885a4 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRSTestBase.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/DanaRSTestBase.kt @@ -1,10 +1,11 @@ -package info.nightscout.androidaps.danars.comm +package info.nightscout.androidaps.danars import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector import info.nightscout.androidaps.TestBaseWithProfile -import info.nightscout.androidaps.db.TemporaryBasal import info.nightscout.androidaps.dana.DanaPump +import info.nightscout.androidaps.danars.comm.DanaRS_Packet +import info.nightscout.androidaps.db.TemporaryBasal import info.nightscout.androidaps.utils.sharedPreferences.SP import org.junit.Before import org.mockito.Mock @@ -42,6 +43,7 @@ open class DanaRSTestBase : TestBaseWithProfile() { return ret } + @Suppress("unused") fun putIntToArray(array: ByteArray, position: Int, value: Int): ByteArray { array[DanaRS_Packet.DATA_START + position] = (value and 0xFF).toByte() array[DanaRS_Packet.DATA_START + position + 1] = ((value and 0xFF00) shr 8).toByte() @@ -55,6 +57,6 @@ open class DanaRSTestBase : TestBaseWithProfile() { @Before fun setup() { - danaPump = info.nightscout.androidaps.dana.DanaPump(aapsLogger, sp, injector) + danaPump = DanaPump(aapsLogger, sp, injector) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Basal_Set_Temporary_BasalTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRSPacketBasalSetTemporaryBasalTest.kt similarity index 91% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Basal_Set_Temporary_BasalTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRSPacketBasalSetTemporaryBasalTest.kt index 841f2b8a24..4932678f8b 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Basal_Set_Temporary_BasalTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRSPacketBasalSetTemporaryBasalTest.kt @@ -2,13 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -class DanaRS_Packet_Basal_Set_Temporary_BasalTest : DanaRSTestBase() { +class DanaRSPacketBasalSetTemporaryBasalTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_History_AlarmTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRSPacketHistoryAlarmTest.kt similarity index 87% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_History_AlarmTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRSPacketHistoryAlarmTest.kt index 3f4c681beb..7d861f35cd 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_History_AlarmTest.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.danars.DanaRSTestBase import info.nightscout.androidaps.interfaces.DatabaseHelperInterface import info.nightscout.androidaps.plugins.general.nsclient.NSUpload import org.junit.Assert @@ -12,7 +13,7 @@ import org.powermock.modules.junit4.PowerMockRunner import java.util.* @RunWith(PowerMockRunner::class) -class DanaRS_Packet_History_AlarmTest : DanaRSTestBase() { +class DanaRSPacketHistoryAlarmTest : DanaRSTestBase() { @Mock lateinit var databaseHelper: DatabaseHelperInterface @Mock lateinit var nsUpload: NSUpload @@ -48,7 +49,8 @@ class DanaRS_Packet_History_AlarmTest : DanaRSTestBase() { packet.handleMessage(array) Assert.assertEquals(info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_ALARM, packet.danaRHistoryRecord.recordCode) - Assert.assertEquals(Date(119, 1, 4, 20, 11, 35).time, packet.danaRHistoryRecord.recordDate) + val date = Calendar.getInstance().also { it.set(2019, 2, 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) Assert.assertEquals("REVIEW__ALARM", packet.friendlyName) diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Notify_Delivery_CompleteTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRSPacketNotifyDeliveryCompleteTest.kt similarity index 94% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Notify_Delivery_CompleteTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRSPacketNotifyDeliveryCompleteTest.kt index 6028dd0941..3ded5b81cd 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Notify_Delivery_CompleteTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRSPacketNotifyDeliveryCompleteTest.kt @@ -2,10 +2,11 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSPlugin +import info.nightscout.androidaps.danars.DanaRSTestBase import info.nightscout.androidaps.db.Treatment import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.plugins.bus.RxBusWrapper -import info.nightscout.androidaps.danars.DanaRSPlugin import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith @@ -18,9 +19,8 @@ import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) @PrepareForTest(RxBusWrapper::class, DanaRSPlugin::class) -class DanaRS_Packet_Notify_Delivery_CompleteTest : DanaRSTestBase() { +class DanaRSPacketNotifyDeliveryCompleteTest : DanaRSTestBase() { - @Mock lateinit var danaRSPlugin: DanaRSPlugin @Mock lateinit var activePlugin: ActivePluginProvider private val packetInjector = HasAndroidInjector { diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Option_Set_User_OptionTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRSPacketOptionSetUserOptionTest.kt similarity index 90% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Option_Set_User_OptionTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRSPacketOptionSetUserOptionTest.kt index 043fd13178..dfea5dee2f 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Option_Set_User_OptionTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRSPacketOptionSetUserOptionTest.kt @@ -2,13 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -class DanaRS_Packet_Option_Set_User_OptionTest : DanaRSTestBase() { +class DanaRSPacketOptionSetUserOptionTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { diff --git a/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRSTestBase.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRSTestBase.kt new file mode 100644 index 0000000000..fdc68962c3 --- /dev/null +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRSTestBase.kt @@ -0,0 +1,2 @@ +package info.nightscout.androidaps.danars.comm + diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRSMessageHashTableTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsMessageHashTableTest.kt similarity index 95% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRSMessageHashTableTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsMessageHashTableTest.kt index 193f303aa8..2397295ffa 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRSMessageHashTableTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsMessageHashTableTest.kt @@ -2,11 +2,12 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.encryption.BleEncryption import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.Constraint import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage -import info.nightscout.androidaps.danars.encryption.BleEncryption +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith @@ -17,7 +18,7 @@ import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) @PrepareForTest(ConstraintChecker::class, DetailedBolusInfoStorage::class) -class DanaRSMessageHashTableTest : DanaRSTestBase() { +class DanaRsMessageHashTableTest : DanaRSTestBase() { @Mock lateinit var activePlugin: ActivePluginProvider @Mock lateinit var constraintChecker: ConstraintChecker diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_APS_Basal_Set_Temporary_BasalTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketApsBasalSetTemporaryBasalTest.kt similarity index 94% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_APS_Basal_Set_Temporary_BasalTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketApsBasalSetTemporaryBasalTest.kt index ae09fe8315..d7c9afa3fd 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_APS_Basal_Set_Temporary_BasalTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketApsBasalSetTemporaryBasalTest.kt @@ -2,15 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() -class DanaRS_Packet_APS_Basal_Set_Temporary_BasalTest : DanaRSTestBase() { +class DanaRsPacketApsBasalSetTemporaryBasalTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { @@ -20,6 +19,7 @@ class DanaRS_Packet_APS_Basal_Set_Temporary_BasalTest : DanaRSTestBase() { } } + @ExperimentalUnsignedTypes @Test fun runTest() { // under 100% should last 30 min diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_APS_History_EventsTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketApsHistoryEventsTest.kt similarity index 96% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_APS_History_EventsTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketApsHistoryEventsTest.kt index fe42eb0305..cea0e79c1c 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_APS_History_EventsTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketApsHistoryEventsTest.kt @@ -3,10 +3,11 @@ package info.nightscout.androidaps.danars.comm import android.content.Context import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSPlugin import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage -import info.nightscout.androidaps.danars.DanaRSPlugin +import info.nightscout.androidaps.danars.DanaRSTestBase import info.nightscout.androidaps.utils.DateUtil import org.junit.Assert import org.junit.Test @@ -18,7 +19,7 @@ import java.util.* @RunWith(PowerMockRunner::class) @PrepareForTest(RxBusWrapper::class, DetailedBolusInfoStorage::class, DanaRSPlugin::class) -class DanaRS_Packet_APS_History_EventsTest : DanaRSTestBase() { +class DanaRsPacketApsHistoryEventsTest : DanaRSTestBase() { @Mock lateinit var context: Context @Mock lateinit var activePlugin: ActivePluginProvider diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_APS_Set_Event_HistoryTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketApsSetEventHistoryTest.kt similarity index 73% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_APS_Set_Event_HistoryTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketApsSetEventHistoryTest.kt index 2bbb735ac2..c62418d039 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_APS_Set_Event_HistoryTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketApsSetEventHistoryTest.kt @@ -2,16 +2,15 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import info.nightscout.androidaps.utils.DateUtil import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() -class DanaRS_Packet_APS_Set_Event_HistoryTest : DanaRSTestBase() { +class DanaRsPacketApsSetEventHistoryTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { @@ -28,22 +27,22 @@ class DanaRS_Packet_APS_Set_Event_HistoryTest : DanaRSTestBase() { @Test fun runTest() { // test for negative carbs val now = DateUtil.now() var historyTest = DanaRS_Packet_APS_Set_Event_History(packetInjector, info.nightscout.androidaps.dana.DanaPump.CARBS, now, -1, 0) - var testparams = historyTest.requestParams - Assert.assertEquals(0.toByte(), testparams[8]) + var testParams = historyTest.requestParams + Assert.assertEquals(0.toByte(), testParams[8]) // 5g carbs historyTest = DanaRS_Packet_APS_Set_Event_History(packetInjector, info.nightscout.androidaps.dana.DanaPump.CARBS, now, 5, 0) - testparams = historyTest.requestParams - Assert.assertEquals(5.toByte(), testparams[8]) + testParams = historyTest.requestParams + Assert.assertEquals(5.toByte(), testParams[8]) // 150g carbs historyTest = DanaRS_Packet_APS_Set_Event_History(packetInjector, info.nightscout.androidaps.dana.DanaPump.CARBS, now, 150, 0) - testparams = historyTest.requestParams - Assert.assertEquals(150.toByte(), testparams[8]) + testParams = historyTest.requestParams + Assert.assertEquals(150.toByte(), testParams[8]) // test message generation historyTest = DanaRS_Packet_APS_Set_Event_History(packetInjector, info.nightscout.androidaps.dana.DanaPump.CARBS, now, 5, 0) - testparams = historyTest.requestParams - Assert.assertEquals(5.toByte(), testparams[8]) - Assert.assertEquals(11, testparams.size) - Assert.assertEquals(info.nightscout.androidaps.dana.DanaPump.CARBS.toByte(), testparams[0]) + testParams = historyTest.requestParams + Assert.assertEquals(5.toByte(), testParams[8]) + Assert.assertEquals(11, testParams.size) + Assert.assertEquals(info.nightscout.androidaps.dana.DanaPump.CARBS.toByte(), testParams[0]) // test message decoding historyTest.handleMessage(byteArrayOf(0.toByte(), 0.toByte(), 0.toByte())) Assert.assertEquals(false, historyTest.failed) diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Basal_Get_Basal_RateTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBasalGetBasalRateTest.kt similarity index 87% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Basal_Get_Basal_RateTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBasalGetBasalRateTest.kt index 935ea4d015..938e716ba7 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Basal_Get_Basal_RateTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBasalGetBasalRateTest.kt @@ -3,6 +3,7 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith @@ -11,7 +12,7 @@ import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) @PrepareForTest(RxBusWrapper::class) -class DanaRS_Packet_Basal_Get_Basal_RateTest : DanaRSTestBase() { +class DanaRsPacketBasalGetBasalRateTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { @@ -30,7 +31,7 @@ class DanaRS_Packet_Basal_Get_Basal_RateTest : DanaRSTestBase() { // rate is 0.01 val array = ByteArray(100) putIntToArray(array, 0, (1.0 * 100).toInt()) - putByteToArray(array, 2, (0.05 * 100).toByte()) + putByteToArray(array, 2, (0.05 * 100).toInt().toByte()) packet.handleMessage(array) Assert.assertEquals(1.0, danaPump.maxBasal, 0.0) Assert.assertEquals(0.05, danaPump.basalStep, 0.0) diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Basal_Get_Profile_Basal_RateTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBasalGetProfileBasalRateTest.kt similarity index 94% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Basal_Get_Profile_Basal_RateTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBasalGetProfileBasalRateTest.kt index 2aa3293eaf..c1cfd49dcd 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Basal_Get_Profile_Basal_RateTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBasalGetProfileBasalRateTest.kt @@ -2,13 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert.assertEquals import org.junit.Test import org.junit.runner.RunWith import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -class DanaRS_Packet_Basal_Get_Profile_Basal_RateTest : DanaRSTestBase() { +class DanaRsPacketBasalGetProfileBasalRateTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Basal_Get_Profile_NumberTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBasalGetProfileNumberTest.kt similarity index 85% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Basal_Get_Profile_NumberTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBasalGetProfileNumberTest.kt index 8b430f9146..9847d2f75c 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Basal_Get_Profile_NumberTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBasalGetProfileNumberTest.kt @@ -2,15 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() -class DanaRS_Packet_Basal_Get_Profile_NumberTest : DanaRSTestBase() { +class DanaRsPacketBasalGetProfileNumberTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Basal_Get_Temporary_Basal_StateTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBasalGetTemporaryBasalStateTest.kt similarity index 89% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Basal_Get_Temporary_Basal_StateTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBasalGetTemporaryBasalStateTest.kt index 3ac8c367f1..86bf509924 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Basal_Get_Temporary_Basal_StateTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBasalGetTemporaryBasalStateTest.kt @@ -2,15 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() -class DanaRS_Packet_Basal_Get_Temporary_Basal_StateTest : DanaRSTestBase() { +class DanaRsPacketBasalGetTemporaryBasalStateTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Basal_Set_Basal_RateTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBasalSetBasalRateTest.kt similarity index 89% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Basal_Set_Basal_RateTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBasalSetBasalRateTest.kt index 84450ababc..765b2f462a 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Basal_Set_Basal_RateTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBasalSetBasalRateTest.kt @@ -2,15 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() -class DanaRS_Packet_Basal_Set_Basal_RateTest : DanaRSTestBase() { +class DanaRsPacketBasalSetBasalRateTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Basal_Set_Cancel_Temporary_BasalTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBasalSetCancelTemporaryBasalTest.kt similarity index 85% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Basal_Set_Cancel_Temporary_BasalTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBasalSetCancelTemporaryBasalTest.kt index 2cc549c533..442fed73cf 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Basal_Set_Cancel_Temporary_BasalTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBasalSetCancelTemporaryBasalTest.kt @@ -2,15 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() -class DanaRS_Packet_Basal_Set_Cancel_Temporary_BasalTest : DanaRSTestBase() { +class DanaRsPacketBasalSetCancelTemporaryBasalTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Basal_Set_Profile_Basal_RateTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBasalSetProfileBasalRateTest.kt similarity index 77% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Basal_Set_Profile_Basal_RateTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBasalSetProfileBasalRateTest.kt index fcf254887f..8c45544aa1 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Basal_Set_Profile_Basal_RateTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBasalSetProfileBasalRateTest.kt @@ -2,15 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() -class DanaRS_Packet_Basal_Set_Profile_Basal_RateTest : DanaRSTestBase() { +class DanaRsPacketBasalSetProfileBasalRateTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { @@ -23,11 +22,11 @@ class DanaRS_Packet_Basal_Set_Profile_Basal_RateTest : DanaRSTestBase() { @Test fun runTest() { val packet = DanaRS_Packet_Basal_Set_Profile_Basal_Rate(packetInjector, 1, createArray(24, 1.0)) // test params - val testparams = packet.requestParams + val testParams = packet.requestParams // is profile 1 - Assert.assertEquals(1.toByte(), testparams[0]) + Assert.assertEquals(1.toByte(), testParams[0]) // is value 100 - Assert.assertEquals(100.toByte(), testparams[3]) + Assert.assertEquals(100.toByte(), testParams[3]) // test message decoding packet.handleMessage(byteArrayOf(0.toByte(), 0.toByte(), 0.toByte())) Assert.assertEquals(false, packet.failed) diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Basal_Set_Profile_NumberTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBasalSetProfileNumberTest.kt similarity index 80% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Basal_Set_Profile_NumberTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBasalSetProfileNumberTest.kt index 2e7a720970..d7f1135fb7 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Basal_Set_Profile_NumberTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBasalSetProfileNumberTest.kt @@ -2,15 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() -class DanaRS_Packet_Basal_Set_Profile_NumberTest : DanaRSTestBase() { +class DanaRsPacketBasalSetProfileNumberTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { @@ -23,9 +22,9 @@ class DanaRS_Packet_Basal_Set_Profile_NumberTest : DanaRSTestBase() { @Test fun runTest() { val packet = DanaRS_Packet_Basal_Set_Profile_Number(packetInjector, 1) // test params - val testparams = packet.requestParams + val testParams = packet.requestParams // is profile 1 - Assert.assertEquals(1.toByte(), testparams[0]) + Assert.assertEquals(1.toByte(), testParams[0]) // test message decoding packet.handleMessage(byteArrayOf(0.toByte(), 0.toByte(), 0.toByte())) Assert.assertEquals(false, packet.failed) diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Basal_Set_Suspend_OffTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBasalSetSuspendOffTest.kt similarity index 86% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Basal_Set_Suspend_OffTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBasalSetSuspendOffTest.kt index 24abfb3538..2ebd63d093 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Basal_Set_Suspend_OffTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBasalSetSuspendOffTest.kt @@ -2,15 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() -class DanaRS_Packet_Basal_Set_Suspend_OffTest : DanaRSTestBase() { +class DanaRsPacketBasalSetSuspendOffTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Basal_Set_Suspend_OnTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBasalSetSuspendOnTest.kt similarity index 86% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Basal_Set_Suspend_OnTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBasalSetSuspendOnTest.kt index f0791ef578..7b31bbbd85 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Basal_Set_Suspend_OnTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBasalSetSuspendOnTest.kt @@ -2,15 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() -class DanaRS_Packet_Basal_Set_Suspend_OnTest : DanaRSTestBase() { +class DanaRsPacketBasalSetSuspendOnTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Get_Bolus_OptionTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetBolusOptionTest.kt similarity index 93% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Get_Bolus_OptionTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetBolusOptionTest.kt index b5de343b51..23ed112982 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Get_Bolus_OptionTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetBolusOptionTest.kt @@ -3,6 +3,7 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith @@ -11,7 +12,7 @@ import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) @PrepareForTest(RxBusWrapper::class) -class DanaRS_Packet_Bolus_Get_Bolus_OptionTest : DanaRSTestBase() { +class DanaRsPacketBolusGetBolusOptionTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Get_Calculation_InformationTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetCalculationInformationTest.kt similarity index 86% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Get_Calculation_InformationTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetCalculationInformationTest.kt index 1149a2fccf..a8b887ba45 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Get_Calculation_InformationTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetCalculationInformationTest.kt @@ -2,15 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() -class DanaRS_Packet_Bolus_Get_Calculation_InformationTest : DanaRSTestBase() { +class DanaRsPacketBolusGetCalculationInformationTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_InformationTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetCarbohydrateCalculationInformationTest.kt similarity index 86% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_InformationTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetCarbohydrateCalculationInformationTest.kt index fae26a11ae..9a5627c42c 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_InformationTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetCarbohydrateCalculationInformationTest.kt @@ -2,15 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() -class DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_InformationTest : DanaRSTestBase() { +class DanaRsPacketBolusGetCarbohydrateCalculationInformationTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Get_CIR_CF_ArrayTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetCirCfArrayTest.kt similarity index 91% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Get_CIR_CF_ArrayTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetCirCfArrayTest.kt index 04afc60cf6..b56e1a5426 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Get_CIR_CF_ArrayTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetCirCfArrayTest.kt @@ -3,13 +3,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector import info.nightscout.androidaps.dana.DanaPump +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -class DanaRS_Packet_Bolus_Get_CIR_CF_ArrayTest : DanaRSTestBase() { +class DanaRsPacketBolusGetCirCfArrayTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Get_Dual_BolusTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetDualBolusTest.kt similarity index 91% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Get_Dual_BolusTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetDualBolusTest.kt index 3af180017f..5f04609ec5 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Get_Dual_BolusTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetDualBolusTest.kt @@ -2,13 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -class DanaRS_Packet_Bolus_Get_Dual_BolusTest : DanaRSTestBase() { +class DanaRsPacketBolusGetDualBolusTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus_StateTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetExtendedBolusStateTest.kt similarity index 79% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus_StateTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetExtendedBolusStateTest.kt index 093ccbfa0c..c74b203ff5 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Get_Extended_Bolus_StateTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetExtendedBolusStateTest.kt @@ -2,15 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() -class DanaRS_Packet_Bolus_Get_Extended_Bolus_StateTest : DanaRSTestBase() { +class DanaRsPacketBolusGetExtendedBolusStateTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { @@ -27,10 +26,10 @@ class DanaRS_Packet_Bolus_Get_Extended_Bolus_StateTest : DanaRSTestBase() { Assert.assertEquals(null, packet.requestParams) // test message decoding var testValue = 0.0 - packet.handleMessage(createArray(11, testValue.toByte())) + packet.handleMessage(createArray(11, testValue.toInt().toByte())) Assert.assertEquals(testValue != 0.0, packet.failed) testValue = 1.0 - packet.handleMessage(createArray(11, testValue.toByte())) + packet.handleMessage(createArray(11, testValue.toInt().toByte())) // is extended bolus in progress Assert.assertEquals(testValue == 1.0, danaPump.isExtendedInProgress) Assert.assertEquals(testValue != 0.0, packet.failed) diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Get_Extended_BolusTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetExtendedBolusTest.kt similarity index 77% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Get_Extended_BolusTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetExtendedBolusTest.kt index 5f89ad8a8e..4da5e4ea6c 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Get_Extended_BolusTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetExtendedBolusTest.kt @@ -2,15 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() -class DanaRS_Packet_Bolus_Get_Extended_BolusTest : DanaRSTestBase() { +class DanaRsPacketBolusGetExtendedBolusTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { @@ -27,11 +26,11 @@ class DanaRS_Packet_Bolus_Get_Extended_BolusTest : DanaRSTestBase() { Assert.assertEquals(null, packet.requestParams) // test message decoding var testValue = 0.0 - packet.handleMessage(createArray(10, testValue.toByte())) + packet.handleMessage(createArray(10, testValue.toInt().toByte())) Assert.assertEquals(testValue != 0.0, packet.failed) testValue = 1.0 - packet.handleMessage(createArray(10, testValue.toByte())) - // is pump.bolustep set to 1 + packet.handleMessage(createArray(10, testValue.toInt().toByte())) + // is pump.bolusStep set to 1 Assert.assertEquals(testValue / 100.0, danaPump.bolusStep, 0.0) Assert.assertEquals(testValue != 0.0, packet.failed) Assert.assertEquals("BOLUS__GET_EXTENDED_BOLUS", packet.friendlyName) diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Get_Extended_Menu_Option_StateTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetExtendedMenuOptionStateTest.kt similarity index 86% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Get_Extended_Menu_Option_StateTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetExtendedMenuOptionStateTest.kt index 550273e68d..db66481f5a 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Get_Extended_Menu_Option_StateTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetExtendedMenuOptionStateTest.kt @@ -2,13 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -class DanaRS_Packet_Bolus_Get_Extended_Menu_Option_StateTest : DanaRSTestBase() { +class DanaRsPacketBolusGetExtendedMenuOptionStateTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { @@ -24,7 +25,7 @@ class DanaRS_Packet_Bolus_Get_Extended_Menu_Option_StateTest : DanaRSTestBase() Assert.assertEquals(null, packet.requestParams) // test message decoding packet.handleMessage(createArray(34, 0.toByte())) - // isExtendedinprogres should be false + // isExtendedInProgress should be false Assert.assertEquals(false, danaPump.isExtendedInProgress) // assertEquals(false, packet.failed); packet.handleMessage(createArray(34, 1.toByte())) diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Get_Initial_BolusTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetInitialBolusTest.kt similarity index 84% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Get_Initial_BolusTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetInitialBolusTest.kt index 0bd7db33a3..883205431c 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Get_Initial_BolusTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetInitialBolusTest.kt @@ -2,13 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -class DanaRS_Packet_Bolus_Get_Initial_BolusTest : DanaRSTestBase() { +class DanaRsPacketBolusGetInitialBolusTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { @@ -23,7 +24,7 @@ class DanaRS_Packet_Bolus_Get_Initial_BolusTest : DanaRSTestBase() { Assert.assertEquals(null, packet.requestParams) // test message decoding packet.handleMessage(createArray(34, 0.toByte())) - // should fail only if all the initialbolusses are 0 + // should fail only if all the initial boluses are 0 Assert.assertEquals(false, !packet.failed) packet.handleMessage(createArray(34, 1.toByte())) Assert.assertEquals(true, !packet.failed) diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_InformationTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetStepBolusInformationTest.kt similarity index 82% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_InformationTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetStepBolusInformationTest.kt index 66df970476..b1e4721db8 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Get_Step_Bolus_InformationTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusGetStepBolusInformationTest.kt @@ -2,16 +2,15 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner import java.util.* @RunWith(PowerMockRunner::class) -@PrepareForTest() -class DanaRS_Packet_Bolus_Get_Step_Bolus_InformationTest : DanaRSTestBase() { +class DanaRsPacketBolusGetStepBolusInformationTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { @@ -41,9 +40,10 @@ class DanaRS_Packet_Bolus_Get_Step_Bolus_InformationTest : DanaRSTestBase() { packet.handleMessage(array) Assert.assertTrue(packet.failed) Assert.assertEquals(6.0, danaPump.initialBolusAmount, 0.01) - val lastBolus = Date(danaPump.lastBolusTime) - Assert.assertEquals(13, lastBolus.hours) - Assert.assertEquals(20, lastBolus.minutes) + val lastBolus = Calendar.getInstance() + lastBolus.timeInMillis = danaPump.lastBolusTime + Assert.assertEquals(13, lastBolus.get(Calendar.HOUR_OF_DAY)) + Assert.assertEquals(20, lastBolus.get(Calendar.MINUTE)) Assert.assertEquals(12.5, danaPump.lastBolusAmount, 0.01) Assert.assertEquals(25.0, danaPump.maxBolus, 0.01) Assert.assertEquals(1.0, danaPump.bolusStep, 0.01) diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Set_Bolus_OptionTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusSetBolusOptionTest.kt similarity index 81% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Set_Bolus_OptionTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusSetBolusOptionTest.kt index 7fa66dbe43..450e0d17f8 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Set_Bolus_OptionTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusSetBolusOptionTest.kt @@ -2,13 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -class DanaRS_Packet_Bolus_Set_Bolus_OptionTest : DanaRSTestBase() { +class DanaRsPacketBolusSetBolusOptionTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { @@ -21,9 +22,9 @@ class DanaRS_Packet_Bolus_Set_Bolus_OptionTest : DanaRSTestBase() { @Test fun runTest() { val packet = DanaRS_Packet_Bolus_Set_Bolus_Option(packetInjector, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) // test params - val testparams = packet.requestParams - Assert.assertEquals(0.toByte(), testparams[0]) - Assert.assertEquals(0.toByte(), testparams[18]) + val testParams = packet.requestParams + Assert.assertEquals(0.toByte(), testParams[0]) + Assert.assertEquals(0.toByte(), testParams[18]) // test message decoding packet.handleMessage(createArray(34, 0.toByte())) // DanaRPump testPump = DanaRPump.getInstance(); diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Set_CIR_CF_ArrayTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusSetCirCfArrayTest.kt similarity index 81% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Set_CIR_CF_ArrayTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusSetCirCfArrayTest.kt index 925dd1731b..2987a11fb0 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Set_CIR_CF_ArrayTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusSetCirCfArrayTest.kt @@ -2,13 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -class DanaRS_Packet_Bolus_Set_CIR_CF_ArrayTest : DanaRSTestBase() { +class DanaRsPacketBolusSetCirCfArrayTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { @@ -21,9 +22,9 @@ class DanaRS_Packet_Bolus_Set_CIR_CF_ArrayTest : DanaRSTestBase() { @Test fun runTest() { val packet = DanaRS_Packet_Bolus_Set_CIR_CF_Array(packetInjector, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) // test params - val testparams = packet.requestParams - Assert.assertEquals(0.toByte(), testparams[0]) - Assert.assertEquals(0.toByte(), testparams[18]) + val testParams = packet.requestParams + Assert.assertEquals(0.toByte(), testParams[0]) + Assert.assertEquals(0.toByte(), testParams[18]) // test message decoding packet.handleMessage(createArray(34, 0.toByte())) // DanaRPump testPump = DanaRPump.getInstance(); diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Set_Dual_BolusTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusSetDualBolusTest.kt similarity index 81% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Set_Dual_BolusTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusSetDualBolusTest.kt index 5ae468084e..bd15873509 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Set_Dual_BolusTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusSetDualBolusTest.kt @@ -2,13 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -class DanaRS_Packet_Bolus_Set_Dual_BolusTest : DanaRSTestBase() { +class DanaRsPacketBolusSetDualBolusTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { @@ -21,9 +22,9 @@ class DanaRS_Packet_Bolus_Set_Dual_BolusTest : DanaRSTestBase() { @Test fun runTest() { val packet = DanaRS_Packet_Bolus_Set_Dual_Bolus(packetInjector, 0.0, 0.0, 1) // test params - val testparams = packet.requestParams - Assert.assertEquals(0.toByte(), testparams[0]) - Assert.assertEquals(1.toByte(), testparams[4]) + val testParams = packet.requestParams + Assert.assertEquals(0.toByte(), testParams[0]) + Assert.assertEquals(1.toByte(), testParams[4]) // test message decoding packet.handleMessage(createArray(34, 0.toByte())) // DanaRPump testPump = DanaRPump.getInstance(); diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus_CancelTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusSetExtendedBolusCancelTest.kt similarity index 88% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus_CancelTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusSetExtendedBolusCancelTest.kt index 3d836828d9..02893dc262 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Set_Extended_Bolus_CancelTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusSetExtendedBolusCancelTest.kt @@ -2,13 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -class DanaRS_Packet_Bolus_Set_Extended_Bolus_CancelTest : DanaRSTestBase() { +class DanaRsPacketBolusSetExtendedBolusCancelTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Set_Extended_BolusTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusSetExtendedBolusTest.kt similarity index 91% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Set_Extended_BolusTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusSetExtendedBolusTest.kt index aa3eb950d6..055bbf3582 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Set_Extended_BolusTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusSetExtendedBolusTest.kt @@ -2,13 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -class DanaRS_Packet_Bolus_Set_Extended_BolusTest : DanaRSTestBase() { +class DanaRsPacketBolusSetExtendedBolusTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Set_Initial_BolusTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusSetInitialBolusTest.kt similarity index 77% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Set_Initial_BolusTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusSetInitialBolusTest.kt index dee94531fc..f3510221ff 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Set_Initial_BolusTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusSetInitialBolusTest.kt @@ -2,13 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -class DanaRS_Packet_Bolus_Set_Initial_BolusTest : DanaRSTestBase() { +class DanaRsPacketBolusSetInitialBolusTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { @@ -21,9 +22,9 @@ class DanaRS_Packet_Bolus_Set_Initial_BolusTest : DanaRSTestBase() { @Test fun runTest() { val packet = DanaRS_Packet_Bolus_Set_Initial_Bolus(packetInjector, 0, 0, 0, 100) // test params - val testparams = packet.requestParams - Assert.assertEquals(0.toByte(), testparams[0]) - Assert.assertEquals(100.toByte(), testparams[6]) + val testParams = packet.requestParams + Assert.assertEquals(0.toByte(), testParams[0]) + Assert.assertEquals(100.toByte(), testParams[6]) // test message decoding packet.handleMessage(createArray(34, 0.toByte())) Assert.assertEquals(false, packet.failed) diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StartTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusSetStepBolusStartTest.kt similarity index 89% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StartTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusSetStepBolusStartTest.kt index e97af48150..95b95df7a7 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StartTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusSetStepBolusStartTest.kt @@ -4,6 +4,7 @@ import android.content.Context import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector import info.nightscout.androidaps.danars.DanaRSPlugin +import info.nightscout.androidaps.danars.DanaRSTestBase import info.nightscout.androidaps.interfaces.CommandQueueProvider import info.nightscout.androidaps.interfaces.Constraint import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker @@ -19,7 +20,7 @@ import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) @PrepareForTest(ConstraintChecker::class, DetailedBolusInfoStorage::class) -class DanaRS_Packet_Bolus_Set_Step_Bolus_StartTest : DanaRSTestBase() { +class DanaRsPacketBolusSetStepBolusStartTest : DanaRSTestBase() { @Mock lateinit var constraintChecker: ConstraintChecker @Mock lateinit var commandQueue: CommandQueueProvider @@ -41,9 +42,9 @@ class DanaRS_Packet_Bolus_Set_Step_Bolus_StartTest : DanaRSTestBase() { @Test fun runTest() { val packet = DanaRS_Packet_Bolus_Set_Step_Bolus_Start(packetInjector) // test params - val testparams = packet.requestParams - Assert.assertEquals(0.toByte(), testparams[0]) - Assert.assertEquals(0.toByte(), testparams[2]) + val testParams = packet.requestParams + Assert.assertEquals(0.toByte(), testParams[0]) + Assert.assertEquals(0.toByte(), testParams[2]) // test message decoding packet.handleMessage(byteArrayOf(0.toByte(), 0.toByte(), 0.toByte())) Assert.assertEquals(false, packet.failed) diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StopTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusSetStepBolusStopTest.kt similarity index 94% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StopTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusSetStepBolusStopTest.kt index b7a4238bd6..2de51051ff 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StopTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketBolusSetStepBolusStopTest.kt @@ -2,10 +2,11 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSPlugin +import info.nightscout.androidaps.danars.DanaRSTestBase import info.nightscout.androidaps.db.Treatment import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.plugins.bus.RxBusWrapper -import info.nightscout.androidaps.danars.DanaRSPlugin import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith @@ -17,7 +18,7 @@ import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) @PrepareForTest(RxBusWrapper::class, DanaRSPlugin::class) -class DanaRS_Packet_Bolus_Set_Step_Bolus_StopTest : DanaRSTestBase() { +class DanaRsPacketBolusSetStepBolusStopTest : DanaRSTestBase() { @Mock lateinit var activePlugin: ActivePluginProvider diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Etc_Keep_ConnectionTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketEtcKeepConnectionTest.kt similarity index 90% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Etc_Keep_ConnectionTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketEtcKeepConnectionTest.kt index 8316314b5e..ecc02cc85b 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Etc_Keep_ConnectionTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketEtcKeepConnectionTest.kt @@ -2,13 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -class DanaRS_Packet_Etc_Keep_ConnectionTest : DanaRSTestBase() { +class DanaRsPacketEtcKeepConnectionTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Etc_Set_History_SaveTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketEtcSetHistorySaveTest.kt similarity index 75% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Etc_Set_History_SaveTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketEtcSetHistorySaveTest.kt index e69ff881fb..a239281ad3 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Etc_Set_History_SaveTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketEtcSetHistorySaveTest.kt @@ -2,15 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() -class DanaRS_Packet_Etc_Set_History_SaveTest : DanaRSTestBase() { +class DanaRsPacketEtcSetHistorySaveTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { @@ -23,9 +22,9 @@ class DanaRS_Packet_Etc_Set_History_SaveTest : DanaRSTestBase() { @Test fun runTest() { val packet = DanaRS_Packet_Etc_Set_History_Save(packetInjector, 0, 0, 0, 0, 0, 0, 0, 0, 2) // test params - val testparams = packet.requestParams - Assert.assertEquals(2.toByte(), testparams[8]) - Assert.assertEquals((2 ushr 8).toByte(), testparams[9]) + val testParams = packet.requestParams + Assert.assertEquals(2.toByte(), testParams[8]) + Assert.assertEquals((2 ushr 8).toByte(), testParams[9]) // test message decoding packet.handleMessage(createArray(34, 0.toByte())) Assert.assertEquals(false, packet.failed) diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_General_Delivery_StatusTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketGeneralDeliveryStatusTest.kt similarity index 86% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_General_Delivery_StatusTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketGeneralDeliveryStatusTest.kt index 03f46ecb5b..c1a758daee 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_General_Delivery_StatusTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketGeneralDeliveryStatusTest.kt @@ -2,15 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() -class DanaRS_Packet_General_Delivery_StatusTest : DanaRSTestBase() { +class DanaRsPacketGeneralDeliveryStatusTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_General_Get_More_InformationTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketGeneralGetMoreInformationTest.kt similarity index 81% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_General_Get_More_InformationTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketGeneralGetMoreInformationTest.kt index 61aa3e632c..f21ae1b563 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_General_Get_More_InformationTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketGeneralGetMoreInformationTest.kt @@ -2,6 +2,7 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith @@ -9,7 +10,7 @@ import org.powermock.modules.junit4.PowerMockRunner import java.util.* @RunWith(PowerMockRunner::class) -class DanaRS_Packet_General_Get_More_InformationTest : DanaRSTestBase() { +class DanaRsPacketGeneralGetMoreInformationTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { @@ -37,7 +38,7 @@ class DanaRS_Packet_General_Get_More_InformationTest : DanaRSTestBase() { putIntToArray(array, 5, 150) // extended remaining minutes 150 putByteToArray(array, 9, 15) // hours 15 putByteToArray(array, 10, 25) // minutes 25 - putIntToArray(array, 11, 170) // last bolus manout 1.70 + putIntToArray(array, 11, 170) // last bolus amount 1.70 packet.handleMessage(array) Assert.assertFalse(packet.failed) @@ -45,9 +46,10 @@ class DanaRS_Packet_General_Get_More_InformationTest : DanaRSTestBase() { Assert.assertEquals(12.5, danaPump.dailyTotalUnits, 0.01) Assert.assertTrue(danaPump.isExtendedInProgress) Assert.assertEquals(150, danaPump.extendedBolusRemainingMinutes) - val lastBolus = Date(danaPump.lastBolusTime) - Assert.assertEquals(15, lastBolus.hours) - Assert.assertEquals(25, lastBolus.minutes) + val lastBolus = Calendar.getInstance() + lastBolus.timeInMillis = danaPump.lastBolusTime + Assert.assertEquals(15, lastBolus.get(Calendar.HOUR_OF_DAY)) + Assert.assertEquals(25, lastBolus.get(Calendar.MINUTE)) Assert.assertEquals(1.7, danaPump.lastBolusAmount, 0.01) Assert.assertEquals("REVIEW__GET_MORE_INFORMATION", packet.friendlyName) diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_General_Get_PasswordTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketGeneralGetPasswordTest.kt similarity index 90% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_General_Get_PasswordTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketGeneralGetPasswordTest.kt index 6968c7eff1..9fe3e2a8ec 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_General_Get_PasswordTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketGeneralGetPasswordTest.kt @@ -2,13 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -class DanaRS_Packet_General_Get_PasswordTest : DanaRSTestBase() { +class DanaRsPacketGeneralGetPasswordTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_General_Get_Pump_CheckTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketGeneralGetPumpCheckTest.kt similarity index 92% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_General_Get_Pump_CheckTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketGeneralGetPumpCheckTest.kt index 5994d2d5d0..b3c7b5df8f 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_General_Get_Pump_CheckTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketGeneralGetPumpCheckTest.kt @@ -2,6 +2,7 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import info.nightscout.androidaps.plugins.bus.RxBusWrapper import org.junit.Assert import org.junit.Test @@ -11,7 +12,7 @@ import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) @PrepareForTest(RxBusWrapper::class) -class DanaRS_Packet_General_Get_Pump_CheckTest : DanaRSTestBase() { +class DanaRsPacketGeneralGetPumpCheckTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_General_Get_Shipping_InformationTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketGeneralGetShippingInformationTest.kt similarity index 90% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_General_Get_Shipping_InformationTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketGeneralGetShippingInformationTest.kt index 21716b37c8..07201595db 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_General_Get_Shipping_InformationTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketGeneralGetShippingInformationTest.kt @@ -2,13 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -class DanaRS_Packet_General_Get_Shipping_InformationTest : DanaRSTestBase() { +class DanaRsPacketGeneralGetShippingInformationTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_General_Get_Shipping_VerisonTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketGeneralGetShippingVerisonTest.kt similarity index 89% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_General_Get_Shipping_VerisonTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketGeneralGetShippingVerisonTest.kt index e66dea3dad..3a63508855 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_General_Get_Shipping_VerisonTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketGeneralGetShippingVerisonTest.kt @@ -2,13 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -class DanaRS_Packet_General_Get_Shipping_VerisonTest : DanaRSTestBase() { +class DanaRsPacketGeneralGetShippingVerisonTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_General_Get_Today_Delivery_TotalTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketGeneralGetTodayDeliveryTotalTest.kt similarity index 91% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_General_Get_Today_Delivery_TotalTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketGeneralGetTodayDeliveryTotalTest.kt index bcb6c0987d..4497e3dc90 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_General_Get_Today_Delivery_TotalTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketGeneralGetTodayDeliveryTotalTest.kt @@ -2,13 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -class DanaRS_Packet_General_Get_Today_Delivery_TotalTest : DanaRSTestBase() { +class DanaRsPacketGeneralGetTodayDeliveryTotalTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_General_Get_User_Time_Change_FlagTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketGeneralGetUserTimeChangeFlagTest.kt similarity index 89% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_General_Get_User_Time_Change_FlagTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketGeneralGetUserTimeChangeFlagTest.kt index 69cada9822..0f901ca6e8 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_General_Get_User_Time_Change_FlagTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketGeneralGetUserTimeChangeFlagTest.kt @@ -2,13 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -class DanaRS_Packet_General_Get_User_Time_Change_FlagTest : DanaRSTestBase() { +class DanaRsPacketGeneralGetUserTimeChangeFlagTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_General_Initial_Screen_InformationTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketGeneralInitialScreenInformationTest.kt similarity index 90% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_General_Initial_Screen_InformationTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketGeneralInitialScreenInformationTest.kt index 60a8a6d74d..a67535ea5e 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_General_Initial_Screen_InformationTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketGeneralInitialScreenInformationTest.kt @@ -2,13 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -class DanaRS_Packet_General_Initial_Screen_InformationTest : DanaRSTestBase() { +class DanaRsPacketGeneralInitialScreenInformationTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_General_Set_History_Upload_ModeTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketGeneralSetHistoryUploadModeTest.kt similarity index 89% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_General_Set_History_Upload_ModeTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketGeneralSetHistoryUploadModeTest.kt index 4e88396e27..4a2061bce1 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_General_Set_History_Upload_ModeTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketGeneralSetHistoryUploadModeTest.kt @@ -2,13 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -class DanaRS_Packet_General_Set_History_Upload_ModeTest : DanaRSTestBase() { +class DanaRsPacketGeneralSetHistoryUploadModeTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_General_Set_User_Time_Change_Flag_ClearTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketGeneralSetUserTimeChangeFlagClearTest.kt similarity index 89% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_General_Set_User_Time_Change_Flag_ClearTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketGeneralSetUserTimeChangeFlagClearTest.kt index 20b312641a..2e6e170be5 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_General_Set_User_Time_Change_Flag_ClearTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketGeneralSetUserTimeChangeFlagClearTest.kt @@ -2,13 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -class DanaRS_Packet_General_Set_User_Time_Change_Flag_ClearTest : DanaRSTestBase() { +class DanaRsPacketGeneralSetUserTimeChangeFlagClearTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_History_All_HistoryTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketHistoryAllHistoryTest.kt similarity index 87% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_History_All_HistoryTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketHistoryAllHistoryTest.kt index 8e2558f0e2..8135997298 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_History_All_HistoryTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketHistoryAllHistoryTest.kt @@ -2,13 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -class DanaRS_Packet_History_All_HistoryTest : DanaRSTestBase() { +class DanaRsPacketHistoryAllHistoryTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_History_BasalTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketHistoryBasalTest.kt similarity index 87% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_History_BasalTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketHistoryBasalTest.kt index f0ab651b9e..1d0f7f978d 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_History_BasalTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketHistoryBasalTest.kt @@ -2,13 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -class DanaRS_Packet_History_BasalTest : DanaRSTestBase() { +class DanaRsPacketHistoryBasalTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_History_Blood_GlucoseTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketHistoryBloodGlucoseTest.kt similarity index 87% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_History_Blood_GlucoseTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketHistoryBloodGlucoseTest.kt index df83c63baa..683298ff8b 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_History_Blood_GlucoseTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketHistoryBloodGlucoseTest.kt @@ -2,13 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -class DanaRS_Packet_History_Blood_GlucoseTest : DanaRSTestBase() { +class DanaRsPacketHistoryBloodGlucoseTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_History_BolusTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketHistoryBolusTest.kt similarity index 87% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_History_BolusTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketHistoryBolusTest.kt index e2bc27ae88..94b8f19777 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_History_BolusTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketHistoryBolusTest.kt @@ -2,13 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -class DanaRS_Packet_History_BolusTest : DanaRSTestBase() { +class DanaRsPacketHistoryBolusTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_History_CarbohydrateTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketHistoryCarbohydrateTest.kt similarity index 87% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_History_CarbohydrateTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketHistoryCarbohydrateTest.kt index 6a9aa52189..cfa447fa89 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_History_CarbohydrateTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketHistoryCarbohydrateTest.kt @@ -2,13 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -class DanaRS_Packet_History_CarbohydrateTest : DanaRSTestBase() { +class DanaRsPacketHistoryCarbohydrateTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_History_DailyTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketHistoryDailyTest.kt similarity index 87% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_History_DailyTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketHistoryDailyTest.kt index 85719ce40d..a98894c6e7 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_History_DailyTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketHistoryDailyTest.kt @@ -2,13 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -class DanaRS_Packet_History_DailyTest : DanaRSTestBase() { +class DanaRsPacketHistoryDailyTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_History_PrimeTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketHistoryPrimeTest.kt similarity index 87% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_History_PrimeTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketHistoryPrimeTest.kt index f06f0605b9..a651910802 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_History_PrimeTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketHistoryPrimeTest.kt @@ -2,13 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -class DanaRS_Packet_History_PrimeTest : DanaRSTestBase() { +class DanaRsPacketHistoryPrimeTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_History_RefillTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketHistoryRefillTest.kt similarity index 87% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_History_RefillTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketHistoryRefillTest.kt index fcbc0a182c..65d484aa77 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_History_RefillTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketHistoryRefillTest.kt @@ -2,13 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -class DanaRS_Packet_History_RefillTest : DanaRSTestBase() { +class DanaRsPacketHistoryRefillTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_History_SuspendTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketHistorySuspendTest.kt similarity index 87% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_History_SuspendTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketHistorySuspendTest.kt index e6de597869..04fba763ee 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_History_SuspendTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketHistorySuspendTest.kt @@ -2,13 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -class DanaRS_Packet_History_SuspendTest : DanaRSTestBase() { +class DanaRsPacketHistorySuspendTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_History_TemporaryTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketHistoryTemporaryTest.kt similarity index 87% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_History_TemporaryTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketHistoryTemporaryTest.kt index 9064a8d3b4..c8eed86284 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_History_TemporaryTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketHistoryTemporaryTest.kt @@ -2,13 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -class DanaRS_Packet_History_TemporaryTest : DanaRSTestBase() { +class DanaRsPacketHistoryTemporaryTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Notify_AlarmTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketNotifyAlarmTest.kt similarity index 75% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Notify_AlarmTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketNotifyAlarmTest.kt index 04df7d84f9..0abdb1606a 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Notify_AlarmTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketNotifyAlarmTest.kt @@ -2,19 +2,16 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import info.nightscout.androidaps.plugins.general.nsclient.NSUpload import org.junit.Assert -import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.mockito.Mock -import org.powermock.api.mockito.PowerMockito -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest(NSUpload::class) -class DanaRS_Packet_Notify_AlarmTest : DanaRSTestBase() { +class DanaRsPacketNotifyAlarmTest : DanaRSTestBase() { @Mock lateinit var nsUpload: NSUpload @@ -34,7 +31,7 @@ class DanaRS_Packet_Notify_AlarmTest : DanaRSTestBase() { // test params Assert.assertEquals(null, packet.requestParams) // test message decoding -// handlemessage testing fails on non-eror byte because of NSUpload not properly mocked + // handle message testing fails on non-error byte because of NSUpload not properly mocked packet.handleMessage(createArray(17, 0x01.toByte())) Assert.assertEquals(false, packet.failed) // no error @@ -42,9 +39,4 @@ class DanaRS_Packet_Notify_AlarmTest : DanaRSTestBase() { Assert.assertEquals(true, packet.failed) Assert.assertEquals("NOTIFY__ALARM", packet.friendlyName) } - - @Before - fun mock() { - PowerMockito.mockStatic(NSUpload::class.java) - } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Notify_Delivery_Rate_DisplayTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketNotifyDeliveryRateDisplayTest.kt similarity index 87% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Notify_Delivery_Rate_DisplayTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketNotifyDeliveryRateDisplayTest.kt index 104ba1d13a..18db110e5b 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Notify_Delivery_Rate_DisplayTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketNotifyDeliveryRateDisplayTest.kt @@ -3,8 +3,8 @@ package info.nightscout.androidaps.danars.comm import android.content.Context import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.Config import info.nightscout.androidaps.danars.DanaRSPlugin +import info.nightscout.androidaps.danars.DanaRSTestBase import info.nightscout.androidaps.db.Treatment import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.CommandQueueProvider @@ -23,7 +23,7 @@ import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) @PrepareForTest(ConstraintChecker::class, RxBusWrapper::class, DetailedBolusInfoStorage::class) -class DanaRS_Packet_Notify_Delivery_Rate_DisplayTest : DanaRSTestBase() { +class DanaRsPacketNotifyDeliveryRateDisplayTest : DanaRSTestBase() { @Mock lateinit var activePlugin: ActivePluginProvider @Mock lateinit var constraintChecker: ConstraintChecker @@ -68,7 +68,7 @@ class DanaRS_Packet_Notify_Delivery_Rate_DisplayTest : DanaRSTestBase() { @Before fun mock() { - danaRSPlugin = DanaRSPlugin(HasAndroidInjector { AndroidInjector { Unit } }, aapsLogger, aapsSchedulers, rxBus, context, resourceHelper, constraintChecker, profileFunction, activePluginProvider, sp, commandQueue, danaPump, detailedBolusInfoStorage, fabricPrivacy, dateUtil) + danaRSPlugin = DanaRSPlugin(packetInjector, aapsLogger, aapsSchedulers, rxBus, context, resourceHelper, constraintChecker, profileFunction, activePluginProvider, sp, commandQueue, danaPump, detailedBolusInfoStorage, fabricPrivacy, dateUtil) danaPump.bolusingTreatment = Treatment(packetInjector) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Notify_Missed_Bolus_AlarmTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketNotifyMissedBolusAlarmTest.kt similarity index 89% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Notify_Missed_Bolus_AlarmTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketNotifyMissedBolusAlarmTest.kt index 164720f011..0a25ea13e9 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Notify_Missed_Bolus_AlarmTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketNotifyMissedBolusAlarmTest.kt @@ -2,13 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -class DanaRS_Packet_Notify_Missed_Bolus_AlarmTest : DanaRSTestBase() { +class DanaRsPacketNotifyMissedBolusAlarmTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Option_Get_Pump_TimeTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketOptionGetPumpTimeTest.kt similarity index 91% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Option_Get_Pump_TimeTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketOptionGetPumpTimeTest.kt index 3a1a8e1256..5efaeb9812 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Option_Get_Pump_TimeTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketOptionGetPumpTimeTest.kt @@ -2,6 +2,7 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.joda.time.DateTime import org.junit.Assert import org.junit.Test @@ -9,7 +10,7 @@ import org.junit.runner.RunWith import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -class DanaRS_Packet_Option_Get_Pump_TimeTest : DanaRSTestBase() { +class DanaRsPacketOptionGetPumpTimeTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Option_Get_User_OptionTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketOptionGetUserOptionTest.kt similarity index 90% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Option_Get_User_OptionTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketOptionGetUserOptionTest.kt index 8f5f8f0309..fb55d3c58b 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Option_Get_User_OptionTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketOptionGetUserOptionTest.kt @@ -2,13 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -class DanaRS_Packet_Option_Get_User_OptionTest : DanaRSTestBase() { +class DanaRsPacketOptionGetUserOptionTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Option_Set_Pump_TimeTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketOptionSetPumpTimeTest.kt similarity index 60% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Option_Set_Pump_TimeTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketOptionSetPumpTimeTest.kt index b67447884e..2b39688f61 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Option_Set_Pump_TimeTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketOptionSetPumpTimeTest.kt @@ -2,14 +2,15 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase +import org.joda.time.DateTime import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith import org.powermock.modules.junit4.PowerMockRunner -import java.util.* @RunWith(PowerMockRunner::class) -class DanaRS_Packet_Option_Set_Pump_TimeTest : DanaRSTestBase() { +class DanaRsPacketOptionSetPumpTimeTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { @@ -17,22 +18,20 @@ class DanaRS_Packet_Option_Set_Pump_TimeTest : DanaRSTestBase() { it.aapsLogger = aapsLogger it.dateUtil = dateUtil } - if (it is DanaRS_Packet_Option_Set_Pump_Time) { - } } } @Test fun runTest() { - val date = Date() - val packet = DanaRS_Packet_Option_Set_Pump_Time(packetInjector, date.time) + val date = DateTime() + val packet = DanaRS_Packet_Option_Set_Pump_Time(packetInjector, date.millis) // test params val params = packet.requestParams - Assert.assertEquals((date.year - 100 and 0xff).toByte(), params[0]) // 2019 -> 19 - Assert.assertEquals((date.month + 1 and 0xff).toByte(), params[1]) - Assert.assertEquals((date.date and 0xff).toByte(), params[2]) - Assert.assertEquals((date.hours and 0xff).toByte(), params[3]) - Assert.assertEquals((date.minutes and 0xff).toByte(), params[4]) - Assert.assertEquals((date.seconds and 0xff).toByte(), params[5]) + Assert.assertEquals((date.year - 2000 and 0xff).toByte(), params[0]) // 2019 -> 19 + Assert.assertEquals((date.monthOfYear and 0xff).toByte(), params[1]) + Assert.assertEquals((date.dayOfMonth and 0xff).toByte(), params[2]) + Assert.assertEquals((date.hourOfDay and 0xff).toByte(), params[3]) + Assert.assertEquals((date.minuteOfHour and 0xff).toByte(), params[4]) + Assert.assertEquals((date.secondOfMinute and 0xff).toByte(), params[5]) // test message decoding packet.handleMessage(createArray(3, 0.toByte())) Assert.assertEquals(false, packet.failed) diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Review_Bolus_AvgTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketReviewBolusAvgTest.kt similarity index 87% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Review_Bolus_AvgTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketReviewBolusAvgTest.kt index 5b5e179f7d..c4b7219a41 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Review_Bolus_AvgTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketReviewBolusAvgTest.kt @@ -2,15 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest() -class DanaRS_Packet_Review_Bolus_AvgTest : DanaRSTestBase() { +class DanaRsPacketReviewBolusAvgTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { diff --git a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Review_Get_Pump_Dec_RatioTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketReviewGetPumpDecRatioTest.kt similarity index 88% rename from app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Review_Get_Pump_Dec_RatioTest.kt rename to danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketReviewGetPumpDecRatioTest.kt index 9c04fdf0c1..43c56c9496 100644 --- a/app/src/test/java/info/nightscout/androidaps/danars/comm/DanaRS_Packet_Review_Get_Pump_Dec_RatioTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketReviewGetPumpDecRatioTest.kt @@ -2,13 +2,14 @@ package info.nightscout.androidaps.danars.comm import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -class DanaRS_Packet_Review_Get_Pump_Dec_RatioTest : DanaRSTestBase() { +class DanaRsPacketReviewGetPumpDecRatioTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { AndroidInjector { From f3fb533cf00801294f95dd1a4de3e040fd994e65 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 18 Feb 2021 21:38:36 +0100 Subject: [PATCH 17/28] 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) From 94a7e708e373a25618aceff472a5f8610d8a8366 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 18 Feb 2021 22:33:14 +0100 Subject: [PATCH 18/28] simplify gradle files --- app/build.gradle | 37 ++----------------- core/build.gradle | 41 ++------------------- danars/build.gradle | 44 ++--------------------- gradle/android_dependencies.gradle | 43 ++++++++++++++++++++++ gradle/android_module_dependencies.gradle | 9 +++++ 5 files changed, 61 insertions(+), 113 deletions(-) create mode 100644 gradle/android_module_dependencies.gradle diff --git a/app/build.gradle b/app/build.gradle index 6fdc3c7d18..92071cdec5 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -6,6 +6,8 @@ apply plugin: 'com.google.gms.google-services' apply plugin: 'com.hiya.jacoco-android' apply plugin: 'com.google.firebase.crashlytics' +apply from: "${project.rootDir}/gradle/android_dependencies.gradle" + jacoco { toolVersion = "0.8.6" } @@ -103,12 +105,9 @@ tasks.matching { it instanceof Test }.all { } android { - compileSdkVersion 28 ndkVersion "21.1.6352462" defaultConfig { - minSdkVersion 26 - targetSdkVersion 28 multiDexEnabled true versionCode 1500 version "2.8.2.1-dev-b" @@ -117,37 +116,12 @@ android { buildConfigField "String", "REMOTE", '"' + generateGitRemote() + '"' buildConfigField "String", "HEAD", '"' + generateGitBuild() + '"' buildConfigField "String", "COMMITTED", '"' + allCommitted() + '"' - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - // if you change minSdkVersion to less than 11, you need to change executeTask for wear ndk { moduleName "BleCommandUtil" } } - kotlinOptions { - jvmTarget = '1.8' - } - buildFeatures { - viewBinding true - } - lintOptions { - checkReleaseBuilds false - disable 'MissingTranslation' - disable 'ExtraTranslation' - } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } - debug { - testCoverageEnabled(project.hasProperty('coverage')) - } - firebaseDisable { - System.setProperty("disableFirebase", "true") - ext.enableCrashlytics = false - } - } + flavorDimensions "standard" productFlavors { full { @@ -191,13 +165,8 @@ android { ] } } - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } useLibrary "org.apache.http.legacy" - } allprojects { diff --git a/core/build.gradle b/core/build.gradle index 20f8c6e5e6..9d8dbc05da 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -4,51 +4,16 @@ apply plugin: 'kotlin-kapt' apply plugin: 'kotlin-parcelize' apply plugin: 'com.hiya.jacoco-android' -android { - compileSdkVersion 28 +apply from: "${project.rootDir}/gradle/android_dependencies.gradle" +apply from: "${project.rootDir}/gradle/android_module_dependencies.gradle" +android { defaultConfig { - minSdkVersion 26 - targetSdkVersion 28 versionCode 1 versionName "1.0" - - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - consumerProguardFiles 'consumer-rules.pro' - } - - kotlinOptions { - jvmTarget = '1.8' - } - buildFeatures { - viewBinding true - } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } - debug { - testCoverageEnabled(project.hasProperty('coverage')) - } - firebaseDisable { - System.setProperty("disableFirebase", "true") - ext.enableCrashlytics = false - } - } - flavorDimensions "standard" - productFlavors { - full { - dimension "standard" - } - } - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 } } - dependencies { implementation project(':database') } diff --git a/danars/build.gradle b/danars/build.gradle index a7c5ac60d6..e0caafd2c9 100644 --- a/danars/build.gradle +++ b/danars/build.gradle @@ -3,47 +3,13 @@ apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' apply plugin: 'com.hiya.jacoco-android' -android { - compileSdkVersion 28 +apply from: "${project.rootDir}/gradle/android_dependencies.gradle" +apply from: "${project.rootDir}/gradle/android_module_dependencies.gradle" +android { defaultConfig { - minSdkVersion 26 - targetSdkVersion 28 versionCode 1 versionName "1.0" - - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - consumerProguardFiles 'consumer-rules.pro' - } - - kotlinOptions { - jvmTarget = '1.8' - } - buildFeatures { - viewBinding true - } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' - } - debug { - testCoverageEnabled(project.hasProperty('coverage')) - } - firebaseDisable { - System.setProperty("disableFirebase", "true") - ext.enableCrashlytics = false - } - } - flavorDimensions "standard" - productFlavors { - full { - dimension "standard" - } - } - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 } } @@ -51,10 +17,6 @@ dependencies { implementation project(':core') implementation project(':dana') - implementation fileTree(dir: 'libs', include: ['*.jar']) - - implementation "androidx.core:core-ktx:$coreVersion" - annotationProcessor "com.google.dagger:dagger-compiler:$dagger_version" annotationProcessor "com.google.dagger:dagger-android-processor:$dagger_version" kapt "com.google.dagger:dagger-android-processor:$dagger_version" diff --git a/gradle/android_dependencies.gradle b/gradle/android_dependencies.gradle index e69de29bb2..690d19ba83 100644 --- a/gradle/android_dependencies.gradle +++ b/gradle/android_dependencies.gradle @@ -0,0 +1,43 @@ +android { + compileSdkVersion 28 + defaultConfig { + minSdkVersion 26 + targetSdkVersion 28 + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles 'consumer-rules.pro' + } + + kotlinOptions { + jvmTarget = '1.8' + } + + buildFeatures { + viewBinding true + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + debug { + testCoverageEnabled(project.hasProperty('coverage')) + } + firebaseDisable { + System.setProperty("disableFirebase", "true") + ext.enableCrashlytics = false + } + } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + + lintOptions { + checkReleaseBuilds false + disable 'MissingTranslation' + disable 'ExtraTranslation' + } +} \ No newline at end of file diff --git a/gradle/android_module_dependencies.gradle b/gradle/android_module_dependencies.gradle new file mode 100644 index 0000000000..4f75fb8546 --- /dev/null +++ b/gradle/android_module_dependencies.gradle @@ -0,0 +1,9 @@ +android { + + flavorDimensions "standard" + productFlavors { + full { + dimension "standard" + } + } +} \ No newline at end of file From d7ad8eeefc7f834b6a09594e91d96cd22ee6b0bf Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 18 Feb 2021 23:35:23 +0100 Subject: [PATCH 19/28] migrate rest of gradle module files --- app/src/main/res/values/arrays.xml | 63 ------------------ app/src/main/res/values/strings.xml | 1 - app/src/main/res/values/styles.xml | 10 --- core/build.gradle | 4 +- core/core_dependencies.gradle | 6 +- .../src/main/res/drawable/ic_refresh.xml | 0 core/src/main/res/values/styles.xml | 10 +++ dana/build.gradle | 47 ++----------- .../dana/ExampleInstrumentedTest.kt | 25 ------- danar/build.gradle | 47 ++----------- danars/build.gradle | 10 +-- database/build.gradle | 31 +-------- gradle/android_module_dependencies.gradle | 16 +++++ medtronic/build.gradle | 48 ++------------ .../medtronic/ExampleInstrumentedTest.java | 27 -------- .../res/layout/medtronic_history_activity.xml | 2 +- medtronic/src/main/res/values/arrays.xml | 66 +++++++++++++++++++ medtronic/src/main/res/values/strings.xml | 2 + omnipod-dash/build.gradle | 45 ++----------- omnipod-eros/build.gradle | 50 ++------------ .../eros/OmnipodErosPumpPluginTest.java | 2 +- rileylink/build.gradle | 48 ++------------ .../pump/common/ExampleInstrumentedTest.java | 27 -------- .../res/layout/rileylink_status_history.xml | 4 +- wear/build.gradle | 3 +- 25 files changed, 140 insertions(+), 454 deletions(-) rename {app => core}/src/main/res/drawable/ic_refresh.xml (100%) delete mode 100644 dana/src/androidTest/java/info/nightscout/androidaps/dana/ExampleInstrumentedTest.kt delete mode 100644 medtronic/src/androidTest/java/info/nightscout/androidaps/plugins/pump/medtronic/ExampleInstrumentedTest.java create mode 100644 medtronic/src/main/res/values/arrays.xml delete mode 100644 rileylink/src/androidTest/java/info/nightscout/androidaps/plugins/pump/common/ExampleInstrumentedTest.java diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 0b02d9a048..ecffee5c8e 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -125,69 +125,6 @@ YpsoPump - - Other (unsupported) - 512 - 712 - 515 - 715 - 522 - 722 - 523 (Fw 2.4A or lower) - 723 (Fw 2.4A or lower) - 554 (EU Fw. <= 2.6A) - 754 (EU Fw. <= 2.6A) - 554 (CA Fw. <= 2.7A) - 754 (CA Fw. <= 2.7A) - - - - @string/medtronic_pump_frequency_us_ca - @string/medtronic_pump_frequency_worldwide - - - - @string/key_medtronic_pump_frequency_us_ca - @string/key_medtronic_pump_frequency_worldwide - - - - 5 - 10 - 15 - - - - @string/medtronic_pump_encoding_4b6b_local - @string/medtronic_pump_encoding_4b6b_rileylink - - - - @string/common_on - @string/common_off - - - - @string/key_medtronic_pump_encoding_4b6b_local - @string/key_medtronic_pump_encoding_4b6b_rileylink - - - - @string/medtronic_pump_battery_no - @string/medtronic_pump_battery_alkaline - @string/medtronic_pump_battery_lithium - @string/medtronic_pump_battery_nizn - @string/medtronic_pump_battery_nimh - - - - @string/key_medtronic_pump_battery_no - @string/key_medtronic_pump_battery_alkaline - @string/key_medtronic_pump_battery_lithium - @string/key_medtronic_pump_battery_nizn - @string/key_medtronic_pump_battery_nimh - - 15 30 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0d7e5910da..9c0acd512a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1251,7 +1251,6 @@ snoozedTo snooze_dst_in24h snooze_loopdisabled - ^\\d{6} Use of Extended bolus feature will stop closed loop mode for the time of running extended bolus. Do you really want it? Closed loop disabled because of running Extended bolus \"PhoneChecker\" diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 054f8f8d23..b79d02361d 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -22,16 +22,6 @@ @color/colorAccent - - - + + +