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

158 lines
7.1 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
2021-04-29 20:42:45 +02:00
import info.nightscout.androidaps.data.ProfileSealed
import info.nightscout.androidaps.utils.extensions.pureProfileFromJson
import info.nightscout.androidaps.interfaces.ActivePlugin
2022-11-06 18:21:10 +01:00
import info.nightscout.interfaces.Config
2022-03-13 19:32:38 +01:00
import info.nightscout.androidaps.interfaces.IobCobCalculator
import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.androidaps.interfaces.ProfileStore
2022-11-06 12:28:35 +01:00
import info.nightscout.androidaps.interfaces.ResourceHelper
2021-02-19 00:47:22 +01:00
import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.FabricPrivacy
2022-11-06 12:28:35 +01:00
import info.nightscout.rx.bus.RxBus
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)
2021-04-29 20:42:45 +02:00
return ProfileStore(profileInjector, json, dateUtil)
2021-02-19 00:47:22 +01:00
}
2021-11-10 14:11:08 +01:00
}