From 451cea156f3729d4ee32b9196da50e5d52289f4c Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 19 Mar 2020 18:02:24 +0100 Subject: [PATCH] More tests --- .../nightscout/androidaps/data/Profile.java | 14 ++- .../androidaps/db/DatabaseHelper.java | 2 +- .../androidaps/db/ProfileSwitch.java | 40 +++++--- .../dependencyInjection/AppComponent.kt | 2 + .../dependencyInjection/AppModule.kt | 6 +- .../ProfileFunctionImplementation.kt | 4 +- .../Dialogs/NewNSTreatmentDialog.java | 26 +---- .../plugins/general/nsclient/NSUpload.java | 19 ++++ .../sensitivity/SensitivityAAPSPlugin.java | 2 +- .../sensitivity/SensitivityOref0Plugin.java | 2 +- .../sensitivity/SensitivityOref1Plugin.java | 2 +- .../SensitivityWeightedAveragePlugin.java | 2 +- .../plugins/treatments/TreatmentsPlugin.java | 2 +- .../info/nightscout/androidaps/TestBase.kt | 13 --- .../androidaps/TestBaseWithProfile.kt | 60 ++++++++++++ .../data/NonOverapingIntervalsTest.java | 58 ----------- .../data/NonOverlappingIntervalsTest.kt | 51 ++++++++++ .../data/OverapingIntervalsTest.java | 72 -------------- .../data/OverlappingIntervalsTest.kt | 60 ++++++++++++ .../androidaps/data/ProfileIntervalsTest.java | 95 ------------------- .../androidaps/data/ProfileIntervalsTest.kt | 90 ++++++++++++++++++ .../interfaces/ConstraintsCheckerTest.kt | 10 +- .../plugins/aps/loop/APSResultTest.kt | 10 +- .../actions/ActionNotificationTest.kt | 29 +++++- .../automation/actions/ActionsTestBase.kt | 7 +- .../automation/triggers/TriggerTestBase.kt | 6 +- .../Dialogs/NewNSTreatmentDialogTest.java | 86 ----------------- .../SmsCommunicatorPluginTest.kt | 11 +-- .../plugins/pump/danaR/DanaRPluginTest.kt | 11 +-- .../pump/danaR/comm/MessageHashTableRTest.kt | 3 +- .../pump/danaRKorean/DanaRKoreanPluginTest.kt | 11 +-- .../comm/MessageHashTableRKoreanTest.kt | 5 - .../plugins/pump/danaRS/DanaRSPluginTest.kt | 5 - .../danaRS/comm/DanaRSMessageHashTableTest.kt | 5 - .../pump/danaRS/comm/DanaRSTestBase.kt | 6 +- .../DanaRS_Packet_APS_History_EventsTest.kt | 3 - .../DanaRS_Packet_Basal_Get_Basal_RateTest.kt | 4 - ...anaRS_Packet_Bolus_Get_Bolus_OptionTest.kt | 5 - ...S_Packet_Bolus_Set_Step_Bolus_StartTest.kt | 5 - ...RS_Packet_Bolus_Set_Step_Bolus_StopTest.kt | 3 - ...anaRS_Packet_General_Get_Pump_CheckTest.kt | 5 - .../comm/DanaRS_Packet_History_AlarmTest.kt | 4 - .../DanaRS_Packet_History_All_HistoryTest.kt | 4 - .../comm/DanaRS_Packet_History_BasalTest.kt | 4 - ...DanaRS_Packet_History_Blood_GlucoseTest.kt | 4 - .../comm/DanaRS_Packet_History_BolusTest.kt | 4 - .../DanaRS_Packet_History_CarbohydrateTest.kt | 4 - .../comm/DanaRS_Packet_History_DailyTest.kt | 4 - .../comm/DanaRS_Packet_History_PrimeTest.kt | 4 - .../comm/DanaRS_Packet_History_RefillTest.kt | 4 - .../comm/DanaRS_Packet_History_SuspendTest.kt | 4 - .../DanaRS_Packet_History_TemporaryTest.kt | 4 - .../comm/DanaRS_Packet_Notify_AlarmTest.kt | 4 - ...aRS_Packet_Notify_Delivery_CompleteTest.kt | 4 - ...Packet_Notify_Delivery_Rate_DisplayTest.kt | 4 - .../plugins/pump/danaRv2/DanaRv2PluginTest.kt | 11 +-- .../danaRv2/comm/MessageHashTable_rv2Test.kt | 4 +- .../pump/danaRv2/comm/MsgCheckValue_v2Test.kt | 4 +- .../comm/MedtronicHistoryDataUTest.java | 8 -- .../androidaps/queue/CommandQueueTest.kt | 11 +-- 60 files changed, 392 insertions(+), 554 deletions(-) create mode 100644 app/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt delete mode 100644 app/src/test/java/info/nightscout/androidaps/data/NonOverapingIntervalsTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/data/NonOverlappingIntervalsTest.kt delete mode 100644 app/src/test/java/info/nightscout/androidaps/data/OverapingIntervalsTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/data/OverlappingIntervalsTest.kt delete mode 100644 app/src/test/java/info/nightscout/androidaps/data/ProfileIntervalsTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/data/ProfileIntervalsTest.kt delete mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/general/careportal/Dialogs/NewNSTreatmentDialogTest.java diff --git a/app/src/main/java/info/nightscout/androidaps/data/Profile.java b/app/src/main/java/info/nightscout/androidaps/data/Profile.java index 771e295cba..52b3c3791e 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/Profile.java +++ b/app/src/main/java/info/nightscout/androidaps/data/Profile.java @@ -14,6 +14,7 @@ import javax.inject.Inject; import dagger.android.HasAndroidInjector; import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Constants; +import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.interfaces.ActivePluginProvider; import info.nightscout.androidaps.interfaces.PumpDescription; @@ -30,10 +31,10 @@ import info.nightscout.androidaps.utils.MidnightTime; import info.nightscout.androidaps.utils.resources.ResourceHelper; public class Profile { - @Inject AAPSLogger aapsLogger; - @Inject ActivePluginProvider activePlugin; - @Inject ResourceHelper resourceHelper; - @Inject RxBusWrapper rxBus; + @Inject public AAPSLogger aapsLogger; + @Inject public ActivePluginProvider activePlugin; + @Inject public ResourceHelper resourceHelper; + @Inject public RxBusWrapper rxBus; private HasAndroidInjector injector; @@ -58,6 +59,11 @@ public class Profile { protected boolean isValid; protected boolean isValidated; + // Default constructor for DB + public Profile() { + MainApp.instance().injector.androidInjector().inject(this); + } + protected Profile(HasAndroidInjector injector) { injector.androidInjector().inject(this); this.injector = injector; diff --git a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java index 79e130c2cf..0d65d80f6b 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java @@ -1710,7 +1710,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { public void createProfileSwitchFromJsonIfNotExists(JSONObject trJson) { try { - ProfileSwitch profileSwitch = new ProfileSwitch(); + ProfileSwitch profileSwitch = new ProfileSwitch(MainApp.instance().injector); profileSwitch.date = trJson.getLong("mills"); if (trJson.has("duration")) profileSwitch.durationInMinutes = trJson.getInt("duration"); diff --git a/app/src/main/java/info/nightscout/androidaps/db/ProfileSwitch.java b/app/src/main/java/info/nightscout/androidaps/db/ProfileSwitch.java index de9d58b930..86f557ccce 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/ProfileSwitch.java +++ b/app/src/main/java/info/nightscout/androidaps/db/ProfileSwitch.java @@ -9,18 +9,19 @@ import com.j256.ormlite.field.DatabaseField; import com.j256.ormlite.table.DatabaseTable; import org.json.JSONObject; -import org.slf4j.Logger; import java.util.List; import java.util.Objects; -import info.nightscout.androidaps.MainApp; +import javax.inject.Inject; + +import dagger.android.HasAndroidInjector; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.interfaces.Interval; +import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.logging.StacktraceLoggerWrapper; -import info.nightscout.androidaps.plugins.bus.RxBus; +import info.nightscout.androidaps.plugins.bus.RxBusWrapper; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.general.overview.graphExtensions.DataPointWithLabelInterface; import info.nightscout.androidaps.plugins.general.overview.graphExtensions.PointsWithLabelGraphSeries; @@ -30,10 +31,10 @@ import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.DecimalFormatter; import info.nightscout.androidaps.utils.T; +import info.nightscout.androidaps.utils.resources.ResourceHelper; @DatabaseTable(tableName = DatabaseHelper.DATABASE_PROFILESWITCHES) public class ProfileSwitch implements Interval, DataPointWithLabelInterface { - private static Logger log = StacktraceLoggerWrapper.getLogger(L.DATABASE); @DatabaseField(id = true) public long date; @@ -67,6 +68,17 @@ public class ProfileSwitch implements Interval, DataPointWithLabelInterface { private Profile profile = null; + HasAndroidInjector injector; + @Inject public TreatmentsPlugin treatmentsPlugin; + @Inject public AAPSLogger aapsLogger; + @Inject public RxBusWrapper rxBus; + @Inject public ResourceHelper resourceHelper; + + public ProfileSwitch(HasAndroidInjector injector) { + injector.androidInjector().inject(this); + this.injector = injector; + } + public ProfileSwitch date(long date) { this.date = date; return this; @@ -96,10 +108,10 @@ public class ProfileSwitch implements Interval, DataPointWithLabelInterface { public Profile getProfileObject() { if (profile == null) try { - profile = new Profile(MainApp.instance().injector, new JSONObject(profileJson), percentage, timeshift); + profile = new Profile(injector, new JSONObject(profileJson), percentage, timeshift); } catch (Exception e) { - log.error("Unhandled exception", e); - log.error("Unhandled exception", profileJson); + aapsLogger.error("Unhandled exception", e); + aapsLogger.error("Unhandled exception: " + profileJson); } return profile; } @@ -217,7 +229,7 @@ public class ProfileSwitch implements Interval, DataPointWithLabelInterface { @Override public boolean isValid() { boolean isValid = getProfileObject() != null && getProfileObject().isValid(DateUtil.dateAndTimeString(date)); - ProfileSwitch active = TreatmentsPlugin.getPlugin().getProfileSwitchFromHistory(DateUtil.now()); + ProfileSwitch active = treatmentsPlugin.getProfileSwitchFromHistory(DateUtil.now()); long activeProfileSwitchDate = active != null ? active.date : -1L; if (!isValid && date == activeProfileSwitchDate) createNotificationInvalidProfile(DateUtil.dateAndTimeString(date)); @@ -225,23 +237,23 @@ public class ProfileSwitch implements Interval, DataPointWithLabelInterface { } private void createNotificationInvalidProfile(String detail) { - Notification notification = new Notification(Notification.ZERO_VALUE_IN_PROFILE, String.format(MainApp.gs(R.string.zerovalueinprofile), detail), Notification.LOW, 5); - RxBus.Companion.getINSTANCE().send(new EventNewNotification(notification)); + Notification notification = new Notification(Notification.ZERO_VALUE_IN_PROFILE, resourceHelper.gs(R.string.zerovalueinprofile, detail), Notification.LOW, 5); + rxBus.send(new EventNewNotification(notification)); } - public static boolean isEvent5minBack(List list, long time, boolean zeroDurationOnly) { + public static boolean isEvent5minBack(AAPSLogger aapsLogger, List list, long time, boolean zeroDurationOnly) { for (int i = 0; i < list.size(); i++) { ProfileSwitch event = list.get(i); if (event.date <= time && event.date > (time - T.mins(5).msecs())) { if (zeroDurationOnly) { if (event.durationInMinutes == 0) { if (L.isEnabled(L.DATABASE)) - log.debug("Found ProfileSwitch event for time: " + DateUtil.dateAndTimeString(time) + " " + event.toString()); + aapsLogger.debug("Found ProfileSwitch event for time: " + DateUtil.dateAndTimeString(time) + " " + event.toString()); return true; } } else { if (L.isEnabled(L.DATABASE)) - log.debug("Found ProfileSwitch event for time: " + DateUtil.dateAndTimeString(time) + " " + event.toString()); + aapsLogger.debug("Found ProfileSwitch event for time: " + DateUtil.dateAndTimeString(time) + " " + event.toString()); return true; } } diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppComponent.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppComponent.kt index 8ec9850bb1..2df72d8a63 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppComponent.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppComponent.kt @@ -9,6 +9,7 @@ import info.nightscout.androidaps.data.Profile import info.nightscout.androidaps.data.ProfileStore import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.db.BgReading +import info.nightscout.androidaps.db.ProfileSwitch import info.nightscout.androidaps.plugins.aps.loop.APSResult import info.nightscout.androidaps.plugins.aps.openAPSAMA.DetermineBasalResultAMA import info.nightscout.androidaps.plugins.aps.openAPSMA.DetermineBasalResultMA @@ -144,6 +145,7 @@ interface AppComponent : AndroidInjector { fun injectTreatment(treatment: Treatment) fun injectBgReading(bgReading: BgReading) + fun injectProfileSwitch(profileSwitch: ProfileSwitch) fun injectNotification(notificationWithAction: NotificationWithAction) diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt index 8578605a0f..ddb268b6db 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt @@ -12,6 +12,7 @@ import info.nightscout.androidaps.data.Profile import info.nightscout.androidaps.data.ProfileStore import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.db.BgReading +import info.nightscout.androidaps.db.ProfileSwitch import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.CommandQueueProvider import info.nightscout.androidaps.logging.AAPSLogger @@ -59,8 +60,8 @@ open class AppModule { @Provides @Singleton - fun provideProfileFunction(aapsLogger: AAPSLogger, sp: SP, resourceHelper: ResourceHelper, activePlugin: ActivePluginProvider): ProfileFunction { - return ProfileFunctionImplementation(aapsLogger, sp, resourceHelper, activePlugin) + fun provideProfileFunction(injector: HasAndroidInjector, aapsLogger: AAPSLogger, sp: SP, resourceHelper: ResourceHelper, activePlugin: ActivePluginProvider): ProfileFunction { + return ProfileFunctionImplementation(injector, aapsLogger, sp, resourceHelper, activePlugin) } @Provides @@ -198,6 +199,7 @@ open class AppModule { @ContributesAndroidInjector fun bgReadingInjector(): BgReading @ContributesAndroidInjector fun treatmentInjector(): Treatment + @ContributesAndroidInjector fun profileSwitchInjector(): ProfileSwitch @ContributesAndroidInjector fun notificationWithActionInjector(): NotificationWithAction diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ProfileFunctionImplementation.kt b/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ProfileFunctionImplementation.kt index 13f9fdc8a6..58c6af2df3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ProfileFunctionImplementation.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ProfileFunctionImplementation.kt @@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.configBuilder import android.os.Bundle import com.google.firebase.analytics.FirebaseAnalytics +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.BuildConfig import info.nightscout.androidaps.Constants import info.nightscout.androidaps.R @@ -21,6 +22,7 @@ import javax.inject.Singleton @Singleton class ProfileFunctionImplementation @Inject constructor( + private val injector: HasAndroidInjector, private val aapsLogger: AAPSLogger, private val sp: SP, private val resourceHelper: ResourceHelper, @@ -99,7 +101,7 @@ class ProfileFunctionImplementation @Inject constructor( override fun prepareProfileSwitch(profileStore: ProfileStore, profileName: String, duration: Int, percentage: Int, timeShift: Int, date: Long): ProfileSwitch { val profile = profileStore.getSpecificProfile(profileName) ?: throw InvalidParameterSpecException(profileName) - val profileSwitch = ProfileSwitch() + val profileSwitch = ProfileSwitch(injector) profileSwitch.date = date profileSwitch.source = Source.USER profileSwitch.profileName = profileName diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/Dialogs/NewNSTreatmentDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/Dialogs/NewNSTreatmentDialog.java index c027f2c9ea..211aec3c30 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/Dialogs/NewNSTreatmentDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/Dialogs/NewNSTreatmentDialog.java @@ -50,6 +50,7 @@ import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.db.ProfileSwitch; import info.nightscout.androidaps.interfaces.ActivePluginProvider; +import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.StacktraceLoggerWrapper; import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker; @@ -71,6 +72,7 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP; public class NewNSTreatmentDialog extends DaggerDialogFragment implements View.OnClickListener, DatePickerDialog.OnDateSetListener, TimePickerDialog.OnTimeSetListener { @Inject HasAndroidInjector injector; + @Inject AAPSLogger aapsLogger; @Inject DefaultValueHelper defaultValueHelper; @Inject ProfileFunction profileFunction; @Inject ResourceHelper resourceHelper; @@ -80,8 +82,6 @@ public class NewNSTreatmentDialog extends DaggerDialogFragment implements View.O @Inject TreatmentsPlugin treatmentsPlugin; @Inject HardLimits hardLimits; - private static Logger log = StacktraceLoggerWrapper.getLogger(NewNSTreatmentDialog.class); - private static OptionsToShow options; private static @StringRes int event; @@ -182,7 +182,7 @@ public class NewNSTreatmentDialog extends DaggerDialogFragment implements View.O profileStore = activePlugin.getActiveProfileInterface().getProfile(); if (profileStore == null) { if (options.eventType == R.id.careportal_profileswitch) { - log.error("Profile switch called but plugin doesn't contain valid profile"); + aapsLogger.error("Profile switch called but plugin doesn't contain valid profile"); } } else { ArrayList profileList; @@ -604,7 +604,7 @@ public class NewNSTreatmentDialog extends DaggerDialogFragment implements View.O data.put("relative", enteredInsulin * (100 - SafeParse.stringToDouble(editSplit.getText())) / 100 / SafeParse.stringToDouble(editDuration.getText()) * 60); } } catch (JSONException e) { - log.error("Unhandled exception", e); + aapsLogger.error("Unhandled exception", e); } return data; } @@ -715,26 +715,10 @@ public class NewNSTreatmentDialog extends DaggerDialogFragment implements View.O private void confirmNSTreatmentCreation() { final JSONObject data = gatherData(); - OKDialog.showConfirmation(getContext(), Translator.translate(JsonHelper.safeGetString(data, "eventType", resourceHelper.gs(R.string.overview_treatment_label))), buildConfirmText(data), () -> createNSTreatment(data)); + OKDialog.showConfirmation(getContext(), Translator.translate(JsonHelper.safeGetString(data, "eventType", resourceHelper.gs(R.string.overview_treatment_label))), buildConfirmText(data), () -> NSUpload.createNSTreatment(data, profileStore, profileFunction, eventTime.getTime())); } - void createNSTreatment(JSONObject data) { - if (JsonHelper.safeGetString(data, "eventType", "").equals(CareportalEvent.PROFILESWITCH)) { - ProfileSwitch profileSwitch = profileFunction.prepareProfileSwitch( - profileStore, - JsonHelper.safeGetString(data, "profile"), - JsonHelper.safeGetInt(data, "duration"), - JsonHelper.safeGetInt(data, "percentage"), - JsonHelper.safeGetInt(data, "timeshift"), - eventTime.getTime() - ); - NSUpload.uploadProfileSwitch(profileSwitch); - } else { - NSUpload.uploadCareportalEntryToNS(data); - } - } - @Override public void onSaveInstanceState(Bundle savedInstanceState) { savedInstanceState.putString("notesEdit", notesEdit.getText().toString()); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSUpload.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSUpload.java index c4fd7639a8..afda878640 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSUpload.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSUpload.java @@ -25,6 +25,7 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.DetailedBolusInfo; import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.data.Profile; +import info.nightscout.androidaps.data.ProfileStore; import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.db.DbRequest; @@ -39,9 +40,11 @@ import info.nightscout.androidaps.plugins.aps.loop.DeviceStatus; import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin; import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.configBuilder.PluginStore; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction; import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin; import info.nightscout.androidaps.utils.BatteryLevel; import info.nightscout.androidaps.utils.DateUtil; +import info.nightscout.androidaps.utils.JsonHelper; import info.nightscout.androidaps.utils.SP; /** @@ -463,6 +466,22 @@ public class NSUpload { } + public static void createNSTreatment(JSONObject data, ProfileStore profileStore, ProfileFunction profileFunction, long eventTime) { + if (JsonHelper.safeGetString(data, "eventType", "").equals(CareportalEvent.PROFILESWITCH)) { + ProfileSwitch profileSwitch = profileFunction.prepareProfileSwitch( + profileStore, + JsonHelper.safeGetString(data, "profile"), + JsonHelper.safeGetInt(data, "duration"), + JsonHelper.safeGetInt(data, "percentage"), + JsonHelper.safeGetInt(data, "timeshift"), + eventTime + ); + uploadProfileSwitch(profileSwitch); + } else { + uploadCareportalEntryToNS(data); + } + } + public static boolean isIdValid(String _id) { if (_id == null) return false; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityAAPSPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityAAPSPlugin.java index 9fa8aeed93..cd10ea6088 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityAAPSPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityAAPSPlugin.java @@ -115,7 +115,7 @@ public class SensitivityAAPSPlugin extends AbstractSensitivityPlugin { } // reset deviations after profile switch - if (ProfileSwitch.isEvent5minBack(profileSwitches, autosensData.time, true)) { + if (ProfileSwitch.isEvent5minBack(getAapsLogger(), profileSwitches, autosensData.time, true)) { deviationsArray.clear(); pastSensitivity += "(PROFILESWITCH)"; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityOref0Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityOref0Plugin.java index bdbc8e1697..423be4f548 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityOref0Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityOref0Plugin.java @@ -107,7 +107,7 @@ public class SensitivityOref0Plugin extends AbstractSensitivityPlugin { } // reset deviations after profile switch - if (ProfileSwitch.isEvent5minBack(profileSwitches, autosensData.time, true)) { + if (ProfileSwitch.isEvent5minBack(getAapsLogger(), profileSwitches, autosensData.time, true)) { deviationsArray.clear(); pastSensitivity += "(PROFILESWITCH)"; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityOref1Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityOref1Plugin.java index f5c6d05bfc..778129715c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityOref1Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityOref1Plugin.java @@ -106,7 +106,7 @@ public class SensitivityOref1Plugin extends AbstractSensitivityPlugin { } // reset deviations after profile switch - if (ProfileSwitch.isEvent5minBack(profileSwitches, autosensData.time, true)) { + if (ProfileSwitch.isEvent5minBack(getAapsLogger(), profileSwitches, autosensData.time, true)) { deviationsArray.clear(); pastSensitivity += "(PROFILESWITCH)"; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityWeightedAveragePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityWeightedAveragePlugin.java index d42ac85436..5a00a47461 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityWeightedAveragePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityWeightedAveragePlugin.java @@ -117,7 +117,7 @@ public class SensitivityWeightedAveragePlugin extends AbstractSensitivityPlugin } // reset deviations after profile switch - if (ProfileSwitch.isEvent5minBack(profileSwitches, autosensData.time, true)) { + if (ProfileSwitch.isEvent5minBack(getAapsLogger(), profileSwitches, autosensData.time, true)) { data.clear(); pastSensitivity += "(PROFILESWITCH)"; } 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 41c306b743..e1338887ac 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 @@ -731,7 +731,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface public void doProfileSwitch(final int duration, final int percentage, final int timeShift) { ProfileSwitch profileSwitch = treatmentsPlugin.getProfileSwitchFromHistory(System.currentTimeMillis()); if (profileSwitch != null) { - profileSwitch = new ProfileSwitch(); + profileSwitch = new ProfileSwitch(getInjector()); profileSwitch.date = System.currentTimeMillis(); profileSwitch.source = Source.USER; profileSwitch.profileName = profileFunction.getProfileName(System.currentTimeMillis(), false, false); diff --git a/app/src/test/java/info/nightscout/androidaps/TestBase.kt b/app/src/test/java/info/nightscout/androidaps/TestBase.kt index d6a973abae..9455dea294 100644 --- a/app/src/test/java/info/nightscout/androidaps/TestBase.kt +++ b/app/src/test/java/info/nightscout/androidaps/TestBase.kt @@ -13,19 +13,6 @@ import org.mockito.junit.MockitoRule import java.util.* open class TestBase { - val 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\"}" - val validProfile: Profile = Profile(HasAndroidInjector { AndroidInjector { Unit } }, JSONObject(validProfileJSON), Constants.MGDL) - val TESTPROFILENAME = "someProfile" - - fun getValidProfileStore(): ProfileStore { - val json = JSONObject() - val store = JSONObject() - store.put(TESTPROFILENAME, JSONObject(validProfileJSON)) - json.put("defaultProfile", TESTPROFILENAME) - json.put("store", store) - return ProfileStore(HasAndroidInjector { AndroidInjector { Unit } }, json) - } - // 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 diff --git a/app/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt b/app/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt new file mode 100644 index 0000000000..e88bb92616 --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt @@ -0,0 +1,60 @@ +package info.nightscout.androidaps + +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.data.Profile +import info.nightscout.androidaps.data.ProfileStore +import info.nightscout.androidaps.db.ProfileSwitch +import info.nightscout.androidaps.interfaces.ActivePluginProvider +import info.nightscout.androidaps.logging.AAPSLogger +import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin +import info.nightscout.androidaps.utils.resources.ResourceHelper +import org.json.JSONObject +import org.junit.Before +import org.mockito.Mock + +open class TestBaseWithProfile : TestBase() { + @Mock lateinit var aapsLogger: AAPSLogger + @Mock lateinit var activePluginProvider: ActivePluginProvider + @Mock lateinit var resourceHelper: ResourceHelper + @Mock lateinit var treatmentsPlugin :TreatmentsPlugin + + val rxBus = RxBusWrapper() + + val profileInjector = HasAndroidInjector { + AndroidInjector { + if (it is Profile) { + it.aapsLogger = aapsLogger + it.activePlugin = activePluginProvider + it.resourceHelper = resourceHelper + it.rxBus = rxBus + } + if (it is ProfileSwitch) { + it.treatmentsPlugin = treatmentsPlugin + it.aapsLogger = aapsLogger + it.rxBus = rxBus + it.resourceHelper = resourceHelper + } + } + } + + lateinit var validProfileJSON : String + lateinit var validProfile: Profile + val TESTPROFILENAME = "someProfile" + + @Before + fun prepareMock() { + 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/data/NonOverapingIntervalsTest.java b/app/src/test/java/info/nightscout/androidaps/data/NonOverapingIntervalsTest.java deleted file mode 100644 index a1f2a95943..0000000000 --- a/app/src/test/java/info/nightscout/androidaps/data/NonOverapingIntervalsTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package info.nightscout.androidaps.data; - -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.modules.junit4.PowerMockRunner; - -import info.nightscout.androidaps.db.TemporaryBasal; -import info.nightscout.androidaps.utils.DateUtil; -import info.nightscout.androidaps.utils.T; - -/** - * Created by mike on 26.03.2018. - */ - -@RunWith(PowerMockRunner.class) -public class NonOverapingIntervalsTest { - - private final long startDate = DateUtil.now(); - NonOverlappingIntervals list = new NonOverlappingIntervals<>(); - - @Test - public void doTests() { - // create one 10h interval and test value in and out - list.add(new TemporaryBasal().date(startDate).duration((int) T.hours(10).mins()).absolute(1)); - Assert.assertEquals(null, list.getValueByInterval(startDate - T.secs(1).msecs())); - Assert.assertEquals(1d, list.getValueByInterval(startDate).absoluteRate, 0.01d); - Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(10).msecs() + 1)); - - // stop temp after 5h - list.add(new TemporaryBasal().date(startDate + T.hours(5).msecs()).duration(0)); - Assert.assertEquals(null, list.getValueByInterval(startDate - T.secs(1).msecs())); - Assert.assertEquals(1d, list.getValueByInterval(startDate).absoluteRate, 0.01d); - Assert.assertEquals(1d, list.getValueByInterval(startDate + T.hours(5).msecs() - 1).absoluteRate, 0.01d); - Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(5).msecs() + 1)); - Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(10).msecs() + 1)); - - // insert 1h interval inside - list.add(new TemporaryBasal().date(startDate + T.hours(3).msecs()).duration((int) T.hours(1).mins()).absolute(2)); - Assert.assertEquals(null, list.getValueByInterval(startDate - T.secs(1).msecs())); - Assert.assertEquals(1d, list.getValueByInterval(startDate).absoluteRate, 0.01d); - Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(5).msecs() - 1)); - Assert.assertEquals(2d, list.getValueByInterval(startDate + T.hours(3).msecs()).absoluteRate, 0.01d); - Assert.assertEquals(2d, list.getValueByInterval(startDate + T.hours(4).msecs() - 1).absoluteRate, 0.01d); - Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(4).msecs() + 1)); - Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(10).msecs() + 1)); - } - - @Test - public void testCopyConstructor() { - list.reset(); - list.add(new TemporaryBasal().date(startDate).duration((int) T.hours(10).mins()).absolute(1)); - NonOverlappingIntervals list2 = new NonOverlappingIntervals<>(list); - Assert.assertEquals(1, list2.getList().size()); - } - - -} diff --git a/app/src/test/java/info/nightscout/androidaps/data/NonOverlappingIntervalsTest.kt b/app/src/test/java/info/nightscout/androidaps/data/NonOverlappingIntervalsTest.kt new file mode 100644 index 0000000000..7a915e9e13 --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/data/NonOverlappingIntervalsTest.kt @@ -0,0 +1,51 @@ +package info.nightscout.androidaps.data + +import info.nightscout.androidaps.db.TemporaryBasal +import info.nightscout.androidaps.utils.DateUtil +import info.nightscout.androidaps.utils.T +import org.junit.Assert +import org.junit.Test +import org.junit.runner.RunWith +import org.powermock.modules.junit4.PowerMockRunner + +@RunWith(PowerMockRunner::class) +class NonOverlappingIntervalsTest { + + private val startDate = DateUtil.now() + var list = NonOverlappingIntervals() + + @Test + fun doTests() { + // create one 10h interval and test value in and out + list.add(TemporaryBasal().date(startDate).duration(T.hours(10).mins().toInt()).absolute(1.0)) + Assert.assertEquals(null, list.getValueByInterval(startDate - T.secs(1).msecs())) + Assert.assertEquals(1.0, list.getValueByInterval(startDate)!!.absoluteRate, 0.01) + Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(10).msecs() + 1)) + + // stop temp after 5h + list.add(TemporaryBasal().date(startDate + T.hours(5).msecs()).duration(0)) + Assert.assertEquals(null, list.getValueByInterval(startDate - T.secs(1).msecs())) + Assert.assertEquals(1.0, list.getValueByInterval(startDate)!!.absoluteRate, 0.01) + Assert.assertEquals(1.0, list.getValueByInterval(startDate + T.hours(5).msecs() - 1)!!.absoluteRate, 0.01) + Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(5).msecs() + 1)) + Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(10).msecs() + 1)) + + // insert 1h interval inside + list.add(TemporaryBasal().date(startDate + T.hours(3).msecs()).duration(T.hours(1).mins().toInt()).absolute(2.0)) + Assert.assertEquals(null, list.getValueByInterval(startDate - T.secs(1).msecs())) + Assert.assertEquals(1.0, list.getValueByInterval(startDate)!!.absoluteRate, 0.01) + Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(5).msecs() - 1)) + Assert.assertEquals(2.0, list.getValueByInterval(startDate + T.hours(3).msecs())!!.absoluteRate, 0.01) + Assert.assertEquals(2.0, list.getValueByInterval(startDate + T.hours(4).msecs() - 1)!!.absoluteRate, 0.01) + Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(4).msecs() + 1)) + Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(10).msecs() + 1)) + } + + @Test + fun testCopyConstructor() { + list.reset() + list.add(TemporaryBasal().date(startDate).duration(T.hours(10).mins().toInt()).absolute(1.0)) + val list2 = NonOverlappingIntervals(list) + Assert.assertEquals(1, list2.list.size.toLong()) + } +} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/data/OverapingIntervalsTest.java b/app/src/test/java/info/nightscout/androidaps/data/OverapingIntervalsTest.java deleted file mode 100644 index 80ad43999e..0000000000 --- a/app/src/test/java/info/nightscout/androidaps/data/OverapingIntervalsTest.java +++ /dev/null @@ -1,72 +0,0 @@ -package info.nightscout.androidaps.data; - -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.modules.junit4.PowerMockRunner; - -import java.util.ArrayList; -import java.util.List; - -import info.nightscout.androidaps.db.TempTarget; -import info.nightscout.androidaps.utils.DateUtil; -import info.nightscout.androidaps.utils.T; - -/** - * Created by mike on 26.03.2018. - */ - -@RunWith(PowerMockRunner.class) -public class OverapingIntervalsTest { - - private final long startDate = DateUtil.now(); - OverlappingIntervals list = new OverlappingIntervals<>(); - - @Test - public void doTests() { - // create one 10h interval and test value in and out - list.add(new TempTarget().date(startDate).duration((int) T.hours(10).mins()).low(100).high(100)); - Assert.assertEquals(null, list.getValueByInterval(startDate - T.secs(1).msecs())); - Assert.assertEquals(100d, list.getValueByInterval(startDate).target(), 0.01d); - Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(10).msecs() + 1)); - - // stop temp target after 5h - list.add(new TempTarget().date(startDate + T.hours(5).msecs()).duration(0)); - Assert.assertEquals(null, list.getValueByInterval(startDate - T.secs(1).msecs())); - Assert.assertEquals(100d, list.getValueByInterval(startDate).target(), 0.01d); - Assert.assertEquals(100d, list.getValueByInterval(startDate + T.hours(5).msecs() - 1).target(), 0.01d); - Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(5).msecs() + 1)); - Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(10).msecs() + 1)); - - // insert 1h interval inside - list.add(new TempTarget().date(startDate + T.hours(3).msecs()).duration((int) T.hours(1).mins()).low(200).high(200)); - Assert.assertEquals(null, list.getValueByInterval(startDate - T.secs(1).msecs())); - Assert.assertEquals(100d, list.getValueByInterval(startDate).target(), 0.01d); - Assert.assertEquals(100d, list.getValueByInterval(startDate + T.hours(5).msecs() - 1).target(), 0.01d); - Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(5).msecs() + 1)); - Assert.assertEquals(200d, list.getValueByInterval(startDate + T.hours(3).msecs()).target(), 0.01d); - Assert.assertEquals(100d, list.getValueByInterval(startDate + T.hours(4).msecs() + 1).target(), 0.01d); - Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(10).msecs() + 1)); - } - - @Test - public void testCopyConstructor() { - list.reset(); - list.add(new TempTarget().date(startDate).duration((int) T.hours(10).mins()).low(100).high(100)); - OverlappingIntervals list2 = new OverlappingIntervals<>(list); - Assert.assertEquals(1, list2.getList().size()); - } - - @Test - public void testReversingArrays() { - List someList = new ArrayList<>(); - someList.add(new TempTarget().date(startDate).duration((int) T.hours(3).mins()).low(200).high(200)); - someList.add(new TempTarget().date(startDate + T.hours(1).msecs()).duration((int) T.hours(1).mins()).low(100).high(100)); - list.reset(); - list.add(someList); - Assert.assertEquals(startDate, list.get(0).date); - Assert.assertEquals(startDate + T.hours(1).msecs(), list.getReversed(0).date); - Assert.assertEquals(startDate + T.hours(1).msecs(), list.getReversedList().get(0).date); - - } -} diff --git a/app/src/test/java/info/nightscout/androidaps/data/OverlappingIntervalsTest.kt b/app/src/test/java/info/nightscout/androidaps/data/OverlappingIntervalsTest.kt new file mode 100644 index 0000000000..70b2bb896a --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/data/OverlappingIntervalsTest.kt @@ -0,0 +1,60 @@ +package info.nightscout.androidaps.data + +import info.nightscout.androidaps.db.TempTarget +import info.nightscout.androidaps.utils.DateUtil +import info.nightscout.androidaps.utils.T +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 OverlappingIntervalsTest { + + private val startDate = DateUtil.now() + var list = OverlappingIntervals() + @Test fun doTests() { + // create one 10h interval and test value in and out + list.add(TempTarget().date(startDate).duration(T.hours(10).mins().toInt()).low(100.0).high(100.0)) + Assert.assertEquals(null, list.getValueByInterval(startDate - T.secs(1).msecs())) + Assert.assertEquals(100.0, list.getValueByInterval(startDate)!!.target(), 0.01) + Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(10).msecs() + 1)) + + // stop temp target after 5h + list.add(TempTarget().date(startDate + T.hours(5).msecs()).duration(0)) + Assert.assertEquals(null, list.getValueByInterval(startDate - T.secs(1).msecs())) + Assert.assertEquals(100.0, list.getValueByInterval(startDate)!!.target(), 0.01) + Assert.assertEquals(100.0, list.getValueByInterval(startDate + T.hours(5).msecs() - 1)!!.target(), 0.01) + Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(5).msecs() + 1)) + Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(10).msecs() + 1)) + + // insert 1h interval inside + list.add(TempTarget().date(startDate + T.hours(3).msecs()).duration(T.hours(1).mins().toInt()).low(200.0).high(200.0)) + Assert.assertEquals(null, list.getValueByInterval(startDate - T.secs(1).msecs())) + Assert.assertEquals(100.0, list.getValueByInterval(startDate)!!.target(), 0.01) + Assert.assertEquals(100.0, list.getValueByInterval(startDate + T.hours(5).msecs() - 1)!!.target(), 0.01) + Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(5).msecs() + 1)) + Assert.assertEquals(200.0, list.getValueByInterval(startDate + T.hours(3).msecs())!!.target(), 0.01) + Assert.assertEquals(100.0, list.getValueByInterval(startDate + T.hours(4).msecs() + 1)!!.target(), 0.01) + Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(10).msecs() + 1)) + } + + @Test fun testCopyConstructor() { + list.reset() + list.add(TempTarget().date(startDate).duration(T.hours(10).mins().toInt()).low(100.0).high(100.0)) + val list2 = OverlappingIntervals(list) + Assert.assertEquals(1, list2.list.size.toLong()) + } + + @Test fun testReversingArrays() { + val someList: MutableList = ArrayList() + someList.add(TempTarget().date(startDate).duration(T.hours(3).mins().toInt()).low(200.0).high(200.0)) + someList.add(TempTarget().date(startDate + T.hours(1).msecs()).duration(T.hours(1).mins().toInt()).low(100.0).high(100.0)) + list.reset() + list.add(someList) + Assert.assertEquals(startDate, list[0].date) + Assert.assertEquals(startDate + T.hours(1).msecs(), list.getReversed(0).date) + Assert.assertEquals(startDate + T.hours(1).msecs(), list.reversedList[0].date) + } +} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/data/ProfileIntervalsTest.java b/app/src/test/java/info/nightscout/androidaps/data/ProfileIntervalsTest.java deleted file mode 100644 index 121af322f7..0000000000 --- a/app/src/test/java/info/nightscout/androidaps/data/ProfileIntervalsTest.java +++ /dev/null @@ -1,95 +0,0 @@ -package info.nightscout.androidaps.data; - -import org.junit.Assert; -import org.junit.Before; -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.ArrayList; -import java.util.List; - -import info.AAPSMocker; -import info.nightscout.androidaps.MainApp; -import info.nightscout.androidaps.db.ProfileSwitch; -import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.treatments.TreatmentService; -import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; -import info.nightscout.androidaps.utils.DateUtil; -import info.nightscout.androidaps.utils.T; - -/** - * Created by mike on 26.03.2018. - */ - -@RunWith(PowerMockRunner.class) -@PrepareForTest({MainApp.class, ConfigBuilderPlugin.class, TreatmentsPlugin.class, TreatmentService.class}) -public class ProfileIntervalsTest { - private final long startDate = DateUtil.now(); - ProfileIntervals list = new ProfileIntervals<>(); - - @Test - public void doTests() { - // create one 10h interval and test value in and out - list.add(new ProfileSwitch().date(startDate).duration((int) T.hours(10).mins()).profileName("1").profile(AAPSMocker.getValidProfile())); - // for older date first record should be returned only if has zero duration - Assert.assertEquals(null, list.getValueToTime(startDate - T.secs(1).msecs())); - Assert.assertEquals("1", ((ProfileSwitch) list.getValueToTime(startDate)).profileName); - Assert.assertEquals(null, list.getValueToTime(startDate + T.hours(10).msecs() + 1)); - - list.reset(); - list.add(new ProfileSwitch().date(startDate).profileName("1").profile(AAPSMocker.getValidProfile())); - Assert.assertEquals("1", ((ProfileSwitch) list.getValueToTime(startDate - T.secs(1).msecs())).profileName); - Assert.assertEquals("1", ((ProfileSwitch) list.getValueToTime(startDate)).profileName); - Assert.assertEquals("1", ((ProfileSwitch) list.getValueToTime(startDate + T.hours(10).msecs() + 1)).profileName); - - // switch to different profile after 5h - list.add(new ProfileSwitch().date(startDate + T.hours(5).msecs()).duration(0).profileName("2").profile(AAPSMocker.getValidProfile())); - Assert.assertEquals("1", ((ProfileSwitch) list.getValueToTime(startDate - T.secs(1).msecs())).profileName); - Assert.assertEquals("1", ((ProfileSwitch) list.getValueToTime(startDate + T.hours(5).msecs() - 1)).profileName); - Assert.assertEquals("2", ((ProfileSwitch) list.getValueToTime(startDate + T.hours(5).msecs() + 1)).profileName); - - // insert 1h interval inside - list.add(new ProfileSwitch().date(startDate + T.hours(6).msecs()).duration((int) T.hours(1).mins()).profileName("3").profile(AAPSMocker.getValidProfile())); - Assert.assertEquals("2", ((ProfileSwitch) list.getValueToTime(startDate + T.hours(6).msecs() - 1)).profileName); - Assert.assertEquals("3", ((ProfileSwitch) list.getValueToTime(startDate + T.hours(6).msecs() + 1)).profileName); - Assert.assertEquals("2", ((ProfileSwitch) list.getValueToTime(startDate + T.hours(7).msecs() + 1)).profileName); - } - - @Test - public void testCopyConstructor() { - list.reset(); - list.add(new ProfileSwitch().date(startDate).duration((int) T.hours(10).mins()).profileName("4").profile(AAPSMocker.getValidProfile())); - ProfileIntervals list2 = new ProfileIntervals<>(list); - Assert.assertEquals(1, list2.getList().size()); - } - - @Test - public void invalidProfilesShouldNotBeReturned() { - list.reset(); - list.add(new ProfileSwitch().date(startDate + T.hours(1).msecs()).profileName("6")); - Assert.assertEquals(null, list.get(0)); - } - - @Test - public void testReversingArrays() { - List someList = new ArrayList<>(); - someList.add(new ProfileSwitch().date(startDate).duration((int) T.hours(3).mins()).profileName("5").profile(AAPSMocker.getValidProfile())); - someList.add(new ProfileSwitch().date(startDate + T.hours(1).msecs()).duration((int) T.hours(1).mins()).profileName("6").profile(AAPSMocker.getValidProfile())); - list.reset(); - list.add(someList); - Assert.assertEquals(startDate, list.get(0).date); - Assert.assertEquals(startDate + T.hours(1).msecs(), list.getReversed(0).date); - Assert.assertEquals(startDate + T.hours(1).msecs(), list.getReversedList().get(0).date); - - } - - @Before - public void prepareMock() { - AAPSMocker.mockMainApp(); - AAPSMocker.mockStrings(); - AAPSMocker.mockConfigBuilder(); - AAPSMocker.mockTreatmentPlugin(); - } -} diff --git a/app/src/test/java/info/nightscout/androidaps/data/ProfileIntervalsTest.kt b/app/src/test/java/info/nightscout/androidaps/data/ProfileIntervalsTest.kt new file mode 100644 index 0000000000..06a0239767 --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/data/ProfileIntervalsTest.kt @@ -0,0 +1,90 @@ +package info.nightscout.androidaps.data + +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.TestBaseWithProfile +import info.nightscout.androidaps.db.ProfileSwitch +import info.nightscout.androidaps.interfaces.PumpDescription +import info.nightscout.androidaps.logging.AAPSLogger +import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin +import info.nightscout.androidaps.utils.DateUtil +import info.nightscout.androidaps.utils.T +import info.nightscout.androidaps.utils.resources.ResourceHelper +import org.junit.Assert +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.Mock +import org.mockito.Mockito.`when` +import org.powermock.core.classloader.annotations.PrepareForTest +import org.powermock.modules.junit4.PowerMockRunner +import java.util.* + +@RunWith(PowerMockRunner::class) +@PrepareForTest(VirtualPumpPlugin::class) +class ProfileIntervalsTest : TestBaseWithProfile() { + + @Mock lateinit var virtualPumpPlugin: VirtualPumpPlugin + + private val startDate = DateUtil.now() + var list = ProfileIntervals() + + @Before + fun mock() { + `when`(activePluginProvider.activePump).thenReturn(virtualPumpPlugin) + `when`(virtualPumpPlugin.pumpDescription).thenReturn(PumpDescription()) + } + @Test + fun doTests() { + // create one 10h interval and test value in and out + list.add(ProfileSwitch(profileInjector).date(startDate).duration(T.hours(10).mins().toInt()).profileName("1").profile(validProfile)) + // for older date first record should be returned only if has zero duration + Assert.assertEquals(null, list.getValueToTime(startDate - T.secs(1).msecs())) + Assert.assertEquals("1", (list.getValueToTime(startDate) as ProfileSwitch?)!!.profileName) + Assert.assertEquals(null, list.getValueToTime(startDate + T.hours(10).msecs() + 1)) + list.reset() + list.add(ProfileSwitch(profileInjector).date(startDate).profileName("1").profile(validProfile)) + Assert.assertEquals("1", (list.getValueToTime(startDate - T.secs(1).msecs()) as ProfileSwitch?)!!.profileName) + Assert.assertEquals("1", (list.getValueToTime(startDate) as ProfileSwitch?)!!.profileName) + Assert.assertEquals("1", (list.getValueToTime(startDate + T.hours(10).msecs() + 1) as ProfileSwitch?)!!.profileName) + + // switch to different profile after 5h + list.add(ProfileSwitch(profileInjector).date(startDate + T.hours(5).msecs()).duration(0).profileName("2").profile(validProfile)) + Assert.assertEquals("1", (list.getValueToTime(startDate - T.secs(1).msecs()) as ProfileSwitch?)!!.profileName) + Assert.assertEquals("1", (list.getValueToTime(startDate + T.hours(5).msecs() - 1) as ProfileSwitch?)!!.profileName) + Assert.assertEquals("2", (list.getValueToTime(startDate + T.hours(5).msecs() + 1) as ProfileSwitch?)!!.profileName) + + // insert 1h interval inside + list.add(ProfileSwitch(profileInjector).date(startDate + T.hours(6).msecs()).duration(T.hours(1).mins().toInt()).profileName("3").profile(validProfile)) + Assert.assertEquals("2", (list.getValueToTime(startDate + T.hours(6).msecs() - 1) as ProfileSwitch?)!!.profileName) + Assert.assertEquals("3", (list.getValueToTime(startDate + T.hours(6).msecs() + 1) as ProfileSwitch?)!!.profileName) + Assert.assertEquals("2", (list.getValueToTime(startDate + T.hours(7).msecs() + 1) as ProfileSwitch?)!!.profileName) + } + + @Test + fun testCopyConstructor() { + list.reset() + list.add(ProfileSwitch(profileInjector).date(startDate).duration(T.hours(10).mins().toInt()).profileName("4").profile(validProfile)) + val list2 = ProfileIntervals(list) + Assert.assertEquals(1, list2.list.size.toLong()) + } + + @Test fun invalidProfilesShouldNotBeReturned() { + list.reset() + list.add(ProfileSwitch(profileInjector).date(startDate + T.hours(1).msecs()).profileName("6")) + Assert.assertEquals(null, list[0]) + } + + @Test fun testReversingArrays() { + val someList: MutableList = ArrayList() + someList.add(ProfileSwitch(profileInjector).date(startDate).duration(T.hours(3).mins().toInt()).profileName("5").profile(validProfile)) + someList.add(ProfileSwitch(profileInjector).date(startDate + T.hours(1).msecs()).duration(T.hours(1).mins().toInt()).profileName("6").profile(validProfile)) + list.reset() + list.add(someList) + Assert.assertEquals(startDate, list[0].date) + Assert.assertEquals(startDate + T.hours(1).msecs(), list.getReversed(0).date) + Assert.assertEquals(startDate + T.hours(1).msecs(), list.reversedList[0].date) + } +} \ No newline at end of file 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 1f64a1311a..06a6f85dbd 100644 --- a/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt @@ -3,9 +3,9 @@ package info.nightscout.androidaps.interfaces import android.content.Context import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.TestBase import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.R +import info.nightscout.androidaps.TestBaseWithProfile import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAPlugin import info.nightscout.androidaps.plugins.aps.openAPSMA.OpenAPSMAPlugin @@ -48,15 +48,12 @@ import java.util.* */ @RunWith(PowerMockRunner::class) @PrepareForTest(MainApp::class, ConfigBuilderPlugin::class, ConstraintChecker::class, SP::class, Context::class, OpenAPSMAPlugin::class, OpenAPSAMAPlugin::class, OpenAPSSMBPlugin::class, TreatmentsPlugin::class, TreatmentService::class, VirtualPumpPlugin::class, DetailedBolusInfoStorage::class, GlimpPlugin::class) -class ConstraintsCheckerTest : TestBase() { +class ConstraintsCheckerTest : TestBaseWithProfile() { - @Mock lateinit var aapsLogger: AAPSLogger - @Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var activePlugin: ActivePluginProvider @Mock lateinit var virtualPumpPlugin: VirtualPumpPlugin @Mock lateinit var sp: SP @Mock lateinit var profileFunction: ProfileFunction - @Mock lateinit var treatmentsPlugin: TreatmentsPlugin @Mock lateinit var commandQueue: CommandQueueProvider @Mock lateinit var detailedBolusInfoStorage: DetailedBolusInfoStorage @Mock lateinit var context: Context @@ -64,7 +61,6 @@ class ConstraintsCheckerTest : TestBase() { @Mock lateinit var glimpPlugin: GlimpPlugin @Mock lateinit var sensitivityOref1Plugin: SensitivityOref1Plugin - val rxBus = RxBusWrapper() private var buildHelper = BuildHelper() lateinit var danaRPump: DanaRPump @@ -89,7 +85,7 @@ class ConstraintsCheckerTest : TestBase() { } @Before - fun prepareMock() { + fun prepare() { `when`(resourceHelper.gs(R.string.closed_loop_disabled_on_dev_branch)).thenReturn("Running dev version. Closed loop is disabled.") `when`(resourceHelper.gs(R.string.closedmodedisabledinpreferences)).thenReturn("Closed loop mode disabled in preferences") `when`(resourceHelper.gs(R.string.objectivenotstarted)).thenReturn("Objective %d not started") 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 167941eb9f..5db025db4c 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 @@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.aps.loop import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector import info.nightscout.androidaps.TestBase +import info.nightscout.androidaps.TestBaseWithProfile import info.nightscout.androidaps.db.TemporaryBasal import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.Constraint @@ -28,16 +29,13 @@ import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) @PrepareForTest(ConstraintChecker::class, VirtualPumpPlugin::class) -class APSResultTest : TestBase() { +class APSResultTest : TestBaseWithProfile() { - @Mock lateinit var aapsLogger: AAPSLogger @Mock lateinit var constraintChecker: ConstraintChecker @Mock lateinit var sp: SP - @Mock lateinit var activePluginProvider: ActivePluginProvider - @Mock lateinit var treatmentsPlugin: TreatmentsPlugin @Mock lateinit var profileFunction: ProfileFunction - @Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var virtualPumpPlugin: VirtualPumpPlugin + private var closedLoopEnabled = Constraint(false) private val pumpDescription = PumpDescription() @@ -199,7 +197,7 @@ class APSResultTest : TestBase() { } @Before - fun prepareMock() { + fun prepare() { `when`(constraintChecker.isClosedLoopAllowed()).thenReturn(closedLoopEnabled) `when`(activePluginProvider.activePump).thenReturn(virtualPumpPlugin) `when`(sp.getDouble(ArgumentMatchers.anyInt(), ArgumentMatchers.anyDouble())).thenReturn(30.0) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionNotificationTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionNotificationTest.kt index c45a07bc71..b9d9c35900 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionNotificationTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionNotificationTest.kt @@ -1,14 +1,22 @@ package info.nightscout.androidaps.plugins.general.automation.actions +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector import info.nightscout.androidaps.R +import info.nightscout.androidaps.TestBase +import info.nightscout.androidaps.data.PumpEnactResult +import info.nightscout.androidaps.logging.AAPSLogger +import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.general.automation.elements.InputString import info.nightscout.androidaps.plugins.general.nsclient.NSUpload import info.nightscout.androidaps.queue.Callback +import info.nightscout.androidaps.utils.resources.ResourceHelper import org.junit.Assert import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.mockito.ArgumentMatchers +import org.mockito.Mock import org.mockito.Mockito import org.mockito.Mockito.`when` import org.powermock.api.mockito.PowerMockito @@ -16,14 +24,31 @@ import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest(NSUpload::class) -class ActionNotificationTest : ActionsTestBase() { +@PrepareForTest(NSUpload::class, RxBusWrapper::class) +class ActionNotificationTest : TestBase() { + + @Mock lateinit var aapsLogger: AAPSLogger + @Mock lateinit var resourceHelper: ResourceHelper + @Mock lateinit var rxBus: RxBusWrapper private lateinit var sut: ActionNotification + var injector: HasAndroidInjector = HasAndroidInjector { + AndroidInjector { + if (it is ActionNotification) { + it.resourceHelper = resourceHelper + it.rxBus = rxBus + } + if (it is PumpEnactResult) { + it.aapsLogger = aapsLogger + it.resourceHelper = resourceHelper + } + } + } @Before fun setup() { PowerMockito.mockStatic(NSUpload::class.java) + `when`(resourceHelper.gs(R.string.ok)).thenReturn("OK") `when`(resourceHelper.gs(R.string.notification)).thenReturn("Notification") `when`(resourceHelper.gs(ArgumentMatchers.eq(R.string.notification_message), ArgumentMatchers.anyString())).thenReturn("Notification: %s") diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionsTestBase.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionsTestBase.kt index 6757916655..1afef7136c 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionsTestBase.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionsTestBase.kt @@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.general.automation.actions import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector import info.nightscout.androidaps.TestBase +import info.nightscout.androidaps.TestBaseWithProfile import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.CommandQueueProvider @@ -21,16 +22,12 @@ import org.mockito.Mock import org.powermock.core.classloader.annotations.PrepareForTest @PrepareForTest(VirtualPumpPlugin::class, RxBusWrapper::class, LocalProfilePlugin::class, SmsCommunicatorPlugin::class) -open class ActionsTestBase : TestBase() { +open class ActionsTestBase : TestBaseWithProfile() { - @Mock lateinit var aapsLogger: AAPSLogger - @Mock lateinit var rxBus: RxBusWrapper @Mock lateinit var sp: SP - @Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var commandQueue: CommandQueueProvider @Mock lateinit var configBuilderPlugin: ConfigBuilderPlugin @Mock lateinit var virtualPumpPlugin: VirtualPumpPlugin - @Mock lateinit var treatmentsPlugin: TreatmentsPlugin @Mock lateinit var loopPlugin: LoopPlugin @Mock lateinit var activePlugin: ActivePluginProvider @Mock lateinit var profileFunction: ProfileFunction 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 1d6d91b460..221a1989ab 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 @@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.general.automation.triggers import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector import info.nightscout.androidaps.TestBase +import info.nightscout.androidaps.TestBaseWithProfile import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.plugins.bus.RxBusWrapper @@ -19,14 +20,11 @@ import org.mockito.Mock import org.powermock.core.classloader.annotations.PrepareForTest @PrepareForTest(LastLocationDataContainer::class) -open class TriggerTestBase : TestBase() { +open class TriggerTestBase : TestBaseWithProfile() { - @Mock lateinit var aapsLogger: AAPSLogger - @Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var profileFunction: ProfileFunction @Mock lateinit var sp: SP @Mock lateinit var locationDataContainer: LastLocationDataContainer - @Mock lateinit var treatmentsPlugin: TreatmentsPlugin @Mock lateinit var activePlugin: ActivePluginProvider @Mock lateinit var iobCobCalculatorPlugin: IobCobCalculatorPlugin diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/careportal/Dialogs/NewNSTreatmentDialogTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/general/careportal/Dialogs/NewNSTreatmentDialogTest.java deleted file mode 100644 index 11f01d2486..0000000000 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/careportal/Dialogs/NewNSTreatmentDialogTest.java +++ /dev/null @@ -1,86 +0,0 @@ -package info.nightscout.androidaps.plugins.general.careportal.Dialogs; - -import android.content.Context; - -import org.json.JSONObject; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.ArgumentMatchers; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - -import java.util.Date; - -import info.AAPSMocker; -import info.SPMocker; -import info.nightscout.androidaps.MainApp; -import info.nightscout.androidaps.R; -import info.nightscout.androidaps.db.CareportalEvent; -import info.nightscout.androidaps.db.DatabaseHelper; -import info.nightscout.androidaps.db.ProfileSwitch; -import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.profile.ns.NSProfilePlugin; -import info.nightscout.androidaps.plugins.treatments.TreatmentService; -import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; -import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; -import info.nightscout.androidaps.utils.SP; - -import static info.nightscout.androidaps.plugins.general.careportal.CareportalFragment.PROFILESWITCH; -import static org.powermock.api.mockito.PowerMockito.doAnswer; -import static org.powermock.api.mockito.PowerMockito.when; - -@RunWith(PowerMockRunner.class) -@PrepareForTest({SP.class, MainApp.class, ConfigBuilderPlugin.class, Context.class, NSUpload.class, TreatmentsPlugin.class, TreatmentService.class, DatabaseHelper.class}) -public class NewNSTreatmentDialogTest { - - NewNSTreatmentDialog dialog; - ProfileSwitch profileSwitchUpload = null; - - @Test - public void createNSTreatmentTest() throws Exception { - // Test profile creation - doAnswer(invocation -> { - ProfileSwitch ps = invocation.getArgument(0); - profileSwitchUpload = ps; - return null; - }).when(NSUpload.class, "uploadProfileSwitch", ArgumentMatchers.any()); - dialog.setOptions(PROFILESWITCH, R.string.careportal_profileswitch); - dialog.profileStore = AAPSMocker.getValidProfileStore(); - dialog.eventTime = new Date(); - JSONObject data = new JSONObject(); - data.put("eventType", CareportalEvent.PROFILESWITCH); - data.put("profile", AAPSMocker.TESTPROFILENAME); - data.put("duration", 0); - data.put("percentage", 110); - data.put("timeshift", 0); - dialog.createNSTreatment(data); - - // Profile should be sent to NS - Assert.assertEquals(AAPSMocker.TESTPROFILENAME, profileSwitchUpload.profileName); - } - - @Before - public void prepareMock() throws Exception { - AAPSMocker.mockMainApp(); - SPMocker.prepareMock(); - SP.putString("profile", AAPSMocker.getValidProfileStore().getData().toString()); - AAPSMocker.mockConfigBuilder(); - AAPSMocker.mockApplicationContext(); - AAPSMocker.mockStrings(); - PowerMockito.mockStatic(NSUpload.class); - AAPSMocker.mockTreatmentService(); - AAPSMocker.mockDatabaseHelper(); - - NSProfilePlugin profilePlugin = NSProfilePlugin.getPlugin(); - when(ConfigBuilderPlugin.getPlugin().getActiveProfileInterface()) - .thenReturn(profilePlugin); - - dialog = new NewNSTreatmentDialog(); - - PowerMockito.spy(System.class); - when(System.currentTimeMillis()).thenReturn(1000L); - } -} \ No newline at end of file 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 baa2f68396..2f2dafcb87 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 @@ -3,10 +3,10 @@ package info.nightscout.androidaps.plugins.general.smsCommunicator import android.telephony.SmsManager import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.TestBase import info.nightscout.androidaps.Constants import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.R +import info.nightscout.androidaps.TestBaseWithProfile import info.nightscout.androidaps.data.IobTotal import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.db.BgReading @@ -14,7 +14,6 @@ import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.CommandQueueProvider import info.nightscout.androidaps.interfaces.Constraint import info.nightscout.androidaps.interfaces.PluginType -import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker @@ -33,7 +32,6 @@ import info.nightscout.androidaps.utils.DefaultValueHelper import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.T import info.nightscout.androidaps.utils.XdripCalibrations -import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP import org.junit.Assert import org.junit.Before @@ -52,13 +50,10 @@ import java.util.* @RunWith(PowerMockRunner::class) @PrepareForTest(ConstraintChecker::class, FabricPrivacy::class, VirtualPumpPlugin::class, XdripCalibrations::class, SmsManager::class, RxBusWrapper::class, CommandQueue::class, LocalProfilePlugin::class, DateUtil::class, IobCobCalculatorPlugin::class, MainApp::class) -class SmsCommunicatorPluginTest : TestBase() { +class SmsCommunicatorPluginTest : TestBaseWithProfile() { - @Mock lateinit var aapsLogger: AAPSLogger - @Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var sp: SP @Mock lateinit var constraintChecker: ConstraintChecker - lateinit var rxBus: RxBusWrapper @Mock lateinit var profileFunction: ProfileFunction @Mock lateinit var fabricPrivacy: FabricPrivacy @Mock lateinit var activePlugin: ActivePluginProvider @@ -68,7 +63,6 @@ class SmsCommunicatorPluginTest : TestBase() { @Mock lateinit var virtualPumpPlugin: VirtualPumpPlugin @Mock lateinit var defaultValueHelper: DefaultValueHelper @Mock lateinit var localProfilePlugin: LocalProfilePlugin - @Mock lateinit var treatmentsPlugin: TreatmentsPlugin @Mock lateinit var treatmentService: TreatmentService var injector: HasAndroidInjector = HasAndroidInjector { @@ -99,7 +93,6 @@ class SmsCommunicatorPluginTest : TestBase() { private var hasBeenRun = false @Before fun prepareTests() { - rxBus = RxBusWrapper() val reading = BgReading(injector) reading.value = 100.0 val bgList: MutableList = ArrayList() diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPluginTest.kt index e9fcfddb32..44ee4019c3 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/DanaRPluginTest.kt @@ -3,17 +3,14 @@ package info.nightscout.androidaps.plugins.pump.danaR import android.content.Context import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.TestBase import info.nightscout.androidaps.Constants import info.nightscout.androidaps.R +import info.nightscout.androidaps.TestBaseWithProfile import info.nightscout.androidaps.interfaces.CommandQueueProvider import info.nightscout.androidaps.interfaces.Constraint import info.nightscout.androidaps.interfaces.PluginType -import info.nightscout.androidaps.logging.AAPSLogger -import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin -import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP import org.junit.Assert import org.junit.Before @@ -26,17 +23,13 @@ import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) @PrepareForTest(SP::class, ConstraintChecker::class) -class DanaRPluginTest : TestBase() { +class DanaRPluginTest : TestBaseWithProfile() { - @Mock lateinit var aapsLogger: AAPSLogger @Mock lateinit var context: Context - @Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var constraintChecker: ConstraintChecker - @Mock lateinit var treatmentsPlugin: TreatmentsPlugin @Mock lateinit var sp: SP @Mock lateinit var commandQueue: CommandQueueProvider - val rxBus = RxBusWrapper() lateinit var danaRPump: DanaRPump private lateinit var danaRPlugin: DanaRPlugin diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MessageHashTableRTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MessageHashTableRTest.kt index 211e19cc7c..e2ad047b78 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MessageHashTableRTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MessageHashTableRTest.kt @@ -9,7 +9,6 @@ import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin -import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRSTestBase import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.utils.resources.ResourceHelper import org.junit.Assert @@ -22,7 +21,7 @@ import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) @PrepareForTest(ConstraintChecker::class, DetailedBolusInfoStorage::class) -class MessageHashTableRTest : DanaRSTestBase() { +class MessageHashTableRTest : DanaRTestBase() { @Mock lateinit var rxBus: RxBusWrapper @Mock lateinit var resourceHelper: ResourceHelper diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRKorean/DanaRKoreanPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRKorean/DanaRKoreanPluginTest.kt index fe2a1e32aa..5dd1c1a3b0 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRKorean/DanaRKoreanPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRKorean/DanaRKoreanPluginTest.kt @@ -3,18 +3,15 @@ package info.nightscout.androidaps.plugins.pump.danaRKorean import android.content.Context import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.TestBase import info.nightscout.androidaps.Constants import info.nightscout.androidaps.R +import info.nightscout.androidaps.TestBaseWithProfile import info.nightscout.androidaps.interfaces.CommandQueueProvider import info.nightscout.androidaps.interfaces.Constraint import info.nightscout.androidaps.interfaces.PluginType -import info.nightscout.androidaps.logging.AAPSLogger -import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin -import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP import org.junit.Assert import org.junit.Before @@ -27,17 +24,13 @@ import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) @PrepareForTest(SP::class, ConstraintChecker::class) -class DanaRKoreanPluginTest : TestBase() { +class DanaRKoreanPluginTest : TestBaseWithProfile() { - @Mock lateinit var aapsLogger: AAPSLogger @Mock lateinit var context: Context - @Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var constraintChecker: ConstraintChecker - @Mock lateinit var treatmentsPlugin: TreatmentsPlugin @Mock lateinit var sp: SP @Mock lateinit var commandQueue: CommandQueueProvider - val rxBus = RxBusWrapper() lateinit var danaRPump: DanaRPump private lateinit var danaRPlugin: DanaRKoreanPlugin diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MessageHashTableRKoreanTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MessageHashTableRKoreanTest.kt index e9050aa871..90397dc87b 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MessageHashTableRKoreanTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MessageHashTableRKoreanTest.kt @@ -3,7 +3,6 @@ package info.nightscout.androidaps.plugins.pump.danaRKorean.comm import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.CommandQueueProvider import info.nightscout.androidaps.interfaces.Constraint -import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage @@ -11,7 +10,6 @@ import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRSTestBase import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin -import info.nightscout.androidaps.utils.resources.ResourceHelper import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith @@ -24,8 +22,6 @@ import org.powermock.modules.junit4.PowerMockRunner @PrepareForTest(ConstraintChecker::class, DetailedBolusInfoStorage::class) class MessageHashTableRKoreanTest : DanaRSTestBase() { - @Mock lateinit var rxBus: RxBusWrapper - @Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var constraintChecker: ConstraintChecker @Mock lateinit var danaRPlugin: DanaRPlugin @Mock lateinit var danaRKoreanPlugin: DanaRKoreanPlugin @@ -33,7 +29,6 @@ class MessageHashTableRKoreanTest : DanaRSTestBase() { @Mock lateinit var commandQueue: CommandQueueProvider @Mock lateinit var activePlugin: ActivePluginProvider @Mock lateinit var detailedBolusInfoStorage: DetailedBolusInfoStorage - @Mock lateinit var treatmentsPlugin: TreatmentsPlugin @Test fun runTest() { Mockito.`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(Constraint(0.0)) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPluginTest.kt index 3064b1c0e3..a9a13dbc90 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPluginTest.kt @@ -14,7 +14,6 @@ import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRSTestBase import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin -import info.nightscout.androidaps.utils.resources.ResourceHelper import org.junit.Assert import org.junit.Before import org.junit.Test @@ -30,15 +29,12 @@ import org.powermock.modules.junit4.PowerMockRunner class DanaRSPluginTest : DanaRSTestBase() { @Mock lateinit var context: Context - @Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var constraintChecker: ConstraintChecker @Mock lateinit var profileFunction: ProfileFunction - @Mock lateinit var treatmentsPlugin: TreatmentsPlugin @Mock lateinit var commandQueue: CommandQueueProvider @Mock lateinit var detailedBolusInfoStorage: DetailedBolusInfoStorage private lateinit var danaRSPlugin: DanaRSPlugin - lateinit var rxBus: RxBusWrapper @Test fun basalRateShouldBeLimited() { @@ -70,7 +66,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") - rxBus = RxBusWrapper() danaRSPlugin = DanaRSPlugin(HasAndroidInjector { AndroidInjector { Unit } }, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, treatmentsPlugin, sp, commandQueue, danaRPump, detailedBolusInfoStorage) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTableTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTableTest.kt index 1d07ee750f..34f7c64def 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTableTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSMessageHashTableTest.kt @@ -3,13 +3,10 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm import com.cozmo.danar.util.BleCommandUtil import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.Constraint -import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin -import info.nightscout.androidaps.utils.resources.ResourceHelper -import info.nightscout.androidaps.utils.sharedPreferences.SP import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith @@ -22,8 +19,6 @@ import org.powermock.modules.junit4.PowerMockRunner @PrepareForTest(ConstraintChecker::class, DetailedBolusInfoStorage::class) class DanaRSMessageHashTableTest : DanaRSTestBase() { - @Mock lateinit var rxBus: RxBusWrapper - @Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var danaRSPlugin: DanaRSPlugin @Mock lateinit var activePlugin: ActivePluginProvider @Mock lateinit var constraintChecker: ConstraintChecker diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSTestBase.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSTestBase.kt index 9246d86bd0..a118af1b85 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSTestBase.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRSTestBase.kt @@ -1,16 +1,14 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.TestBase -import info.nightscout.androidaps.logging.AAPSLogger +import info.nightscout.androidaps.TestBaseWithProfile import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump import info.nightscout.androidaps.utils.sharedPreferences.SP import org.junit.Before import org.mockito.Mock -open class DanaRSTestBase : TestBase() { +open class DanaRSTestBase : TestBaseWithProfile() { - @Mock lateinit var aapsLogger: AAPSLogger @Mock lateinit var sp: SP @Mock lateinit var injector: HasAndroidInjector diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_EventsTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_EventsTest.kt index e4e2c61208..1072c72e09 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_EventsTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_APS_History_EventsTest.kt @@ -5,7 +5,6 @@ import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin import info.nightscout.androidaps.utils.DateUtil -import info.nightscout.androidaps.utils.resources.ResourceHelper import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith @@ -18,8 +17,6 @@ import java.util.* @PrepareForTest(RxBusWrapper::class, DetailedBolusInfoStorage::class) class DanaRS_Packet_APS_History_EventsTest : DanaRSTestBase() { - @Mock lateinit var rxBus: RxBusWrapper - @Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var activePlugin: ActivePluginProvider @Mock lateinit var danaRSPlugin: DanaRSPlugin @Mock lateinit var detailedBolusInfoStorage: DetailedBolusInfoStorage diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Basal_RateTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Basal_RateTest.kt index ab2790e29e..2c5b7ffec1 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Basal_RateTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Basal_RateTest.kt @@ -1,11 +1,9 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm import info.nightscout.androidaps.plugins.bus.RxBusWrapper -import info.nightscout.androidaps.utils.resources.ResourceHelper import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.mockito.Mock import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @@ -13,8 +11,6 @@ import org.powermock.modules.junit4.PowerMockRunner @PrepareForTest(RxBusWrapper::class) class DanaRS_Packet_Basal_Get_Basal_RateTest : DanaRSTestBase() { - @Mock lateinit var rxBus: RxBusWrapper - @Mock lateinit var resourceHelper: ResourceHelper @Test fun runTest() { val packet = DanaRS_Packet_Basal_Get_Basal_Rate(aapsLogger, rxBus, resourceHelper, danaRPump) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Bolus_OptionTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Bolus_OptionTest.kt index 8056633563..1b83b1df86 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Bolus_OptionTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Bolus_OptionTest.kt @@ -1,11 +1,9 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm import info.nightscout.androidaps.plugins.bus.RxBusWrapper -import info.nightscout.androidaps.utils.resources.ResourceHelper import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.mockito.Mock import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @@ -13,9 +11,6 @@ import org.powermock.modules.junit4.PowerMockRunner @PrepareForTest(RxBusWrapper::class) class DanaRS_Packet_Bolus_Get_Bolus_OptionTest : DanaRSTestBase() { - @Mock lateinit var resourceHelper: ResourceHelper - @Mock lateinit var rxBus: RxBusWrapper - @Test fun runTest() { val packet = DanaRS_Packet_Bolus_Get_Bolus_Option(aapsLogger, rxBus, resourceHelper, danaRPump) // test message decoding diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StartTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StartTest.kt index ab0be5c6bb..420b0a73d8 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StartTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StartTest.kt @@ -5,13 +5,11 @@ import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector import info.nightscout.androidaps.interfaces.CommandQueueProvider import info.nightscout.androidaps.interfaces.Constraint -import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin -import info.nightscout.androidaps.utils.resources.ResourceHelper import org.junit.Assert import org.junit.Before import org.junit.Test @@ -25,12 +23,9 @@ import org.powermock.modules.junit4.PowerMockRunner @PrepareForTest(ConstraintChecker::class, DetailedBolusInfoStorage::class) class DanaRS_Packet_Bolus_Set_Step_Bolus_StartTest : DanaRSTestBase() { - @Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var profileFunction: ProfileFunction - @Mock lateinit var treatmentsPlugin: TreatmentsPlugin @Mock lateinit var constraintChecker: ConstraintChecker @Mock lateinit var commandQueue: CommandQueueProvider - @Mock lateinit var rxBus: RxBusWrapper @Mock lateinit var context: Context @Mock lateinit var detailedBolusInfoStorage: DetailedBolusInfoStorage diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StopTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StopTest.kt index 22191340d4..d4854c12cd 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StopTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StopTest.kt @@ -8,7 +8,6 @@ import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin import info.nightscout.androidaps.plugins.treatments.Treatment import info.nightscout.androidaps.utils.DefaultValueHelper -import info.nightscout.androidaps.utils.resources.ResourceHelper import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith @@ -23,8 +22,6 @@ import org.powermock.modules.junit4.PowerMockRunner class DanaRS_Packet_Bolus_Set_Step_Bolus_StopTest : DanaRSTestBase() { @Mock lateinit var defaultValueHelper: DefaultValueHelper - @Mock lateinit var rxBus: RxBusWrapper - @Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var profileFunction: ProfileFunction @Mock lateinit var activePlugin: ActivePluginProvider @Mock lateinit var danaRSPlugin: DanaRSPlugin diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Pump_CheckTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Pump_CheckTest.kt index 6cde591c19..5248c2b699 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Pump_CheckTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Pump_CheckTest.kt @@ -1,11 +1,9 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm import info.nightscout.androidaps.plugins.bus.RxBusWrapper -import info.nightscout.androidaps.utils.resources.ResourceHelper import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.mockito.Mock import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @@ -13,9 +11,6 @@ import org.powermock.modules.junit4.PowerMockRunner @PrepareForTest(RxBusWrapper::class) class DanaRS_Packet_General_Get_Pump_CheckTest : DanaRSTestBase() { - @Mock lateinit var rxBus: RxBusWrapper - @Mock lateinit var resourceHelper: ResourceHelper - @Test fun runTest() { var packet = DanaRS_Packet_General_Get_Pump_Check(aapsLogger, danaRPump, rxBus, resourceHelper) Assert.assertEquals(null, packet.requestParams) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_AlarmTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_AlarmTest.kt index 6f977da777..743d3f66e7 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_AlarmTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_AlarmTest.kt @@ -1,10 +1,8 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.bus.RxBusWrapper import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.mockito.Mock import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @@ -12,8 +10,6 @@ import org.powermock.modules.junit4.PowerMockRunner @PrepareForTest() class DanaRS_Packet_History_AlarmTest : DanaRSTestBase() { - @Mock lateinit var rxBus: RxBusWrapper - @Test fun runTest() { val packet = DanaRS_Packet_History_Alarm(aapsLogger, rxBus, System.currentTimeMillis()) Assert.assertEquals("REVIEW__ALARM", packet.friendlyName) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_All_HistoryTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_All_HistoryTest.kt index e5acd15705..1f7dd00783 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_All_HistoryTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_All_HistoryTest.kt @@ -1,10 +1,8 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.bus.RxBusWrapper import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.mockito.Mock import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @@ -12,8 +10,6 @@ import org.powermock.modules.junit4.PowerMockRunner @PrepareForTest() class DanaRS_Packet_History_All_HistoryTest : DanaRSTestBase() { - @Mock lateinit var rxBus: RxBusWrapper - @Test fun runTest() { val packet = DanaRS_Packet_History_All_History(aapsLogger, rxBus, System.currentTimeMillis()) Assert.assertEquals("REVIEW__ALL_HISTORY", packet.friendlyName) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_BasalTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_BasalTest.kt index 702f297186..8451e90b0f 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_BasalTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_BasalTest.kt @@ -1,10 +1,8 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.bus.RxBusWrapper import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.mockito.Mock import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @@ -12,8 +10,6 @@ import org.powermock.modules.junit4.PowerMockRunner @PrepareForTest() class DanaRS_Packet_History_BasalTest : DanaRSTestBase() { - @Mock lateinit var rxBus: RxBusWrapper - @Test fun runTest() { val packet = DanaRS_Packet_History_Basal(aapsLogger, rxBus, System.currentTimeMillis()) Assert.assertEquals("REVIEW__BASAL", packet.friendlyName) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Blood_GlucoseTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Blood_GlucoseTest.kt index 8cdb489db3..0442ea98b9 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Blood_GlucoseTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Blood_GlucoseTest.kt @@ -1,10 +1,8 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.bus.RxBusWrapper import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.mockito.Mock import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @@ -12,8 +10,6 @@ import org.powermock.modules.junit4.PowerMockRunner @PrepareForTest() class DanaRS_Packet_History_Blood_GlucoseTest : DanaRSTestBase() { - @Mock lateinit var rxBus: RxBusWrapper - @Test fun runTest() { val packet = DanaRS_Packet_History_Blood_Glucose(aapsLogger, rxBus, System.currentTimeMillis()) Assert.assertEquals("REVIEW__BLOOD_GLUCOSE", packet.friendlyName) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_BolusTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_BolusTest.kt index e31c42207e..badaa0aa10 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_BolusTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_BolusTest.kt @@ -1,10 +1,8 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.bus.RxBusWrapper import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.mockito.Mock import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @@ -12,8 +10,6 @@ import org.powermock.modules.junit4.PowerMockRunner @PrepareForTest() class DanaRS_Packet_History_BolusTest : DanaRSTestBase() { - @Mock lateinit var rxBus: RxBusWrapper - @Test fun runTest() { val packet = DanaRS_Packet_History_Bolus(aapsLogger, rxBus, System.currentTimeMillis()) Assert.assertEquals("REVIEW__BOLUS", packet.friendlyName) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_CarbohydrateTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_CarbohydrateTest.kt index 2504be6824..22a99fcc53 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_CarbohydrateTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_CarbohydrateTest.kt @@ -1,10 +1,8 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.bus.RxBusWrapper import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.mockito.Mock import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @@ -12,8 +10,6 @@ import org.powermock.modules.junit4.PowerMockRunner @PrepareForTest() class DanaRS_Packet_History_CarbohydrateTest : DanaRSTestBase() { - @Mock lateinit var rxBus: RxBusWrapper - @Test fun runTest() { val packet = DanaRS_Packet_History_Carbohydrate(aapsLogger, rxBus, System.currentTimeMillis()) Assert.assertEquals("REVIEW__CARBOHYDRATE", packet.friendlyName) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_DailyTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_DailyTest.kt index 2c6e047462..91d4bea862 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_DailyTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_DailyTest.kt @@ -1,10 +1,8 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.bus.RxBusWrapper import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.mockito.Mock import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @@ -12,8 +10,6 @@ import org.powermock.modules.junit4.PowerMockRunner @PrepareForTest() class DanaRS_Packet_History_DailyTest : DanaRSTestBase() { - @Mock lateinit var rxBus: RxBusWrapper - @Test fun runTest() { val packet = DanaRS_Packet_History_Daily(aapsLogger, rxBus, System.currentTimeMillis()) Assert.assertEquals("REVIEW__DAILY", packet.friendlyName) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_PrimeTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_PrimeTest.kt index 1d15c66a40..19c8d2ef4e 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_PrimeTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_PrimeTest.kt @@ -1,10 +1,8 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.bus.RxBusWrapper import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.mockito.Mock import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @@ -12,8 +10,6 @@ import org.powermock.modules.junit4.PowerMockRunner @PrepareForTest() class DanaRS_Packet_History_PrimeTest : DanaRSTestBase() { - @Mock lateinit var rxBus: RxBusWrapper - @Test fun runTest() { val packet = DanaRS_Packet_History_Prime(aapsLogger, rxBus, System.currentTimeMillis()) Assert.assertEquals("REVIEW__PRIME", packet.friendlyName) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_RefillTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_RefillTest.kt index 47e26cea25..8b75ec344f 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_RefillTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_RefillTest.kt @@ -1,10 +1,8 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.bus.RxBusWrapper import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.mockito.Mock import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @@ -12,8 +10,6 @@ import org.powermock.modules.junit4.PowerMockRunner @PrepareForTest() class DanaRS_Packet_History_RefillTest : DanaRSTestBase() { - @Mock lateinit var rxBus: RxBusWrapper - @Test fun runTest() { val packet = DanaRS_Packet_History_Refill(aapsLogger, rxBus, System.currentTimeMillis()) Assert.assertEquals("REVIEW__REFILL", packet.friendlyName) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_SuspendTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_SuspendTest.kt index cc0157be55..66b06f4ed7 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_SuspendTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_SuspendTest.kt @@ -1,10 +1,8 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.bus.RxBusWrapper import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.mockito.Mock import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @@ -12,8 +10,6 @@ import org.powermock.modules.junit4.PowerMockRunner @PrepareForTest() class DanaRS_Packet_History_SuspendTest : DanaRSTestBase() { - @Mock lateinit var rxBus: RxBusWrapper - @Test fun runTest() { val packet = DanaRS_Packet_History_Suspend(aapsLogger, rxBus, System.currentTimeMillis()) Assert.assertEquals("REVIEW__SUSPEND", packet.friendlyName) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_TemporaryTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_TemporaryTest.kt index bfdac8cc05..a4e436a373 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_TemporaryTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_TemporaryTest.kt @@ -1,10 +1,8 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm -import info.nightscout.androidaps.plugins.bus.RxBusWrapper import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith -import org.mockito.Mock import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @@ -12,8 +10,6 @@ import org.powermock.modules.junit4.PowerMockRunner @PrepareForTest() class DanaRS_Packet_History_TemporaryTest : DanaRSTestBase() { - @Mock lateinit var rxBus: RxBusWrapper - @Test fun runTest() { val packet = DanaRS_Packet_History_Temporary(aapsLogger, rxBus, System.currentTimeMillis()) Assert.assertEquals("REVIEW__TEMPORARY", packet.friendlyName) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_AlarmTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_AlarmTest.kt index 6c2788c224..8aba3da2ba 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_AlarmTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_AlarmTest.kt @@ -1,12 +1,10 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm import info.nightscout.androidaps.plugins.general.nsclient.NSUpload -import info.nightscout.androidaps.utils.resources.ResourceHelper 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 @@ -15,8 +13,6 @@ import org.powermock.modules.junit4.PowerMockRunner @PrepareForTest(NSUpload::class) class DanaRS_Packet_Notify_AlarmTest : DanaRSTestBase() { - @Mock lateinit var resourceHelper: ResourceHelper - @Test fun runTest() { val packet = DanaRS_Packet_Notify_Alarm(aapsLogger, resourceHelper) // test params diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_CompleteTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_CompleteTest.kt index 423425717c..a7246493e6 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_CompleteTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_CompleteTest.kt @@ -4,12 +4,10 @@ import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.plugins.bus.RxBusWrapper -import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin import info.nightscout.androidaps.plugins.treatments.Treatment import info.nightscout.androidaps.utils.DefaultValueHelper -import info.nightscout.androidaps.utils.resources.ResourceHelper import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith @@ -25,8 +23,6 @@ import org.powermock.modules.junit4.PowerMockRunner class DanaRS_Packet_Notify_Delivery_CompleteTest : DanaRSTestBase() { @Mock lateinit var defaultValueHelper: DefaultValueHelper - @Mock lateinit var rxBus: RxBusWrapper - @Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var danaRSPlugin: DanaRSPlugin @Mock lateinit var profileFunction: ProfileFunction @Mock lateinit var activePlugin: ActivePluginProvider diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_DisplayTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_DisplayTest.kt index 5bd8566156..06f69cadbd 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_DisplayTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_DisplayTest.kt @@ -13,7 +13,6 @@ import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin import info.nightscout.androidaps.plugins.treatments.Treatment import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.utils.DefaultValueHelper -import info.nightscout.androidaps.utils.resources.ResourceHelper import org.junit.Assert import org.junit.Before import org.junit.Test @@ -29,13 +28,10 @@ import org.powermock.modules.junit4.PowerMockRunner class DanaRS_Packet_Notify_Delivery_Rate_DisplayTest : DanaRSTestBase() { @Mock lateinit var defaultValueHelper: DefaultValueHelper - @Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var profileFunction: ProfileFunction @Mock lateinit var activePlugin: ActivePluginProvider - @Mock lateinit var treatmentsPlugin: TreatmentsPlugin @Mock lateinit var constraintChecker: ConstraintChecker @Mock lateinit var commandQueue: CommandQueueProvider - @Mock lateinit var rxBus: RxBusWrapper @Mock lateinit var context: Context @Mock lateinit var detailedBolusInfoStorage: DetailedBolusInfoStorage diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/DanaRv2PluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/DanaRv2PluginTest.kt index 23492d58e8..dca4d1e3ad 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/DanaRv2PluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/DanaRv2PluginTest.kt @@ -3,19 +3,16 @@ package info.nightscout.androidaps.plugins.pump.danaRv2 import android.content.Context import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.TestBase import info.nightscout.androidaps.Constants import info.nightscout.androidaps.R +import info.nightscout.androidaps.TestBaseWithProfile import info.nightscout.androidaps.interfaces.CommandQueueProvider import info.nightscout.androidaps.interfaces.Constraint import info.nightscout.androidaps.interfaces.PluginType -import info.nightscout.androidaps.logging.AAPSLogger -import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin -import info.nightscout.androidaps.utils.resources.ResourceHelper import org.junit.Before import org.junit.Test import org.junit.runner.RunWith @@ -26,18 +23,14 @@ import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) @PrepareForTest(ConstraintChecker::class, DetailedBolusInfoStorage::class) -class DanaRv2PluginTest : TestBase() { +class DanaRv2PluginTest : TestBaseWithProfile() { - @Mock lateinit var aapsLogger: AAPSLogger @Mock lateinit var context: Context - @Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var constraintChecker: ConstraintChecker - @Mock lateinit var treatmentsPlugin: TreatmentsPlugin @Mock lateinit var sp: info.nightscout.androidaps.utils.sharedPreferences.SP @Mock lateinit var commandQueue: CommandQueueProvider @Mock lateinit var detailedBolusInfoStorage: DetailedBolusInfoStorage - val rxBus = RxBusWrapper() lateinit var danaRPump: DanaRPump private lateinit var danaRv2Plugin: DanaRv2Plugin diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MessageHashTable_rv2Test.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MessageHashTable_rv2Test.kt index ee4109e476..8cf2f1c9df 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MessageHashTable_rv2Test.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MessageHashTable_rv2Test.kt @@ -8,9 +8,9 @@ import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin +import info.nightscout.androidaps.plugins.pump.danaR.comm.DanaRTestBase import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin -import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRSTestBase import info.nightscout.androidaps.plugins.pump.danaRv2.DanaRv2Plugin import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.utils.resources.ResourceHelper @@ -24,7 +24,7 @@ import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) @PrepareForTest(ConstraintChecker::class, DetailedBolusInfoStorage::class) -class MessageHashTable_rv2Test : DanaRSTestBase() { +class MessageHashTable_rv2Test : DanaRTestBase() { @Mock lateinit var rxBus: RxBusWrapper @Mock lateinit var resourceHelper: ResourceHelper diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgCheckValue_v2Test.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgCheckValue_v2Test.kt index 3529491a26..71a361e8c5 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgCheckValue_v2Test.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgCheckValue_v2Test.kt @@ -5,8 +5,8 @@ import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump +import info.nightscout.androidaps.plugins.pump.danaR.comm.DanaRTestBase import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin -import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRSTestBase import info.nightscout.androidaps.plugins.pump.danaRv2.DanaRv2Plugin import info.nightscout.androidaps.utils.resources.ResourceHelper import org.junit.Assert @@ -18,7 +18,7 @@ import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) @PrepareForTest(DanaRKoreanPlugin::class, DanaRPlugin::class, DanaRv2Plugin::class) -class MsgCheckValue_v2Test : DanaRSTestBase() { +class MsgCheckValue_v2Test : DanaRTestBase() { val rxBus = RxBusWrapper() @Mock lateinit var resourceHelper: ResourceHelper diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/MedtronicHistoryDataUTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/MedtronicHistoryDataUTest.java index 8795ffd68e..cd395842bd 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/MedtronicHistoryDataUTest.java +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/MedtronicHistoryDataUTest.java @@ -6,7 +6,6 @@ import org.junit.Before; import java.util.List; -import info.AAPSMocker; import info.nightscout.androidaps.R; import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil; import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.RawHistoryPage; @@ -48,7 +47,6 @@ public class MedtronicHistoryDataUTest { // } - AAPSMocker.mockMainApp(); } @@ -56,12 +54,6 @@ public class MedtronicHistoryDataUTest { public void prepareMocks() throws Exception { System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "trace"); - AAPSMocker.mockMainApp(); - AAPSMocker.mockConfigBuilder(); - AAPSMocker.mockStrings(); - AAPSMocker.mockApplicationContext(); - AAPSMocker.mockSP(); - AAPSMocker.mockCommandQueue(); when(SP.getString(R.string.key_danars_address, "")).thenReturn(""); 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 c62dfbe8b2..3c8c403695 100644 --- a/app/src/test/java/info/nightscout/androidaps/queue/CommandQueueTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/queue/CommandQueueTest.kt @@ -4,7 +4,7 @@ import android.content.Context import dagger.Lazy import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.TestBase +import info.nightscout.androidaps.TestBaseWithProfile import info.nightscout.androidaps.data.DetailedBolusInfo import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.Constraint @@ -33,24 +33,19 @@ import java.util.* @RunWith(PowerMockRunner::class) @PrepareForTest(ConstraintChecker::class, VirtualPumpPlugin::class, ToastUtils::class, Context::class, TreatmentsPlugin::class, FabricPrivacy::class) -class CommandQueueTest : TestBase() { +class CommandQueueTest : TestBaseWithProfile() { - @Mock lateinit var aapsLogger: AAPSLogger - @Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var constraintChecker: ConstraintChecker @Mock lateinit var profileFunction: ProfileFunction @Mock lateinit var lazyActivePlugin: Lazy @Mock lateinit var activePlugin: ActivePluginProvider @Mock lateinit var context: Context - @Mock lateinit var treatmentsPlugin: TreatmentsPlugin @Mock lateinit var virtualPumpPlugin: VirtualPumpPlugin @Mock lateinit var sp: SP @Mock lateinit var fabricPrivacy: FabricPrivacy private val buildHelper = BuildHelper() - val rxBus = RxBusWrapper() - val injector = HasAndroidInjector { AndroidInjector { if (it is Command) { @@ -63,7 +58,7 @@ class CommandQueueTest : TestBase() { lateinit var commandQueue: CommandQueue @Before - fun prepareMock() { + fun prepare() { commandQueue = CommandQueue(injector, aapsLogger, rxBus, resourceHelper, constraintChecker, profileFunction, lazyActivePlugin, context, sp, buildHelper, fabricPrivacy) val pumpDescription = PumpDescription()