60 lines
2.5 KiB
Kotlin
60 lines
2.5 KiB
Kotlin
|
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)
|
||
|
}
|
||
|
}
|