AndroidAPS/app/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt

75 lines
3.4 KiB
Kotlin
Raw Normal View History

2020-03-19 18:02:24 +01:00
package info.nightscout.androidaps
2021-04-11 17:47:55 +02:00
import android.content.Context
2020-03-19 18:02:24 +01:00
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
2021-04-29 20:42:45 +02:00
import info.nightscout.androidaps.data.ProfileSealed
import info.nightscout.androidaps.database.embedments.InsulinConfiguration
import info.nightscout.androidaps.database.entities.EffectiveProfileSwitch
import info.nightscout.androidaps.extensions.pureProfileFromJson
import info.nightscout.androidaps.interfaces.ActivePlugin
import info.nightscout.androidaps.interfaces.Config
import info.nightscout.androidaps.interfaces.IobCobCalculator
import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.androidaps.interfaces.ProfileStore
2021-02-18 20:45:32 +01:00
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
2020-05-07 23:40:59 +02:00
import info.nightscout.androidaps.utils.DateUtil
2020-03-19 21:24:48 +01:00
import info.nightscout.androidaps.utils.FabricPrivacy
2020-03-19 18:02:24 +01:00
import info.nightscout.androidaps.utils.resources.ResourceHelper
import org.json.JSONObject
import org.junit.Before
import org.mockito.Mock
2021-02-18 21:38:36 +01:00
@Suppress("SpellCheckingInspection")
2020-03-19 18:02:24 +01:00
open class TestBaseWithProfile : TestBase() {
2021-02-18 20:45:32 +01:00
2021-04-14 00:45:30 +02:00
@Mock lateinit var activePluginProvider: ActivePlugin
2020-03-19 18:02:24 +01:00
@Mock lateinit var resourceHelper: ResourceHelper
@Mock lateinit var iobCobCalculator: IobCobCalculator
2020-03-19 21:24:48 +01:00
@Mock lateinit var fabricPrivacy: FabricPrivacy
2020-04-20 19:27:54 +02:00
@Mock lateinit var profileFunction: ProfileFunction
2021-04-14 18:42:12 +02:00
@Mock lateinit var config: Config
2021-04-11 17:47:55 +02:00
@Mock lateinit var context: Context
2020-03-19 18:02:24 +01:00
2021-04-11 17:47:55 +02:00
lateinit var dateUtil: DateUtil
2021-02-04 20:54:09 +01:00
val rxBus = RxBusWrapper(aapsSchedulers)
2020-03-19 18:02:24 +01:00
2021-04-29 20:42:45 +02:00
val profileInjector = HasAndroidInjector { AndroidInjector { } }
2020-03-19 18:02:24 +01:00
2021-02-04 20:54:09 +01:00
private lateinit var validProfileJSON: String
2021-04-29 20:42:45 +02:00
lateinit var validProfile: ProfileSealed.Pure
lateinit var effectiveProfileSwitch: EffectiveProfileSwitch
2021-02-18 20:45:32 +01:00
@Suppress("PropertyName") val TESTPROFILENAME = "someProfile"
2020-03-19 18:02:24 +01:00
@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\"}"
2021-04-11 17:47:55 +02:00
dateUtil = DateUtil(context)
2021-04-29 20:42:45 +02:00
validProfile = ProfileSealed.Pure(pureProfileFromJson(JSONObject(validProfileJSON), dateUtil)!!)
effectiveProfileSwitch = EffectiveProfileSwitch(
timestamp = dateUtil.now(),
basalBlocks = validProfile.basalBlocks,
isfBlocks = validProfile.isfBlocks,
icBlocks = validProfile.icBlocks,
targetBlocks = validProfile.targetBlocks,
glucoseUnit = EffectiveProfileSwitch.GlucoseUnit.MMOL,
originalProfileName = "",
originalCustomizedName = "",
originalTimeshift = 0,
originalPercentage = 100,
originalDuration = 0,
originalEnd = 0,
insulinConfiguration = InsulinConfiguration("", 0, 0)
)
2020-03-19 18:02:24 +01:00
}
fun getValidProfileStore(): ProfileStore {
val json = JSONObject()
val store = JSONObject()
store.put(TESTPROFILENAME, JSONObject(validProfileJSON))
json.put("defaultProfile", TESTPROFILENAME)
json.put("store", store)
2021-04-29 20:42:45 +02:00
return ProfileStore(profileInjector, json, dateUtil)
2020-03-19 18:02:24 +01:00
}
}