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
|
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-21 22:43:34 +01:00
|
|
|
import info.nightscout.core.utils.fabric.FabricPrivacy
|
2022-11-09 23:28:48 +01:00
|
|
|
import info.nightscout.database.entities.EffectiveProfileSwitch
|
|
|
|
import info.nightscout.database.entities.embedments.InsulinConfiguration
|
2022-11-25 21:08:03 +01:00
|
|
|
import info.nightscout.implementation.profile.ProfileStoreObject
|
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
|
2022-11-08 11:08:14 +01:00
|
|
|
import info.nightscout.shared.interfaces.ResourceHelper
|
|
|
|
import info.nightscout.shared.utils.DateUtil
|
2020-03-19 18:02:24 +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
|
2020-03-19 18:02:24 +01:00
|
|
|
import org.mockito.Mock
|
2022-03-13 19:32:38 +01:00
|
|
|
import org.mockito.Mockito
|
2022-06-27 21:59:40 +02:00
|
|
|
import org.mockito.Mockito.`when`
|
2022-03-13 19:32:38 +01:00
|
|
|
import org.mockito.invocation.InvocationOnMock
|
2020-03-19 18:02:24 +01:00
|
|
|
|
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
|
2021-11-04 10:56:12 +01:00
|
|
|
@Mock lateinit var rh: ResourceHelper
|
2021-04-05 22:41:28 +02:00
|
|
|
@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-10-30 18:29:00 +02:00
|
|
|
val rxBus = RxBus(aapsSchedulers, aapsLogger)
|
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() {
|
2021-11-10 13:58:31 +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-06-27 21:59:40 +02:00
|
|
|
dateUtil = Mockito.spy(DateUtil(context))
|
|
|
|
`when`(dateUtil.now()).thenReturn(1656358822000)
|
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)
|
|
|
|
)
|
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())
|
|
|
|
|
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)
|
2022-11-10 16:55:18 +01:00
|
|
|
return ProfileStoreObject(profileInjector, json, dateUtil)
|
2020-03-19 18:02:24 +01:00
|
|
|
}
|
2021-11-10 13:58:31 +01:00
|
|
|
}
|