From ffa9c044967a9ff0d198e4f65d4161773bf5b73a Mon Sep 17 00:00:00 2001 From: Philoul Date: Tue, 6 Apr 2021 23:30:16 +0200 Subject: [PATCH 1/2] Remove dependency and create 2 classes for drivers --- .../fragments/TreatmentsUserEntryFragment.kt | 3 +- .../androidaps/logging/UserEntryLogger.kt | 9 ++ .../maintenance/formats/ClassicPrefsFormat.kt | 2 +- .../utils/userEntry/UserEntryMapper.kt | 139 ++++++++++++++++++ .../UserEntryPresentationHelper.kt | 6 +- .../utils/userEntry/ValueWithUnitMapper.kt | 96 ++++++++++++ .../formats/ClassicPrefsFormatTest.kt | 2 +- dana/build.gradle | 1 - .../androidaps/dana/DanaFragment.kt | 4 +- 9 files changed, 254 insertions(+), 8 deletions(-) create mode 100644 core/src/main/java/info/nightscout/androidaps/utils/userEntry/UserEntryMapper.kt rename core/src/main/java/info/nightscout/androidaps/utils/{ => userEntry}/UserEntryPresentationHelper.kt (97%) create mode 100644 core/src/main/java/info/nightscout/androidaps/utils/userEntry/ValueWithUnitMapper.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsUserEntryFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsUserEntryFragment.kt index 59a0bc5652..5e76792b4a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsUserEntryFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsUserEntryFragment.kt @@ -15,7 +15,6 @@ import info.nightscout.androidaps.database.entities.UserEntry.Sources import info.nightscout.androidaps.databinding.TreatmentsUserEntryFragmentBinding import info.nightscout.androidaps.databinding.TreatmentsUserEntryItemBinding import info.nightscout.androidaps.events.EventPreferenceChange -import info.nightscout.androidaps.extensions.colorId import info.nightscout.androidaps.interfaces.ImportExportPrefsInterface import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.logging.UserEntryLogger @@ -25,7 +24,7 @@ import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.T import info.nightscout.androidaps.utils.Translator -import info.nightscout.androidaps.utils.UserEntryPresentationHelper +import info.nightscout.androidaps.utils.userEntry.UserEntryPresentationHelper import info.nightscout.androidaps.utils.alertDialogs.OKDialog import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.rx.AapsSchedulers diff --git a/core/src/main/java/info/nightscout/androidaps/logging/UserEntryLogger.kt b/core/src/main/java/info/nightscout/androidaps/logging/UserEntryLogger.kt index 5c94251621..9bed01b2f0 100644 --- a/core/src/main/java/info/nightscout/androidaps/logging/UserEntryLogger.kt +++ b/core/src/main/java/info/nightscout/androidaps/logging/UserEntryLogger.kt @@ -6,6 +6,8 @@ import info.nightscout.androidaps.database.entities.UserEntry.Action import info.nightscout.androidaps.database.entities.UserEntry.Sources import info.nightscout.androidaps.database.transactions.UserEntryTransaction import info.nightscout.androidaps.utils.rx.AapsSchedulers +import info.nightscout.androidaps.utils.userEntry.UserEntryMapper +import info.nightscout.androidaps.utils.userEntry.ValueWithUnitMapper import io.reactivex.disposables.CompositeDisposable import io.reactivex.rxkotlin.plusAssign import io.reactivex.rxkotlin.subscribeBy @@ -40,4 +42,11 @@ class UserEntryLogger @Inject constructor( onComplete = { aapsLogger.debug("USER ENTRY: $action $source $note $filteredValues") } ) } + + fun log(action: UserEntryMapper.Action, source: UserEntryMapper.Sources, note: String? ="", vararg listvalues: ValueWithUnitMapper?) = log(action.db, source.db, note, listvalues.toList().map {it?.db()}) + + fun log(action: UserEntryMapper.Action, source: UserEntryMapper.Sources, vararg listvalues: ValueWithUnitMapper?) = log(action.db, source.db, "", listvalues.toList().map {it?.db()}) + + fun log(action: UserEntryMapper.Action, source: UserEntryMapper.Sources, note: String? ="", listvalues: List = listOf()) = log(action.db, source.db, note, listvalues.map {it?.db()}) + } \ No newline at end of file diff --git a/core/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/formats/ClassicPrefsFormat.kt b/core/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/formats/ClassicPrefsFormat.kt index d9254ad50a..03a1ee69a6 100644 --- a/core/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/formats/ClassicPrefsFormat.kt +++ b/core/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/formats/ClassicPrefsFormat.kt @@ -6,7 +6,7 @@ import info.nightscout.androidaps.database.entities.UserEntry import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.Translator -import info.nightscout.androidaps.utils.UserEntryPresentationHelper +import info.nightscout.androidaps.utils.userEntry.UserEntryPresentationHelper import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.storage.Storage import java.io.File diff --git a/core/src/main/java/info/nightscout/androidaps/utils/userEntry/UserEntryMapper.kt b/core/src/main/java/info/nightscout/androidaps/utils/userEntry/UserEntryMapper.kt new file mode 100644 index 0000000000..bd0a2b723d --- /dev/null +++ b/core/src/main/java/info/nightscout/androidaps/utils/userEntry/UserEntryMapper.kt @@ -0,0 +1,139 @@ +package info.nightscout.androidaps.utils.userEntry + +import info.nightscout.androidaps.database.entities.UserEntry + +class UserEntryMapper { + enum class Action (val db: UserEntry.Action) { + BOLUS (UserEntry.Action.BOLUS), + SMB (UserEntry.Action.SMB), + BOLUS_ADVISOR (UserEntry.Action.BOLUS_ADVISOR), + EXTENDED_BOLUS (UserEntry.Action.EXTENDED_BOLUS), + SUPERBOLUS_TBR (UserEntry.Action.SUPERBOLUS_TBR), + CARBS (UserEntry.Action.CARBS), + EXTENDED_CARBS (UserEntry.Action.EXTENDED_CARBS), + TEMP_BASAL (UserEntry.Action.TEMP_BASAL), + TT (UserEntry.Action.TT), + NEW_PROFILE (UserEntry.Action.NEW_PROFILE), + CLONE_PROFILE (UserEntry.Action.CLONE_PROFILE), + STORE_PROFILE (UserEntry.Action.STORE_PROFILE), + PROFILE_SWITCH (UserEntry.Action.PROFILE_SWITCH), + PROFILE_SWITCH_CLONED (UserEntry.Action.PROFILE_SWITCH_CLONED), + CLOSED_LOOP_MODE (UserEntry.Action.CLOSED_LOOP_MODE), + LGS_LOOP_MODE (UserEntry.Action.LGS_LOOP_MODE), + OPEN_LOOP_MODE (UserEntry.Action.OPEN_LOOP_MODE), + LOOP_DISABLED (UserEntry.Action.LOOP_DISABLED), + LOOP_ENABLED (UserEntry.Action.LOOP_ENABLED), + RECONNECT (UserEntry.Action.RECONNECT), + DISCONNECT (UserEntry.Action.DISCONNECT), + RESUME (UserEntry.Action.RESUME), + SUSPEND (UserEntry.Action.SUSPEND), + HW_PUMP_ALLOWED (UserEntry.Action.HW_PUMP_ALLOWED), + CLEAR_PAIRING_KEYS (UserEntry.Action.CLEAR_PAIRING_KEYS), + ACCEPTS_TEMP_BASAL (UserEntry.Action.ACCEPTS_TEMP_BASAL), + CANCEL_TEMP_BASAL (UserEntry.Action.CANCEL_TEMP_BASAL), + CANCEL_EXTENDED_BOLUS (UserEntry.Action.CANCEL_EXTENDED_BOLUS), + CANCEL_TT (UserEntry.Action.CANCEL_TT), + CAREPORTAL (UserEntry.Action.CAREPORTAL), + SITE_CHANGE (UserEntry.Action.SITE_CHANGE), + RESERVOIR_CHANGE (UserEntry.Action.RESERVOIR_CHANGE), + CALIBRATION (UserEntry.Action.CALIBRATION), + PRIME_BOLUS (UserEntry.Action.PRIME_BOLUS), + TREATMENT (UserEntry.Action.TREATMENT), + CAREPORTAL_NS_REFRESH (UserEntry.Action.CAREPORTAL_NS_REFRESH), + PROFILE_SWITCH_NS_REFRESH (UserEntry.Action.PROFILE_SWITCH_NS_REFRESH), + TREATMENTS_NS_REFRESH (UserEntry.Action.TREATMENTS_NS_REFRESH), + TT_NS_REFRESH (UserEntry.Action.TT_NS_REFRESH), + AUTOMATION_REMOVED (UserEntry.Action.AUTOMATION_REMOVED), + BG_REMOVED (UserEntry.Action.BG_REMOVED), + CAREPORTAL_REMOVED (UserEntry.Action.CAREPORTAL_REMOVED), + EXTENDED_BOLUS_REMOVED (UserEntry.Action.EXTENDED_BOLUS_REMOVED), + FOOD_REMOVED (UserEntry.Action.FOOD_REMOVED), + PROFILE_REMOVED (UserEntry.Action.PROFILE_REMOVED), + PROFILE_SWITCH_REMOVED (UserEntry.Action.PROFILE_SWITCH_REMOVED), + RESTART_EVENTS_REMOVED (UserEntry.Action.RESTART_EVENTS_REMOVED), + TREATMENT_REMOVED (UserEntry.Action.TREATMENT_REMOVED), + BOLUS_REMOVED (UserEntry.Action.BOLUS_REMOVED), + CARBS_REMOVED (UserEntry.Action.CARBS_REMOVED), + TEMP_BASAL_REMOVED (UserEntry.Action.TEMP_BASAL_REMOVED), + TT_REMOVED (UserEntry.Action.TT_REMOVED), + NS_PAUSED (UserEntry.Action.NS_PAUSED), + NS_RESUME (UserEntry.Action.NS_RESUME), + NS_QUEUE_CLEARED (UserEntry.Action.NS_QUEUE_CLEARED), + NS_SETTINGS_COPIED (UserEntry.Action.NS_SETTINGS_COPIED), + ERROR_DIALOG_OK (UserEntry.Action.ERROR_DIALOG_OK), + ERROR_DIALOG_MUTE (UserEntry.Action.ERROR_DIALOG_MUTE), + ERROR_DIALOG_MUTE_5MIN (UserEntry.Action.ERROR_DIALOG_MUTE_5MIN), + OBJECTIVE_STARTED (UserEntry.Action.OBJECTIVE_STARTED), + OBJECTIVE_UNSTARTED (UserEntry.Action.OBJECTIVE_UNSTARTED), + OBJECTIVES_SKIPPED (UserEntry.Action.OBJECTIVES_SKIPPED), + STAT_RESET (UserEntry.Action.STAT_RESET), + DELETE_LOGS (UserEntry.Action.DELETE_LOGS), + DELETE_FUTURE_TREATMENTS (UserEntry.Action.DELETE_FUTURE_TREATMENTS), + EXPORT_SETTINGS (UserEntry.Action.EXPORT_SETTINGS), + IMPORT_SETTINGS (UserEntry.Action.IMPORT_SETTINGS), + RESET_DATABASES (UserEntry.Action.RESET_DATABASES), + EXPORT_DATABASES (UserEntry.Action.EXPORT_DATABASES), + IMPORT_DATABASES (UserEntry.Action.IMPORT_DATABASES), + OTP_EXPORT (UserEntry.Action.OTP_EXPORT), + OTP_RESET (UserEntry.Action.OTP_RESET), + STOP_SMS (UserEntry.Action.STOP_SMS), + FOOD (UserEntry.Action.FOOD), + EXPORT_CSV (UserEntry.Action.EXPORT_CSV), + UNKNOWN (UserEntry.Action.UNKNOWN) + ; + } + + enum class Sources (val db: UserEntry.Sources) { + TreatmentDialog (UserEntry.Sources.TreatmentDialog), + InsulinDialog (UserEntry.Sources.InsulinDialog), + CarbDialog (UserEntry.Sources.CarbDialog), + WizardDialog (UserEntry.Sources.WizardDialog), + QuickWizard (UserEntry.Sources.QuickWizard), + ExtendedBolusDialog (UserEntry.Sources.ExtendedBolusDialog), + TTDialog (UserEntry.Sources.TTDialog), + ProfileSwitchDialog (UserEntry.Sources.ProfileSwitchDialog), + LoopDialog (UserEntry.Sources.LoopDialog), + TempBasalDialog (UserEntry.Sources.TempBasalDialog), + CalibrationDialog (UserEntry.Sources.CalibrationDialog), + FillDialog (UserEntry.Sources.FillDialog), + BgCheck (UserEntry.Sources.BgCheck), + SensorInsert (UserEntry.Sources.SensorInsert), + BatteryChange (UserEntry.Sources.BatteryChange), + Note (UserEntry.Sources.Note), + Exercise (UserEntry.Sources.Exercise), + Question (UserEntry.Sources.Question), + Announcement (UserEntry.Sources.Announcement), + Actions (UserEntry.Sources.Actions), + Automation (UserEntry.Sources.Automation), + BG (UserEntry.Sources.BG), + LocalProfile (UserEntry.Sources.LocalProfile), + Loop (UserEntry.Sources.Loop), + Maintenance (UserEntry.Sources.Maintenance), + NSClient (UserEntry.Sources.NSClient), + NSProfile (UserEntry.Sources.NSProfile), + Objectives (UserEntry.Sources.Objectives), + Pump (UserEntry.Sources.Pump), + Dana (UserEntry.Sources.Dana), + DanaR (UserEntry.Sources.DanaR), + DanaRC (UserEntry.Sources.DanaRC), + DanaRv2 (UserEntry.Sources.DanaRv2), + DanaRS (UserEntry.Sources.DanaRS), + Insight (UserEntry.Sources.Insight), + Combo (UserEntry.Sources.Combo), + Medtronic (UserEntry.Sources.Medtronic), + Omnipod (UserEntry.Sources.Omnipod), + OmnipodEros (UserEntry.Sources.OmnipodEros), + OmnipodDash (UserEntry.Sources.OmnipodDash), + MDI (UserEntry.Sources.MDI), + VirtualPump (UserEntry.Sources.VirtualPump), + SMS (UserEntry.Sources.SMS), + Treatments (UserEntry.Sources.Treatments), + Wear (UserEntry.Sources.Wear), + Food (UserEntry.Sources.Food), + ConfigBuilder (UserEntry.Sources.ConfigBuilder), + Overview (UserEntry.Sources.Overview), + Stats (UserEntry.Sources.Stats), + Unknown(UserEntry.Sources.Unknown) + ; + } +} \ No newline at end of file diff --git a/core/src/main/java/info/nightscout/androidaps/utils/UserEntryPresentationHelper.kt b/core/src/main/java/info/nightscout/androidaps/utils/userEntry/UserEntryPresentationHelper.kt similarity index 97% rename from core/src/main/java/info/nightscout/androidaps/utils/UserEntryPresentationHelper.kt rename to core/src/main/java/info/nightscout/androidaps/utils/userEntry/UserEntryPresentationHelper.kt index 8371ba96ab..0aeffddb2c 100644 --- a/core/src/main/java/info/nightscout/androidaps/utils/UserEntryPresentationHelper.kt +++ b/core/src/main/java/info/nightscout/androidaps/utils/userEntry/UserEntryPresentationHelper.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.utils +package info.nightscout.androidaps.utils.userEntry import android.text.Spanned import dagger.Reusable @@ -10,6 +10,10 @@ import info.nightscout.androidaps.database.entities.UserEntry.ColorGroup import info.nightscout.androidaps.database.entities.UserEntry.Sources import info.nightscout.androidaps.database.entities.ValueWithUnit import info.nightscout.androidaps.interfaces.ProfileFunction +import info.nightscout.androidaps.utils.DateUtil +import info.nightscout.androidaps.utils.DecimalFormatter +import info.nightscout.androidaps.utils.HtmlHelper +import info.nightscout.androidaps.utils.Translator import info.nightscout.androidaps.utils.resources.ResourceHelper import javax.inject.Inject diff --git a/core/src/main/java/info/nightscout/androidaps/utils/userEntry/ValueWithUnitMapper.kt b/core/src/main/java/info/nightscout/androidaps/utils/userEntry/ValueWithUnitMapper.kt new file mode 100644 index 0000000000..78858d07e0 --- /dev/null +++ b/core/src/main/java/info/nightscout/androidaps/utils/userEntry/ValueWithUnitMapper.kt @@ -0,0 +1,96 @@ +package info.nightscout.androidaps.utils.userEntry + +import androidx.annotation.StringRes +import info.nightscout.androidaps.Constants +import info.nightscout.androidaps.database.entities.TemporaryTarget +import info.nightscout.androidaps.database.entities.TherapyEvent +import info.nightscout.androidaps.database.entities.ValueWithUnit + +sealed class ValueWithUnitMapper { //I use a sealed class because of StringResource that containts a listOf as second parameter + + object UNKNOWN : ValueWithUnitMapper() // formerly None used as fallback + + data class SimpleString(val value: String) : ValueWithUnitMapper() // formerly one usage of None + + data class SimpleInt(val value: Int) : ValueWithUnitMapper() // formerly one usage of None + + data class Mgdl(val value: Double) : ValueWithUnitMapper() + + data class Mmoll(val value: Double) : ValueWithUnitMapper() + + data class Timestamp(val value: Long) : ValueWithUnitMapper() + + data class Insulin(val value: Double) : ValueWithUnitMapper() + + data class UnitPerHour(val value: Double) : ValueWithUnitMapper() + + data class Gram(val value: Int) : ValueWithUnitMapper() + + data class Minute(val value: Int) : ValueWithUnitMapper() + + data class Hour(val value: Int) : ValueWithUnitMapper() + + data class Percent(val value: Int) : ValueWithUnitMapper() + + data class TherapyEventType(val value: TherapyEvent.Type) : ValueWithUnitMapper() + + data class TherapyEventMeterType(val value: TherapyEvent.MeterType) : ValueWithUnitMapper() + + data class TherapyEventTTReason(val value: TemporaryTarget.Reason) : ValueWithUnitMapper() + + data class StringResource(@StringRes val value: Int, val params: List = listOf()) : ValueWithUnitMapper() + + fun db(): ValueWithUnit? { + return when(this) { + is Gram -> ValueWithUnit.Gram(this.value) + is Hour -> ValueWithUnit.Hour(this.value) + is Insulin -> ValueWithUnit.Insulin(this.value) + is Mgdl -> ValueWithUnit.Mgdl(this.value) + is Minute -> ValueWithUnit.Minute(this.value) + is Mmoll -> ValueWithUnit.Mmoll(this.value) + is Percent -> ValueWithUnit.Percent(this.value) + is SimpleInt -> ValueWithUnit.SimpleInt(this.value) + is SimpleString -> ValueWithUnit.SimpleString(this.value) + is StringResource -> ValueWithUnit.StringResource(this.value, this.params.map {it.db()}.filterNotNull()) + is TherapyEventMeterType -> ValueWithUnit.TherapyEventMeterType(this.value) + is TherapyEventTTReason -> ValueWithUnit.TherapyEventTTReason(this.value) + is TherapyEventType -> ValueWithUnit.TherapyEventType(this.value) + is Timestamp -> ValueWithUnit.Timestamp(this.value) + is UnitPerHour -> ValueWithUnit.UnitPerHour(this.value) + UNKNOWN -> null + } + } + + fun value(): Any? { + return when(this) { + is Gram -> this.value + is Hour -> this.value + is Insulin -> this.value + is Mgdl -> this.value + is Minute -> this.value + is Mmoll -> this.value + is Percent -> this.value + is SimpleInt -> this.value + is SimpleString -> this.value + is StringResource -> this.value + is TherapyEventMeterType -> this.value + is TherapyEventTTReason -> this.value + is TherapyEventType -> this.value + is Timestamp -> this.value + is UnitPerHour -> this.value + UNKNOWN -> null + } + } + + companion object { + + const val MGDL = Constants.MGDL + const val MMOL = Constants.MMOL + + fun fromGlucoseUnit(value: Double, string: String): ValueWithUnitMapper? = when (string) { + MGDL, "mgdl" -> Mgdl(value) + MMOL, "mmol/l" -> Mmoll(value) + else -> null + } + } +} \ No newline at end of file diff --git a/core/src/test/java/info/nightscout/androidaps/plugins/general/maintenance/formats/ClassicPrefsFormatTest.kt b/core/src/test/java/info/nightscout/androidaps/plugins/general/maintenance/formats/ClassicPrefsFormatTest.kt index 3bc636c614..89634c179f 100644 --- a/core/src/test/java/info/nightscout/androidaps/plugins/general/maintenance/formats/ClassicPrefsFormatTest.kt +++ b/core/src/test/java/info/nightscout/androidaps/plugins/general/maintenance/formats/ClassicPrefsFormatTest.kt @@ -4,7 +4,7 @@ import info.nightscout.androidaps.TestBase import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.Translator -import info.nightscout.androidaps.utils.UserEntryPresentationHelper +import info.nightscout.androidaps.utils.userEntry.UserEntryPresentationHelper import info.nightscout.androidaps.utils.resources.ResourceHelper import org.junit.Assert import org.junit.Test diff --git a/dana/build.gradle b/dana/build.gradle index 55565f892b..8020051b31 100644 --- a/dana/build.gradle +++ b/dana/build.gradle @@ -17,5 +17,4 @@ android { dependencies { implementation project(':core') - implementation project(':database') } \ No newline at end of file diff --git a/dana/src/main/java/info/nightscout/androidaps/dana/DanaFragment.kt b/dana/src/main/java/info/nightscout/androidaps/dana/DanaFragment.kt index d736e6b9ab..9b30c8887c 100644 --- a/dana/src/main/java/info/nightscout/androidaps/dana/DanaFragment.kt +++ b/dana/src/main/java/info/nightscout/androidaps/dana/DanaFragment.kt @@ -10,8 +10,6 @@ import android.view.ViewGroup import dagger.android.support.DaggerFragment import info.nightscout.androidaps.activities.TDDStatsActivity import info.nightscout.androidaps.dana.databinding.DanarFragmentBinding -import info.nightscout.androidaps.database.entities.UserEntry.Action -import info.nightscout.androidaps.database.entities.UserEntry.Sources import info.nightscout.androidaps.dialogs.ProfileViewerDialog import info.nightscout.androidaps.events.EventExtendedBolusChange import info.nightscout.androidaps.events.EventInitializationChanged @@ -29,6 +27,8 @@ import info.nightscout.androidaps.queue.events.EventQueueChanged import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.T +import info.nightscout.androidaps.utils.userEntry.UserEntryMapper.Action +import info.nightscout.androidaps.utils.userEntry.UserEntryMapper.Sources import info.nightscout.androidaps.utils.WarnColors import info.nightscout.androidaps.utils.alertDialogs.OKDialog import info.nightscout.androidaps.extensions.toVisibility From 22dfea652d5bc1115607251bd0f5172cfe5dd09f Mon Sep 17 00:00:00 2001 From: Philoul Date: Tue, 6 Apr 2021 23:58:54 +0200 Subject: [PATCH 2/2] RRemove unused injection and try to fix tests... It works for LoopPluginTest, but not for ClassicPrefsFormatTest as many other... (don't know if it's my config or not) --- .../androidaps/plugins/aps/loop/LoopPluginTest.kt | 6 ++++-- .../maintenance/formats/ClassicPrefsFormat.kt | 6 ------ .../maintenance/formats/ClassicPrefsFormatTest.kt | 12 +++--------- 3 files changed, 7 insertions(+), 17 deletions(-) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/aps/loop/LoopPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/aps/loop/LoopPluginTest.kt index ff7321cd4f..8d40547190 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/aps/loop/LoopPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/aps/loop/LoopPluginTest.kt @@ -9,6 +9,7 @@ import info.nightscout.androidaps.R import info.nightscout.androidaps.TestBase import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.interfaces.* +import info.nightscout.androidaps.logging.UserEntryLogger import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.configBuilder.RunningConfiguration @@ -30,7 +31,7 @@ import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @RunWith(PowerMockRunner::class) -@PrepareForTest(ConstraintChecker::class, ReceiverStatusStore::class, RunningConfiguration::class) +@PrepareForTest(ConstraintChecker::class, ReceiverStatusStore::class, RunningConfiguration::class, UserEntryLogger::class) class LoopPluginTest : TestBase() { @Mock lateinit var sp: SP @@ -48,6 +49,7 @@ class LoopPluginTest : TestBase() { @Mock lateinit var receiverStatusStore: ReceiverStatusStore @Mock lateinit var notificationManager: NotificationManager @Mock lateinit var repository: AppRepository + @Mock lateinit var uel:UserEntryLogger @Mock lateinit var dateUtil: DateUtil @Mock lateinit var runningConfiguration: RunningConfiguration @@ -56,7 +58,7 @@ class LoopPluginTest : TestBase() { val injector = HasAndroidInjector { AndroidInjector { } } @Before fun prepareMock() { - loopPlugin = LoopPlugin(injector, aapsLogger, aapsSchedulers, rxBus, sp, Config(), constraintChecker, resourceHelper, profileFunction, context, commandQueue, activePlugin, virtualPumpPlugin, iobCobCalculator, receiverStatusStore, fabricPrivacy, dateUtil, repository, runningConfiguration) + loopPlugin = LoopPlugin(injector, aapsLogger, aapsSchedulers, rxBus, sp, Config(), constraintChecker, resourceHelper, profileFunction, context, commandQueue, activePlugin, virtualPumpPlugin, iobCobCalculator, receiverStatusStore, fabricPrivacy, dateUtil, uel, repository, runningConfiguration) `when`(activePlugin.activePump).thenReturn(virtualPumpPlugin) `when`(context.getSystemService(Context.NOTIFICATION_SERVICE)).thenReturn(notificationManager) } diff --git a/core/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/formats/ClassicPrefsFormat.kt b/core/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/formats/ClassicPrefsFormat.kt index 03a1ee69a6..83d699015d 100644 --- a/core/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/formats/ClassicPrefsFormat.kt +++ b/core/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/formats/ClassicPrefsFormat.kt @@ -3,9 +3,6 @@ package info.nightscout.androidaps.plugins.general.maintenance.formats import info.nightscout.androidaps.Constants import info.nightscout.androidaps.core.R import info.nightscout.androidaps.database.entities.UserEntry -import info.nightscout.androidaps.interfaces.ProfileFunction -import info.nightscout.androidaps.utils.DateUtil -import info.nightscout.androidaps.utils.Translator import info.nightscout.androidaps.utils.userEntry.UserEntryPresentationHelper import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.storage.Storage @@ -18,9 +15,6 @@ import javax.inject.Singleton @Singleton class ClassicPrefsFormat @Inject constructor( private var resourceHelper: ResourceHelper, - private var dateUtil: DateUtil, - private var translator: Translator, - private var profileFunction: ProfileFunction, private var userEntryPresentationHelper: UserEntryPresentationHelper, private var storage: Storage ) : PrefsFormat { diff --git a/core/src/test/java/info/nightscout/androidaps/plugins/general/maintenance/formats/ClassicPrefsFormatTest.kt b/core/src/test/java/info/nightscout/androidaps/plugins/general/maintenance/formats/ClassicPrefsFormatTest.kt index 89634c179f..ae55f7ede9 100644 --- a/core/src/test/java/info/nightscout/androidaps/plugins/general/maintenance/formats/ClassicPrefsFormatTest.kt +++ b/core/src/test/java/info/nightscout/androidaps/plugins/general/maintenance/formats/ClassicPrefsFormatTest.kt @@ -1,9 +1,6 @@ package info.nightscout.androidaps.plugins.general.maintenance.formats import info.nightscout.androidaps.TestBase -import info.nightscout.androidaps.interfaces.ProfileFunction -import info.nightscout.androidaps.utils.DateUtil -import info.nightscout.androidaps.utils.Translator import info.nightscout.androidaps.utils.userEntry.UserEntryPresentationHelper import info.nightscout.androidaps.utils.resources.ResourceHelper import org.junit.Assert @@ -16,13 +13,10 @@ import org.powermock.modules.junit4.PowerMockRunner import java.io.File @RunWith(PowerMockRunner::class) -@PrepareForTest(File::class, Translator::class) +@PrepareForTest(File::class, UserEntryPresentationHelper::class) class ClassicPrefsFormatTest : TestBase() { @Mock lateinit var resourceHelper: ResourceHelper - @Mock lateinit var dateUtil: DateUtil - @Mock lateinit var translator: Translator - @Mock lateinit var profileFunction: ProfileFunction @Mock lateinit var userEntryPresentationHelper: UserEntryPresentationHelper @Mock lateinit var file: MockedFile @@ -30,7 +24,7 @@ class ClassicPrefsFormatTest : TestBase() { fun preferenceLoadingTest() { val test = "key1::val1\nkeyB::valB" - val classicFormat = ClassicPrefsFormat(resourceHelper, dateUtil, translator, profileFunction, userEntryPresentationHelper, SingleStringStorage(test)) + val classicFormat = ClassicPrefsFormat(resourceHelper, userEntryPresentationHelper, SingleStringStorage(test)) val prefs = classicFormat.loadPreferences(getMockedFile(), "") Assert.assertEquals(prefs.values.size, 2) @@ -42,7 +36,7 @@ class ClassicPrefsFormatTest : TestBase() { @Test fun preferenceSavingTest() { val storage = SingleStringStorage("") - val classicFormat = ClassicPrefsFormat(resourceHelper, dateUtil, translator, profileFunction, userEntryPresentationHelper, storage) + val classicFormat = ClassicPrefsFormat(resourceHelper, userEntryPresentationHelper, storage) val prefs = Prefs( mapOf( "key1" to "A",