DetailedBolusInfoStorage: Fix unit tests

This commit is contained in:
jbr7rr 2023-08-09 09:34:57 +02:00
parent 65e9c2b9e8
commit 863ad1d1ac
2 changed files with 8 additions and 2 deletions

View file

@ -83,7 +83,7 @@ class DetailedBolusInfoStorageImpl @Inject constructor(
private fun loadStore(): ArrayList<DetailedBolusInfo> {
val jsonString = sp.getString(rh.gs(R.string.bolus_storage), "")
return if (jsonString.isNotEmpty()) {
return if (jsonString != null && jsonString.isNotEmpty()) {
val type = object : TypeToken<List<DetailedBolusInfo>>() {}.type
Gson().fromJson(jsonString, type)
} else {

View file

@ -2,13 +2,19 @@ package info.nightscout.implementation.pump
import info.nightscout.androidaps.TestBase
import info.nightscout.interfaces.pump.DetailedBolusInfo
import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.sharedPreferences.SP
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.Mock
class DetailedBolusInfoStorageTest : TestBase() {
@Mock lateinit var sp: SP
@Mock lateinit var rh: ResourceHelper
private val info1 = DetailedBolusInfo()
private val info2 = DetailedBolusInfo()
private val info3 = DetailedBolusInfo()
@ -26,7 +32,7 @@ class DetailedBolusInfoStorageTest : TestBase() {
@BeforeEach
fun prepare() {
detailedBolusInfoStorage = DetailedBolusInfoStorageImpl(aapsLogger)
detailedBolusInfoStorage = DetailedBolusInfoStorageImpl(aapsLogger, sp, rh)
}
private fun setUp() {