:app module refactor

This commit is contained in:
Milos Kozak 2023-09-23 16:30:25 +02:00
parent a0b4fbcd21
commit 2ed2fa0d17
46 changed files with 119 additions and 486 deletions

View file

@ -3,7 +3,9 @@
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.BLUETOOTH" tools:remove="android:maxSdkVersion" />
<uses-permission
android:name="android.permission.BLUETOOTH"
tools:remove="android:maxSdkVersion" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
@ -32,9 +34,9 @@
<uses-permission android:name="com.microtechmd.cgms.aidex.permissions.RECEIVE_BG_ESTIMATE" />
<application
android:name=".MainApp"
android:name="app.aaps.MainApp"
android:allowBackup="true"
android:backupAgent=".utils.SPBackupAgent"
android:backupAgent="app.aaps.utils.SPBackupAgent"
android:fullBackupOnly="false"
android:icon="${appIcon}"
android:label="@string/app_name"
@ -56,7 +58,7 @@
android:resource="@xml/automotive_app_desc" />
<activity
android:name=".MainActivity"
android:name="app.aaps.MainActivity"
android:exported="true"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
@ -67,16 +69,16 @@
</intent-filter>
</activity>
<activity
android:name=".activities.PreferencesActivity"
android:name="app.aaps.activities.PreferencesActivity"
android:exported="false"
android:theme="@style/AppTheme"/>
android:theme="@style/AppTheme" />
<activity
android:name=".activities.HistoryBrowseActivity"
android:name="app.aaps.activities.HistoryBrowseActivity"
android:exported="false"
android:theme="@style/AppTheme" />
<!-- Receive new BG readings from other local apps -->
<receiver
android:name=".receivers.DataReceiver"
android:name="app.aaps.receivers.DataReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
@ -100,7 +102,7 @@
<!-- Receive new SMS messages -->
<receiver
android:name=".receivers.SmsReceiver"
android:name="app.aaps.receivers.SmsReceiver"
android:enabled="true"
android:exported="true"
android:permission="android.permission.BROADCAST_SMS">
@ -114,7 +116,7 @@
<!-- Auto start -->
<receiver
android:name=".receivers.AutoStartReceiver"
android:name="app.aaps.receivers.AutoStartReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>

View file

@ -1,13 +0,0 @@
package info.nightscout.androidaps.di
import dagger.Module
import dagger.android.ContributesAndroidInjector
import info.nightscout.androidaps.activities.MyPreferenceFragment
@Module
@Suppress("unused")
abstract class FragmentsModule {
@ContributesAndroidInjector abstract fun contributesPreferencesFragment(): MyPreferenceFragment
}

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps
package app.aaps
import android.content.Context
import android.content.Intent
@ -29,6 +29,8 @@ import androidx.core.view.GravityCompat
import androidx.core.view.MenuCompat
import androidx.core.view.MenuProvider
import androidx.viewpager2.widget.ViewPager2
import app.aaps.activities.HistoryBrowseActivity
import app.aaps.activities.PreferencesActivity
import app.aaps.configuration.activities.DaggerAppCompatActivityWithResult
import app.aaps.configuration.activities.SingleFragmentActivity
import app.aaps.configuration.setupwizard.SetupWizardActivity
@ -37,8 +39,8 @@ import com.google.android.material.tabs.TabLayoutMediator
import com.google.firebase.crashlytics.FirebaseCrashlytics
import com.joanzapata.iconify.Iconify
import com.joanzapata.iconify.fonts.FontAwesomeModule
import info.nightscout.androidaps.activities.HistoryBrowseActivity
import info.nightscout.androidaps.activities.PreferencesActivity
import info.nightscout.androidaps.BuildConfig
import info.nightscout.androidaps.R
import info.nightscout.androidaps.databinding.ActivityMainBinding
import info.nightscout.core.ui.UIRunnable
import info.nightscout.core.ui.dialogs.OKDialog

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps
package app.aaps
import android.bluetooth.BluetoothDevice
import android.content.Intent
@ -13,13 +13,15 @@ import androidx.work.Data
import androidx.work.ExistingPeriodicWorkPolicy
import androidx.work.PeriodicWorkRequest
import androidx.work.WorkManager
import app.aaps.di.DaggerAppComponent
import app.aaps.receivers.BTReceiver
import app.aaps.receivers.ChargingStateReceiver
import app.aaps.receivers.KeepAliveWorker
import app.aaps.receivers.TimeDateOrTZChangeReceiver
import dagger.android.AndroidInjector
import dagger.android.DaggerApplication
import info.nightscout.androidaps.di.DaggerAppComponent
import info.nightscout.androidaps.receivers.BTReceiver
import info.nightscout.androidaps.receivers.ChargingStateReceiver
import info.nightscout.androidaps.receivers.KeepAliveWorker
import info.nightscout.androidaps.receivers.TimeDateOrTZChangeReceiver
import info.nightscout.androidaps.BuildConfig
import info.nightscout.androidaps.R
import info.nightscout.core.ui.locale.LocaleHelper
import info.nightscout.database.entities.TherapyEvent
import info.nightscout.database.entities.UserEntry

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.activities
package app.aaps.activities
import android.annotation.SuppressLint
import android.content.Context

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.activities
package app.aaps.activities
import dagger.android.HasAndroidInjector
import info.nightscout.core.graph.OverviewData

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.activities
package app.aaps.activities
import android.annotation.SuppressLint
import android.content.Context

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.activities
package app.aaps.activities
import android.os.Bundle
import android.view.Menu

View file

@ -1,10 +1,11 @@
package info.nightscout.androidaps.di
package app.aaps.di
import app.aaps.MainActivity
import app.aaps.activities.HistoryBrowseActivity
import app.aaps.activities.MyPreferenceFragment
import app.aaps.activities.PreferencesActivity
import dagger.Module
import dagger.android.ContributesAndroidInjector
import info.nightscout.androidaps.MainActivity
import info.nightscout.androidaps.activities.HistoryBrowseActivity
import info.nightscout.androidaps.activities.PreferencesActivity
@Module
@Suppress("unused")
@ -13,5 +14,5 @@ abstract class ActivitiesModule {
@ContributesAndroidInjector abstract fun contributesHistoryBrowseActivity(): HistoryBrowseActivity
@ContributesAndroidInjector abstract fun contributesMainActivity(): MainActivity
@ContributesAndroidInjector abstract fun contributesPreferencesActivity(): PreferencesActivity
@ContributesAndroidInjector abstract fun contributesPreferencesFragment(): MyPreferenceFragment
}

View file

@ -1,12 +1,12 @@
package info.nightscout.androidaps.di
package app.aaps.di
import app.aaps.MainApp
import app.aaps.configuration.di.ConfigurationModule
import app.aaps.shared.impl.di.SharedImplModule
import dagger.BindsInstance
import dagger.Component
import dagger.android.AndroidInjectionModule
import dagger.android.AndroidInjector
import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.danar.di.DanaRModule
import info.nightscout.androidaps.insight.di.InsightDatabaseModule
import info.nightscout.androidaps.insight.di.InsightModule
@ -47,7 +47,6 @@ import javax.inject.Singleton
AppModule::class,
PluginsListModule::class,
ActivitiesModule::class,
FragmentsModule::class,
ReceiversModule::class,
// Gradle modules

View file

@ -1,16 +1,16 @@
package info.nightscout.androidaps.di
package app.aaps.di
import android.content.Context
import app.aaps.MainApp
import app.aaps.implementations.ConfigImpl
import app.aaps.implementations.InstantiatorImpl
import app.aaps.implementations.UiInteractionImpl
import app.aaps.workflow.CalculationWorkflowImpl
import dagger.Binds
import dagger.Lazy
import dagger.Module
import dagger.Provides
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.implementations.ConfigImpl
import info.nightscout.androidaps.implementations.InstantiatorImpl
import info.nightscout.androidaps.implementations.UiInteractionImpl
import info.nightscout.androidaps.workflow.CalculationWorkflowImpl
import info.nightscout.core.workflow.CalculationWorkflow
import info.nightscout.interfaces.Config
import info.nightscout.interfaces.plugin.PluginBase

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.di
package app.aaps.di
import app.aaps.configuration.configBuilder.ConfigBuilderPlugin
import app.aaps.configuration.maintenance.MaintenancePlugin

View file

@ -1,14 +1,14 @@
package info.nightscout.androidaps.di
package app.aaps.di
import app.aaps.receivers.AutoStartReceiver
import app.aaps.receivers.BTReceiver
import app.aaps.receivers.ChargingStateReceiver
import app.aaps.receivers.DataReceiver
import app.aaps.receivers.KeepAliveWorker
import app.aaps.receivers.SmsReceiver
import app.aaps.receivers.TimeDateOrTZChangeReceiver
import dagger.Module
import dagger.android.ContributesAndroidInjector
import info.nightscout.androidaps.receivers.AutoStartReceiver
import info.nightscout.androidaps.receivers.BTReceiver
import info.nightscout.androidaps.receivers.ChargingStateReceiver
import info.nightscout.androidaps.receivers.DataReceiver
import info.nightscout.androidaps.receivers.KeepAliveWorker
import info.nightscout.androidaps.receivers.SmsReceiver
import info.nightscout.androidaps.receivers.TimeDateOrTZChangeReceiver
@Module
@Suppress("unused")

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.implementations
package app.aaps.implementations
import android.os.Build
import info.nightscout.androidaps.BuildConfig

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.implementations
package app.aaps.implementations
import dagger.Reusable
import dagger.android.HasAndroidInjector

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.implementations
package app.aaps.implementations
import android.content.Context
import android.content.Intent
@ -6,13 +6,13 @@ import android.os.Bundle
import androidx.annotation.RawRes
import androidx.annotation.StringRes
import androidx.fragment.app.FragmentManager
import app.aaps.MainActivity
import app.aaps.activities.HistoryBrowseActivity
import app.aaps.activities.MyPreferenceFragment
import app.aaps.activities.PreferencesActivity
import app.aaps.configuration.activities.SingleFragmentActivity
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.MainActivity
import info.nightscout.androidaps.R
import info.nightscout.androidaps.activities.HistoryBrowseActivity
import info.nightscout.androidaps.activities.MyPreferenceFragment
import info.nightscout.androidaps.activities.PreferencesActivity
import info.nightscout.core.events.EventNewNotification
import info.nightscout.core.ui.toast.ToastUtils
import info.nightscout.interfaces.notifications.Notification

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.receivers
package app.aaps.receivers
import android.content.Context
import android.content.Intent

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.receivers
package app.aaps.receivers
import android.bluetooth.BluetoothDevice
import android.content.Context
@ -20,6 +20,7 @@ class BTReceiver : DaggerBroadcastReceiver() {
when (intent.action) {
BluetoothDevice.ACTION_ACL_CONNECTED ->
rxBus.send(EventBTChange(EventBTChange.Change.CONNECT, deviceName = device.name, deviceAddress = device.address))
BluetoothDevice.ACTION_ACL_DISCONNECTED ->
rxBus.send(EventBTChange(EventBTChange.Change.DISCONNECT, deviceName = device.name, deviceAddress = device.address))
}

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.receivers
package app.aaps.receivers
import android.content.Context
import android.content.Intent
@ -13,6 +13,7 @@ import info.nightscout.rx.logging.LTag
import javax.inject.Inject
class ChargingStateReceiver : DaggerBroadcastReceiver() {
@Inject lateinit var aapsLogger: AAPSLogger
@Inject lateinit var rxBus: RxBus
@Inject lateinit var receiverStatusStore: ReceiverStatusStore
@ -22,7 +23,8 @@ class ChargingStateReceiver : DaggerBroadcastReceiver() {
rxBus.send(grabChargingState(context))
aapsLogger.debug(
LTag.CORE, receiverStatusStore.lastChargingEvent?.toString()
?: "Unknown charging state")
?: "Unknown charging state"
)
}
private fun grabChargingState(context: Context): EventChargingState {

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.receivers
package app.aaps.receivers
import android.content.Context
import android.content.Intent
@ -39,11 +39,13 @@ open class DataReceiver : DaggerBroadcastReceiver() {
Intents.ACTION_NEW_BG_ESTIMATE ->
OneTimeWorkRequest.Builder(XdripSourcePlugin.XdripSourceWorker::class.java)
.setInputData(dataWorkerStorage.storeInputData(bundle, intent.action)).build()
Intents.POCTECH_BG ->
OneTimeWorkRequest.Builder(PoctechPlugin.PoctechWorker::class.java)
.setInputData(Data.Builder().also {
it.copyString("data", bundle)
}.build()).build()
Intents.GLIMP_BG ->
OneTimeWorkRequest.Builder(GlimpPlugin.GlimpWorker::class.java)
.setInputData(Data.Builder().also {
@ -51,6 +53,7 @@ open class DataReceiver : DaggerBroadcastReceiver() {
it.copyString("myTrend", bundle)
it.copyLong("myTimestamp", bundle)
}.build()).build()
Intents.TOMATO_BG ->
@Suppress("SpellCheckingInspection")
OneTimeWorkRequest.Builder(TomatoPlugin.TomatoWorker::class.java)
@ -58,15 +61,18 @@ open class DataReceiver : DaggerBroadcastReceiver() {
it.copyDouble("com.fanqies.tomatofn.Extras.BgEstimate", bundle)
it.copyLong("com.fanqies.tomatofn.Extras.Time", bundle)
}.build()).build()
Intents.NS_EMULATOR ->
OneTimeWorkRequest.Builder(MM640gPlugin.MM640gWorker::class.java)
.setInputData(Data.Builder().also {
it.copyString("collection", bundle)
it.copyString("data", bundle)
}.build()).build()
Telephony.Sms.Intents.SMS_RECEIVED_ACTION ->
OneTimeWorkRequest.Builder(SmsCommunicatorPlugin.SmsCommunicatorWorker::class.java)
.setInputData(dataWorkerStorage.storeInputData(bundle, intent.action)).build()
Intents.EVERSENSE_BG ->
OneTimeWorkRequest.Builder(EversensePlugin.EversenseWorker::class.java)
.setInputData(dataWorkerStorage.storeInputData(bundle, intent.action)).build()
@ -78,6 +84,7 @@ open class DataReceiver : DaggerBroadcastReceiver() {
Intents.AIDEX_NEW_BG_ESTIMATE ->
OneTimeWorkRequest.Builder(AidexPlugin.AidexWorker::class.java)
.setInputData(dataWorkerStorage.storeInputData(bundle, intent.action)).build()
else -> null
}?.let { request -> dataWorkerStorage.enqueue(request) }
}

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.receivers
package app.aaps.receivers
import android.content.Context
import androidx.work.Data

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.receivers
package app.aaps.receivers
/**
* Forward received SMS intents. This is a separate class, because unlike local broadcasts handled by DataReceiver,

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.receivers
package app.aaps.receivers
import android.content.Context
import android.content.Intent
@ -15,6 +15,7 @@ import java.util.TimeZone
import javax.inject.Inject
class TimeDateOrTZChangeReceiver : DaggerBroadcastReceiver() {
@Inject lateinit var aapsLogger: AAPSLogger
@Inject lateinit var activePlugin: ActivePlugin
val gson: Gson = Gson()

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.utils
package app.aaps.utils
import android.app.backup.BackupAgentHelper
import android.app.backup.SharedPreferencesBackupHelper

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.workflow
package app.aaps.workflow
import android.content.Context
import android.os.SystemClock

View file

@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="info.nightscout.androidaps.activities.HistoryBrowseActivity">
tools:context="info.nightscout.androidaps.app.aaps.activities.HistoryBrowseActivity">
<LinearLayout
android:layout_width="match_parent"

View file

@ -1,7 +1,7 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".MainActivity">
tools:context="app.aaps.MainActivity">
<item
android:id="@+id/nav_preferences"
@ -33,12 +33,12 @@
android:orderInCategory="1"
app:showAsAction="never"
android:title="@string/statistics" />
<!-- <item
<!-- <item
android:id="@+id/nav_survey"
android:orderInCategory="1"
app:showAsAction="never"
android:title="@string/nav_survey" />
-->
-->
<item
android:id="@+id/nav_defaultprofile"
android:orderInCategory="1"

View file

@ -1,41 +0,0 @@
package info.nightscout.plugins.configBuilder
import app.aaps.configuration.configBuilder.ConfigBuilderPlugin
import app.aaps.shared.tests.TestBase
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.interfaces.logging.UserEntryLogger
import info.nightscout.interfaces.plugin.ActivePlugin
import info.nightscout.interfaces.protection.ProtectionCheck
import info.nightscout.interfaces.pump.PumpSync
import info.nightscout.interfaces.ui.UiInteraction
import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.sharedPreferences.SP
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.Mock
class ConfigBuilderPluginTest : TestBase() {
@Mock lateinit var sp: SP
@Mock lateinit var rh: ResourceHelper
@Mock lateinit var activePlugin: ActivePlugin
@Mock lateinit var uel: UserEntryLogger
@Mock lateinit var pumpSync: PumpSync
@Mock lateinit var protectionCheck: ProtectionCheck
@Mock lateinit var uiInteraction: UiInteraction
private lateinit var configBuilderPlugin: ConfigBuilderPlugin
private val injector = HasAndroidInjector { AndroidInjector { } }
@Test
fun dummy() {
}
@BeforeEach
fun prepareMock() {
configBuilderPlugin = ConfigBuilderPlugin(injector, aapsLogger, rh, sp, rxBus, activePlugin, uel, pumpSync, protectionCheck, uiInteraction)
}
}

View file

@ -24,6 +24,8 @@ dependencies {
implementation project(':core:utils')
testImplementation project(':shared:tests')
testImplementation project(':plugins:aps')
testImplementation project(':pump:virtual')
// Protection
api 'androidx.biometric:biometric:1.1.0'

View file

@ -1,11 +1,10 @@
package info.nightscout.pump
package info.nightscout.interfaces.pump
import app.aaps.shared.tests.TestBaseWithProfile
import com.google.common.truth.Truth.assertThat
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.core.pump.toHtml
import info.nightscout.interfaces.pump.PumpEnactResult
import info.nightscout.plugins.aps.loop.extensions.json
import info.nightscout.pump.virtual.extensions.toText
import org.json.JSONObject

View file

@ -24,6 +24,7 @@ dependencies {
implementation project(':core:ui')
implementation project(':core:validators')
testImplementation project(':pump:virtual')
testImplementation project(':shared:tests')
api "androidx.appcompat:appcompat:$appcompat_version"

View file

@ -1,338 +0,0 @@
package info.nightscout.plugins.aps.loop
import app.aaps.shared.tests.TestBaseWithProfile
import com.google.common.truth.Truth.assertThat
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.core.constraints.ConstraintObject
import info.nightscout.core.utils.JsonHelper.safeGetDouble
import info.nightscout.database.entities.TemporaryBasal
import info.nightscout.interfaces.aps.APSResult
import info.nightscout.interfaces.constraints.Constraint
import info.nightscout.interfaces.constraints.ConstraintsChecker
import info.nightscout.interfaces.pump.defs.PumpType
import info.nightscout.plugins.aps.APSResultObject
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.ArgumentMatchers
import org.mockito.Mock
import org.mockito.Mockito.`when`
class APSResultTest : TestBaseWithProfile() {
@Mock lateinit var constraintsChecker: ConstraintsChecker
private val injector = HasAndroidInjector { AndroidInjector { } }
private lateinit var closedLoopEnabled: Constraint<Boolean>
private fun APSResult.percent(percent: Int): APSResult {
this.percent = percent
return this
}
private fun APSResult.rate(rate: Double): APSResult {
this.rate = rate
return this
}
private fun APSResult.duration(duration: Int): APSResult {
this.duration = duration
return this
}
private fun APSResult.usePercent(usePercent: Boolean): APSResult {
this.usePercent = usePercent
return this
}
private fun APSResult.tempBasalRequested(tempBasalRequested: Boolean): APSResult {
this.isTempBasalRequested = tempBasalRequested
return this
}
@Test
fun changeRequestedTest() {
val apsResult = APSResultObject { AndroidInjector { } }
.also {
it.aapsLogger = aapsLogger
it.constraintChecker = constraintsChecker
it.sp = sp
it.activePlugin = activePlugin
it.iobCobCalculator = iobCobCalculator
it.profileFunction = profileFunction
it.rh = rh
}
// BASAL RATE IN TEST PROFILE IS 1U/h
// **** PERCENT pump ****
testPumpPlugin.pumpDescription.fillFor(PumpType.CELLNOVO) // % based
apsResult.usePercent(true)
// closed loop mode return original request
closedLoopEnabled.set(true)
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(null)
apsResult.tempBasalRequested(false)
assertThat(apsResult.isChangeRequested).isFalse()
apsResult.tempBasalRequested(true).percent(200).duration(30)
assertThat(apsResult.isChangeRequested).isTrue()
// open loop
closedLoopEnabled.set(false)
// no change requested
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(null)
apsResult.tempBasalRequested(false)
assertThat(apsResult.isChangeRequested).isFalse()
// request 100% when no temp is running
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(null)
apsResult.tempBasalRequested(true).percent(100).duration(30)
assertThat(apsResult.isChangeRequested).isFalse()
// request equal temp
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
TemporaryBasal(
timestamp = 0,
rate = 70.0,
duration = 30,
isAbsolute = false,
type = TemporaryBasal.Type.NORMAL
)
)
apsResult.tempBasalRequested(true).percent(70).duration(30)
assertThat(apsResult.isChangeRequested).isFalse()
// request zero temp
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
TemporaryBasal(
timestamp = 0,
rate = 10.0,
duration = 30,
isAbsolute = false,
type = TemporaryBasal.Type.NORMAL
)
)
apsResult.tempBasalRequested(true).percent(0).duration(30)
assertThat(apsResult.isChangeRequested).isTrue()
// request high temp
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
TemporaryBasal(
timestamp = 0,
rate = 190.0,
duration = 30,
isAbsolute = false,
type = TemporaryBasal.Type.NORMAL
)
)
apsResult.tempBasalRequested(true).percent(200).duration(30)
assertThat(apsResult.isChangeRequested).isTrue()
// request slightly different temp
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
TemporaryBasal(
timestamp = 0,
rate = 70.0,
duration = 30,
isAbsolute = false,
type = TemporaryBasal.Type.NORMAL
)
)
apsResult.tempBasalRequested(true).percent(80).duration(30)
assertThat(apsResult.isChangeRequested).isFalse()
// request different temp
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
TemporaryBasal(
timestamp = 0,
rate = 70.0,
duration = 30,
isAbsolute = false,
type = TemporaryBasal.Type.NORMAL
)
)
apsResult.tempBasalRequested(true).percent(120).duration(30)
assertThat(apsResult.isChangeRequested).isTrue()
// it should work with absolute temps too
// request different temp
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
TemporaryBasal(
timestamp = 0,
rate = 1.0,
duration = 30,
isAbsolute = true,
type = TemporaryBasal.Type.NORMAL
)
)
apsResult.tempBasalRequested(true).percent(100).duration(30)
assertThat(apsResult.isChangeRequested).isFalse()
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
TemporaryBasal(
timestamp = 0,
rate = 2.0,
duration = 30,
isAbsolute = true,
type = TemporaryBasal.Type.NORMAL
)
)
apsResult.tempBasalRequested(true).percent(50).duration(30)
assertThat(apsResult.isChangeRequested).isTrue()
// **** ABSOLUTE pump ****
testPumpPlugin.pumpDescription.fillFor(PumpType.MEDTRONIC_515_715) // U/h based
apsResult.usePercent(false)
// open loop
closedLoopEnabled.set(false)
// request 100% when no temp is running
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(null)
apsResult.tempBasalRequested(true).rate(1.0).duration(30)
assertThat(apsResult.isChangeRequested).isFalse()
// request equal temp
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
TemporaryBasal(
timestamp = 0,
rate = 2.0,
duration = 30,
isAbsolute = true,
type = TemporaryBasal.Type.NORMAL
)
)
apsResult.tempBasalRequested(true).rate(2.0).duration(30)
assertThat(apsResult.isChangeRequested).isFalse()
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
TemporaryBasal(
timestamp = 0,
rate = 200.0,
duration = 30,
isAbsolute = false,
type = TemporaryBasal.Type.NORMAL
)
)
apsResult.tempBasalRequested(true).rate(2.0).duration(30)
assertThat(apsResult.isChangeRequested).isFalse()
// request zero temp
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
TemporaryBasal(
timestamp = 0,
rate = 0.1,
duration = 30,
isAbsolute = true,
type = TemporaryBasal.Type.NORMAL
)
)
apsResult.tempBasalRequested(true).rate(0.0).duration(30)
assertThat(apsResult.isChangeRequested).isTrue()
// request high temp
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
TemporaryBasal(
timestamp = 0,
rate = 34.9,
duration = 30,
isAbsolute = true,
type = TemporaryBasal.Type.NORMAL
)
)
apsResult.tempBasalRequested(true).rate(35.0).duration(30)
assertThat(apsResult.isChangeRequested).isTrue()
// request slightly different temp
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
TemporaryBasal(
timestamp = 0,
rate = 1.1,
duration = 30,
isAbsolute = true,
type = TemporaryBasal.Type.NORMAL
)
)
apsResult.tempBasalRequested(true).rate(1.2).duration(30)
assertThat(apsResult.isChangeRequested).isFalse()
// request different temp
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
TemporaryBasal(
timestamp = 0,
rate = 1.1,
duration = 30,
isAbsolute = true,
type = TemporaryBasal.Type.NORMAL
)
)
apsResult.tempBasalRequested(true).rate(1.5).duration(30)
assertThat(apsResult.isChangeRequested).isTrue()
// it should work with percent temps too
// request different temp
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
TemporaryBasal(
timestamp = 0,
rate = 110.0,
duration = 30,
isAbsolute = false,
type = TemporaryBasal.Type.NORMAL
)
)
apsResult.tempBasalRequested(true).rate(1.1).duration(30)
assertThat(apsResult.isChangeRequested).isFalse()
`when`(iobCobCalculator.getTempBasalIncludingConvertedExtended(ArgumentMatchers.anyLong())).thenReturn(
TemporaryBasal(
timestamp = 0,
rate = 200.0,
duration = 30,
isAbsolute = false,
type = TemporaryBasal.Type.NORMAL
)
)
apsResult.tempBasalRequested(true).rate(0.5).duration(30)
assertThat(apsResult.isChangeRequested).isTrue()
}
@Test fun cloneTest() {
val apsResult = APSResultObject(injector)
.also {
it.aapsLogger = aapsLogger
it.constraintChecker = constraintsChecker
it.sp = sp
it.activePlugin = activePlugin
it.iobCobCalculator = iobCobCalculator
it.profileFunction = profileFunction
it.rh = rh
}
apsResult.rate(10.0)
val apsResult2 = apsResult.newAndClone(injector)
assertThat(apsResult2.rate).isEqualTo(apsResult.rate)
}
@Test fun jsonTest() {
closedLoopEnabled.set(true)
val apsResult = APSResultObject(injector)
.also {
it.aapsLogger = aapsLogger
it.constraintChecker = constraintsChecker
it.sp = sp
it.activePlugin = activePlugin
it.iobCobCalculator = iobCobCalculator
it.profileFunction = profileFunction
it.rh = rh
}
apsResult.rate(20.0).tempBasalRequested(true)
assertThat(safeGetDouble(apsResult.json(), "rate")).isEqualTo(20.0)
apsResult.rate(20.0).tempBasalRequested(false)
assertThat(apsResult.json()?.has("rate")).isFalse()
}
@BeforeEach
fun prepare() {
closedLoopEnabled = ConstraintObject(false, aapsLogger)
`when`(constraintsChecker.isClosedLoopAllowed()).thenReturn(closedLoopEnabled)
`when`(sp.getDouble(ArgumentMatchers.anyInt(), ArgumentMatchers.anyDouble())).thenReturn(30.0)
`when`(profileFunction.getProfile()).thenReturn(validProfile)
}
}

View file

@ -1,7 +1,6 @@
package info.nightscout.plugins.general.maintenance
package app.aaps.configuration.maintenance
import android.content.Context
import app.aaps.configuration.maintenance.MaintenancePlugin
import app.aaps.shared.tests.TestBase
import com.google.common.truth.Truth.assertThat
import dagger.android.HasAndroidInjector

View file

@ -23,6 +23,16 @@ dependencies {
implementation project(':core:validators')
implementation project(':database:entities')
testImplementation project(':database:impl')
testImplementation project(':implementation')
testImplementation project(':insight')
testImplementation project(':plugins:aps')
testImplementation project(':plugins:source')
testImplementation project(':pump:combo')
testImplementation project(':pump:dana')
testImplementation project(':pump:danar')
testImplementation project(':pump:danars')
testImplementation project(':pump:virtual')
testImplementation project(':shared:tests')
// Phone checker

View file

@ -5,7 +5,6 @@ import com.google.common.truth.Truth.assertThat
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.danar.DanaRPlugin
import info.nightscout.androidaps.implementations.ConfigImpl
import info.nightscout.androidaps.insight.database.InsightDatabase
import info.nightscout.androidaps.insight.database.InsightDatabaseDao
import info.nightscout.androidaps.insight.database.InsightDbHelper
@ -17,7 +16,6 @@ import info.nightscout.interfaces.bgQualityCheck.BgQualityCheck
import info.nightscout.interfaces.constraints.Constraint
import info.nightscout.interfaces.constraints.Objectives
import info.nightscout.interfaces.constraints.PluginConstraints
import info.nightscout.interfaces.maintenance.PrefFileListProvider
import info.nightscout.interfaces.plugin.PluginBase
import info.nightscout.interfaces.plugin.PluginType
import info.nightscout.interfaces.profile.Instantiator
@ -52,7 +50,7 @@ import org.mockito.Mockito.`when`
/**
* Created by mike on 18.03.2018.
*/
class ConstraintsCheckerTest : TestBaseWithProfile() {
class ConstraintsCheckerImplTest : TestBaseWithProfile() {
@Mock lateinit var virtualPumpPlugin: VirtualPumpPlugin
@Mock lateinit var commandQueue: CommandQueue
@ -60,7 +58,6 @@ class ConstraintsCheckerTest : TestBaseWithProfile() {
@Mock lateinit var temporaryBasalStorage: TemporaryBasalStorage
@Mock lateinit var glimpPlugin: GlimpPlugin
@Mock lateinit var profiler: Profiler
@Mock lateinit var fileListProvider: PrefFileListProvider
@Mock lateinit var repository: AppRepository
@Mock lateinit var pumpSync: PumpSync
@Mock lateinit var insightDatabaseDao: InsightDatabaseDao
@ -215,7 +212,7 @@ class ConstraintsCheckerTest : TestBaseWithProfile() {
safetyPlugin =
SafetyPlugin(
injector, aapsLogger, rh, sp, constraintChecker, activePlugin, hardLimits,
ConfigImpl(fileListProvider), iobCobCalculator, dateUtil, uiInteraction, decimalFormatter
config, iobCobCalculator, dateUtil, uiInteraction, decimalFormatter
)
val constraintsPluginsList = ArrayList<PluginBase>()
constraintsPluginsList.add(safetyPlugin)

View file

@ -1,4 +1,4 @@
package info.nightscout.plugins.safety
package info.nightscout.plugins.constraints.safety
import app.aaps.shared.tests.TestBaseWithProfile
import com.google.common.truth.Truth.assertThat
@ -19,7 +19,6 @@ import info.nightscout.interfaces.ui.UiInteraction
import info.nightscout.interfaces.utils.HardLimits
import info.nightscout.plugins.aps.openAPSAMA.OpenAPSAMAPlugin
import info.nightscout.plugins.aps.openAPSSMB.OpenAPSSMBPlugin
import info.nightscout.plugins.constraints.safety.SafetyPlugin
import info.nightscout.pump.virtual.VirtualPumpPlugin
import info.nightscout.source.GlimpPlugin
import org.junit.jupiter.api.BeforeEach

View file

@ -22,4 +22,6 @@ dependencies {
implementation project(':core:utils')
implementation project(':core:ui')
implementation project(':core:validators')
testImplementation project(':shared:tests')
}

View file

@ -1,4 +1,4 @@
package info.nightscout.plugins.sensitivity
package info.nightscout.sensitivity
import app.aaps.shared.tests.TestBase
import com.google.common.truth.Truth.assertThat
@ -9,7 +9,6 @@ import info.nightscout.interfaces.aps.AutosensResult
import info.nightscout.interfaces.aps.Sensitivity
import info.nightscout.interfaces.plugin.PluginDescription
import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.sensitivity.AbstractSensitivityPlugin
import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.sharedPreferences.SP
import org.json.JSONObject