2020-03-19 18:02:24 +01:00
|
|
|
package info.nightscout.androidaps
|
|
|
|
|
|
|
|
import dagger.android.AndroidInjector
|
|
|
|
import dagger.android.HasAndroidInjector
|
|
|
|
import info.nightscout.androidaps.data.Profile
|
|
|
|
import info.nightscout.androidaps.db.ProfileSwitch
|
2021-02-18 20:45:32 +01:00
|
|
|
import info.nightscout.androidaps.db.Treatment
|
2020-03-19 18:02:24 +01:00
|
|
|
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
2021-02-18 20:45:32 +01:00
|
|
|
import info.nightscout.androidaps.interfaces.ConfigInterface
|
2020-05-07 09:54:36 +02:00
|
|
|
import info.nightscout.androidaps.interfaces.ProfileFunction
|
2021-02-18 20:45:32 +01:00
|
|
|
import info.nightscout.androidaps.interfaces.ProfileStore
|
|
|
|
import info.nightscout.androidaps.interfaces.TreatmentsInterface
|
|
|
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
2020-05-07 23:40:59 +02:00
|
|
|
import info.nightscout.androidaps.utils.DateUtil
|
2020-04-20 19:27:54 +02:00
|
|
|
import info.nightscout.androidaps.utils.DefaultValueHelper
|
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
|
2020-03-19 21:24:48 +01:00
|
|
|
import org.powermock.core.classloader.annotations.PrepareForTest
|
2020-03-19 18:02:24 +01:00
|
|
|
|
2020-03-19 21:24:48 +01:00
|
|
|
@PrepareForTest(FabricPrivacy::class)
|
2020-03-19 18:02:24 +01:00
|
|
|
open class TestBaseWithProfile : TestBase() {
|
2021-02-18 20:45:32 +01:00
|
|
|
|
2020-03-19 18:02:24 +01:00
|
|
|
@Mock lateinit var activePluginProvider: ActivePluginProvider
|
|
|
|
@Mock lateinit var resourceHelper: ResourceHelper
|
2021-02-18 20:45:32 +01:00
|
|
|
@Mock lateinit var treatmentsPlugin: TreatmentsInterface
|
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
|
|
|
|
@Mock lateinit var defaultValueHelper: DefaultValueHelper
|
2020-05-07 23:40:59 +02:00
|
|
|
@Mock lateinit var dateUtil: DateUtil
|
2021-02-18 20:45:32 +01:00
|
|
|
@Mock lateinit var configInterface: ConfigInterface
|
2020-03-19 18:02:24 +01:00
|
|
|
|
2021-02-04 20:54:09 +01:00
|
|
|
val rxBus = RxBusWrapper(aapsSchedulers)
|
2020-03-19 18:02:24 +01:00
|
|
|
|
|
|
|
val profileInjector = HasAndroidInjector {
|
|
|
|
AndroidInjector {
|
|
|
|
if (it is Profile) {
|
|
|
|
it.aapsLogger = aapsLogger
|
|
|
|
it.activePlugin = activePluginProvider
|
|
|
|
it.resourceHelper = resourceHelper
|
|
|
|
it.rxBus = rxBus
|
2020-03-19 21:24:48 +01:00
|
|
|
it.fabricPrivacy = fabricPrivacy
|
2021-02-18 20:45:32 +01:00
|
|
|
it.configInterface = configInterface
|
2020-03-19 18:02:24 +01:00
|
|
|
}
|
|
|
|
if (it is ProfileSwitch) {
|
|
|
|
it.treatmentsPlugin = treatmentsPlugin
|
|
|
|
it.aapsLogger = aapsLogger
|
|
|
|
it.rxBus = rxBus
|
|
|
|
it.resourceHelper = resourceHelper
|
2020-05-07 23:40:59 +02:00
|
|
|
it.dateUtil = dateUtil
|
2020-03-19 18:02:24 +01:00
|
|
|
}
|
2020-04-20 19:27:54 +02:00
|
|
|
if (it is Treatment) {
|
|
|
|
it.activePlugin = activePluginProvider
|
|
|
|
it.profileFunction = profileFunction
|
|
|
|
it.defaultValueHelper = defaultValueHelper
|
|
|
|
it.resourceHelper = resourceHelper
|
|
|
|
}
|
2020-03-19 18:02:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-04 20:54:09 +01:00
|
|
|
private lateinit var validProfileJSON: String
|
2020-03-19 18:02:24 +01:00
|
|
|
lateinit var validProfile: Profile
|
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\"}"
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|