From 863ad1d1ac453420f090629163256461abfba536 Mon Sep 17 00:00:00 2001 From: jbr7rr <> Date: Wed, 9 Aug 2023 09:34:57 +0200 Subject: [PATCH] DetailedBolusInfoStorage: Fix unit tests --- .../implementation/pump/DetailedBolusInfoStorageImpl.kt | 2 +- .../implementation/pump/DetailedBolusInfoStorageTest.kt | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/implementation/src/main/java/info/nightscout/implementation/pump/DetailedBolusInfoStorageImpl.kt b/implementation/src/main/java/info/nightscout/implementation/pump/DetailedBolusInfoStorageImpl.kt index 0ed35bd2cb..e42a9d76cb 100644 --- a/implementation/src/main/java/info/nightscout/implementation/pump/DetailedBolusInfoStorageImpl.kt +++ b/implementation/src/main/java/info/nightscout/implementation/pump/DetailedBolusInfoStorageImpl.kt @@ -83,7 +83,7 @@ class DetailedBolusInfoStorageImpl @Inject constructor( private fun loadStore(): ArrayList { val jsonString = sp.getString(rh.gs(R.string.bolus_storage), "") - return if (jsonString.isNotEmpty()) { + return if (jsonString != null && jsonString.isNotEmpty()) { val type = object : TypeToken>() {}.type Gson().fromJson(jsonString, type) } else { diff --git a/implementation/src/test/java/info/nightscout/implementation/pump/DetailedBolusInfoStorageTest.kt b/implementation/src/test/java/info/nightscout/implementation/pump/DetailedBolusInfoStorageTest.kt index 3831f62381..91d38733d8 100644 --- a/implementation/src/test/java/info/nightscout/implementation/pump/DetailedBolusInfoStorageTest.kt +++ b/implementation/src/test/java/info/nightscout/implementation/pump/DetailedBolusInfoStorageTest.kt @@ -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() {