Rewrites DetailedBolusInfoStorageTest with matchers

Issue #2745
This commit is contained in:
Ryan Haining 2023-09-19 22:35:36 -07:00
parent 822dc0361b
commit fea4d39ca7

View file

@ -1,11 +1,11 @@
package info.nightscout.implementation.pump package info.nightscout.implementation.pump
import com.google.common.truth.Truth.assertThat
import info.nightscout.implementation.R import info.nightscout.implementation.R
import info.nightscout.interfaces.pump.DetailedBolusInfo import info.nightscout.interfaces.pump.DetailedBolusInfo
import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
import info.nightscout.sharedtests.TestBase import info.nightscout.sharedtests.TestBase
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.mockito.Mock import org.mockito.Mock
@ -47,9 +47,9 @@ class DetailedBolusInfoStorageTest : TestBase() {
@Test @Test
fun add() { fun add() {
detailedBolusInfoStorage.store.clear() detailedBolusInfoStorage.store.clear()
Assertions.assertEquals(0, detailedBolusInfoStorage.store.size) assertThat(detailedBolusInfoStorage.store).isEmpty()
detailedBolusInfoStorage.add(info1) detailedBolusInfoStorage.add(info1)
Assertions.assertEquals(1, detailedBolusInfoStorage.store.size) assertThat(detailedBolusInfoStorage.store).hasSize(1)
} }
@Test @Test
@ -58,38 +58,38 @@ class DetailedBolusInfoStorageTest : TestBase() {
// Look for exact bolus // Look for exact bolus
setUp() setUp()
var d: DetailedBolusInfo? = detailedBolusInfoStorage.findDetailedBolusInfo(1000000, 4.0) var d: DetailedBolusInfo? = detailedBolusInfoStorage.findDetailedBolusInfo(1000000, 4.0)
Assertions.assertEquals(4.0, d!!.insulin, 0.01) assertThat(d!!.insulin).isWithin(0.01).of(4.0)
Assertions.assertEquals(2, detailedBolusInfoStorage.store.size) assertThat(detailedBolusInfoStorage.store).hasSize(2)
// Look for exact bolus // Look for exact bolus
setUp() setUp()
d = detailedBolusInfoStorage.findDetailedBolusInfo(1000000, 3.0) d = detailedBolusInfoStorage.findDetailedBolusInfo(1000000, 3.0)
Assertions.assertEquals(3.0, d!!.insulin, 0.01) assertThat(d!!.insulin).isWithin(0.01).of(3.0)
Assertions.assertEquals(2, detailedBolusInfoStorage.store.size) assertThat(detailedBolusInfoStorage.store).hasSize(2)
// With less insulin (bolus not delivered completely). Should return first one matching date // With less insulin (bolus not delivered completely). Should return first one matching date
setUp() setUp()
d = detailedBolusInfoStorage.findDetailedBolusInfo(1000500, 2.0) d = detailedBolusInfoStorage.findDetailedBolusInfo(1000500, 2.0)
Assertions.assertEquals(3.0, d!!.insulin, 0.01) assertThat(d!!.insulin).isWithin(0.01).of(3.0)
Assertions.assertEquals(2, detailedBolusInfoStorage.store.size) assertThat(detailedBolusInfoStorage.store).hasSize(2)
// With less insulin (bolus not delivered completely). Should return first one matching date // With less insulin (bolus not delivered completely). Should return first one matching date
setUp() setUp()
d = detailedBolusInfoStorage.findDetailedBolusInfo(1000500, 3.5) d = detailedBolusInfoStorage.findDetailedBolusInfo(1000500, 3.5)
Assertions.assertEquals(4.0, d!!.insulin, 0.01) assertThat(d!!.insulin).isWithin(0.01).of(4.0)
Assertions.assertEquals(2, detailedBolusInfoStorage.store.size) assertThat(detailedBolusInfoStorage.store).hasSize(2)
// With more insulin should return null // With more insulin should return null
setUp() setUp()
d = detailedBolusInfoStorage.findDetailedBolusInfo(1000500, 4.5) d = detailedBolusInfoStorage.findDetailedBolusInfo(1000500, 4.5)
Assertions.assertNull(d) assertThat(d).isNull()
Assertions.assertEquals(3, detailedBolusInfoStorage.store.size) assertThat(detailedBolusInfoStorage.store).hasSize(3)
// With more than one minute off should return null // With more than one minute off should return null
setUp() setUp()
d = detailedBolusInfoStorage.findDetailedBolusInfo(1070000, 4.0) d = detailedBolusInfoStorage.findDetailedBolusInfo(1070000, 4.0)
Assertions.assertNull(d) assertThat(d).isNull()
Assertions.assertEquals(3, detailedBolusInfoStorage.store.size) assertThat(detailedBolusInfoStorage.store).hasSize(3)
// Use last, if bolus size is the same // Use last, if bolus size is the same
// setUp() // setUp()
// d = detailedBolusInfoStorage.findDetailedBolusInfo(1070000, 5.0) // d = detailedBolusInfoStorage.findDetailedBolusInfo(1070000, 5.0)
// assertEquals(5.0, d!!.insulin, 0.01) // assertThat( d!!.insulin).isWithin(0.01).of(5.0)
// assertEquals(2, detailedBolusInfoStorage.store.size) // assertThat(detailedBolusInfoStorage.store).hasSize(2)
} }
} }