AndroidAPS/pump/danar/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt

159 lines
7.2 KiB
Kotlin
Raw Normal View History

2021-02-19 00:47:22 +01:00
package info.nightscout.androidaps
2022-03-13 19:32:38 +01:00
import android.content.Context
2021-02-19 00:47:22 +01:00
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
2022-11-10 19:27:04 +01:00
import info.nightscout.androidaps.extensions.pureProfileFromJson
2022-11-23 14:36:06 +01:00
import info.nightscout.core.profile.ProfileSealed
2022-11-10 16:55:18 +01:00
import info.nightscout.core.profile.ProfileStoreObject
2022-11-21 22:43:34 +01:00
import info.nightscout.core.utils.fabric.FabricPrivacy
2022-11-09 15:56:59 +01:00
import info.nightscout.interfaces.Config
2022-11-11 23:17:09 +01:00
import info.nightscout.interfaces.iob.IobCobCalculator
import info.nightscout.interfaces.plugin.ActivePlugin
2022-11-11 18:54:30 +01:00
import info.nightscout.interfaces.profile.ProfileFunction
2022-11-10 16:55:18 +01:00
import info.nightscout.interfaces.profile.ProfileStore
2022-11-09 15:56:59 +01:00
import info.nightscout.rx.bus.RxBus
import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.utils.DateUtil
2021-02-19 00:47:22 +01:00
import org.json.JSONObject
import org.junit.Before
2022-03-13 19:32:38 +01:00
import org.mockito.ArgumentMatchers.anyDouble
import org.mockito.ArgumentMatchers.anyInt
import org.mockito.ArgumentMatchers.anyString
2021-02-19 00:47:22 +01:00
import org.mockito.Mock
2022-03-13 19:32:38 +01:00
import org.mockito.Mockito
import org.mockito.invocation.InvocationOnMock
2021-02-19 00:47:22 +01:00
@Suppress("SpellCheckingInspection")
open class TestBaseWithProfile : TestBase() {
2021-04-14 00:45:30 +02:00
@Mock lateinit var activePluginProvider: ActivePlugin
2021-11-04 10:56:12 +01:00
@Mock lateinit var rh: ResourceHelper
2022-03-13 19:32:38 +01:00
@Mock lateinit var iobCobCalculator: IobCobCalculator
2021-02-19 00:47:22 +01:00
@Mock lateinit var fabricPrivacy: FabricPrivacy
@Mock lateinit var profileFunction: ProfileFunction
2021-04-14 18:42:12 +02:00
@Mock lateinit var config: Config
2022-03-13 19:32:38 +01:00
@Mock lateinit var context: Context
2021-02-19 00:47:22 +01:00
2022-03-13 19:32:38 +01:00
lateinit var dateUtil: DateUtil
2021-10-30 18:29:00 +02:00
val rxBus = RxBus(aapsSchedulers, aapsLogger)
2021-02-19 00:47:22 +01:00
2022-03-13 19:32:38 +01:00
val profileInjector = HasAndroidInjector { AndroidInjector { } }
2021-02-19 00:47:22 +01:00
private lateinit var validProfileJSON: String
2022-03-13 19:32:38 +01:00
lateinit var validProfile: ProfileSealed.Pure
2021-02-19 00:47:22 +01:00
@Suppress("PropertyName") val TESTPROFILENAME = "someProfile"
@Before
fun prepareMock() {
2021-11-10 14:11:08 +01:00
validProfileJSON = "{\"dia\":\"5\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"3\"}," +
"{\"time\":\"2:00\",\"value\":\"3.4\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4.5\"}]," +
"\"target_high\":[{\"time\":\"00:00\",\"value\":\"7\"}],\"startDate\":\"1970-01-01T00:00:00.000Z\",\"units\":\"mmol\"}"
2022-03-13 19:32:38 +01:00
dateUtil = DateUtil(context)
2021-04-29 20:42:45 +02:00
validProfile = ProfileSealed.Pure(pureProfileFromJson(JSONObject(validProfileJSON), dateUtil)!!)
2022-03-13 19:32:38 +01:00
Mockito.doAnswer { invocation: InvocationOnMock ->
val string = invocation.getArgument<Int>(0)
val arg1 = invocation.getArgument<Int?>(1)
String.format(rh.gs(string), arg1)
}.`when`(rh).gs(anyInt(), anyInt())
Mockito.doAnswer { invocation: InvocationOnMock ->
val string = invocation.getArgument<Int>(0)
val arg1 = invocation.getArgument<Double?>(1)
String.format(rh.gs(string), arg1)
}.`when`(rh).gs(anyInt(), anyDouble())
Mockito.doAnswer { invocation: InvocationOnMock ->
val string = invocation.getArgument<Int>(0)
val arg1 = invocation.getArgument<String?>(1)
String.format(rh.gs(string), arg1)
}.`when`(rh).gs(anyInt(), anyString())
Mockito.doAnswer { invocation: InvocationOnMock ->
val string = invocation.getArgument<Int>(0)
val arg1 = invocation.getArgument<String?>(1)
val arg2 = invocation.getArgument<String?>(2)
String.format(rh.gs(string), arg1, arg2)
}.`when`(rh).gs(anyInt(), anyString(), anyString())
Mockito.doAnswer { invocation: InvocationOnMock ->
val string = invocation.getArgument<Int>(0)
val arg1 = invocation.getArgument<String?>(1)
val arg2 = invocation.getArgument<Int?>(2)
String.format(rh.gs(string), arg1, arg2)
}.`when`(rh).gs(anyInt(), anyString(), anyInt())
Mockito.doAnswer { invocation: InvocationOnMock ->
val string = invocation.getArgument<Int>(0)
val arg1 = invocation.getArgument<Double?>(1)
val arg2 = invocation.getArgument<String?>(2)
String.format(rh.gs(string), arg1, arg2)
}.`when`(rh).gs(anyInt(), anyDouble(), anyString())
Mockito.doAnswer { invocation: InvocationOnMock ->
val string = invocation.getArgument<Int>(0)
val arg1 = invocation.getArgument<Double?>(1)
val arg2 = invocation.getArgument<Int?>(2)
String.format(rh.gs(string), arg1, arg2)
}.`when`(rh).gs(anyInt(), anyDouble(), anyInt())
Mockito.doAnswer { invocation: InvocationOnMock ->
val string = invocation.getArgument<Int>(0)
val arg1 = invocation.getArgument<Int?>(1)
val arg2 = invocation.getArgument<Int?>(2)
String.format(rh.gs(string), arg1, arg2)
}.`when`(rh).gs(anyInt(), anyInt(), anyInt())
Mockito.doAnswer { invocation: InvocationOnMock ->
val string = invocation.getArgument<Int>(0)
val arg1 = invocation.getArgument<Int?>(1)
val arg2 = invocation.getArgument<String?>(2)
String.format(rh.gs(string), arg1, arg2)
}.`when`(rh).gs(anyInt(), anyInt(), anyString())
Mockito.doAnswer { invocation: InvocationOnMock ->
val string = invocation.getArgument<Int>(0)
val arg1 = invocation.getArgument<Int?>(1)
val arg2 = invocation.getArgument<Int?>(2)
val arg3 = invocation.getArgument<String?>(3)
String.format(rh.gs(string), arg1, arg2, arg3)
}.`when`(rh).gs(anyInt(), anyInt(), anyInt(), anyString())
Mockito.doAnswer { invocation: InvocationOnMock ->
val string = invocation.getArgument<Int>(0)
val arg1 = invocation.getArgument<Int?>(1)
val arg2 = invocation.getArgument<String?>(2)
val arg3 = invocation.getArgument<String?>(3)
String.format(rh.gs(string), arg1, arg2, arg3)
}.`when`(rh).gs(anyInt(), anyInt(), anyString(), anyString())
Mockito.doAnswer { invocation: InvocationOnMock ->
val string = invocation.getArgument<Int>(0)
val arg1 = invocation.getArgument<Double?>(1)
val arg2 = invocation.getArgument<Int?>(2)
val arg3 = invocation.getArgument<String?>(3)
String.format(rh.gs(string), arg1, arg2, arg3)
}.`when`(rh).gs(anyInt(), anyDouble(), anyInt(), anyString())
Mockito.doAnswer { invocation: InvocationOnMock ->
val string = invocation.getArgument<Int>(0)
val arg1 = invocation.getArgument<String?>(1)
val arg2 = invocation.getArgument<Int?>(2)
val arg3 = invocation.getArgument<String?>(3)
String.format(rh.gs(string), arg1, arg2, arg3)
}.`when`(rh).gs(anyInt(), anyString(), anyInt(), anyString())
2021-02-19 00:47:22 +01:00
}
fun getValidProfileStore(): ProfileStore {
val json = JSONObject()
val store = JSONObject()
store.put(TESTPROFILENAME, JSONObject(validProfileJSON))
json.put("defaultProfile", TESTPROFILENAME)
json.put("store", store)
2022-11-10 16:55:18 +01:00
return ProfileStoreObject(profileInjector, json, dateUtil)
2021-02-19 00:47:22 +01:00
}
2021-11-10 14:11:08 +01:00
}