From 7a0635b6a8cac5249abe491e6ff17b3162ff658f Mon Sep 17 00:00:00 2001 From: Ryan Haining Date: Tue, 19 Sep 2023 22:39:36 -0700 Subject: [PATCH] Rewrites TemporaryBasalStorageTest with matchers Issue #2745 --- .../pump/TemporaryBasalStorageTest.kt | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/implementation/src/test/java/info/nightscout/implementation/pump/TemporaryBasalStorageTest.kt b/implementation/src/test/java/info/nightscout/implementation/pump/TemporaryBasalStorageTest.kt index 14465bf0f4..881bd46aa9 100644 --- a/implementation/src/test/java/info/nightscout/implementation/pump/TemporaryBasalStorageTest.kt +++ b/implementation/src/test/java/info/nightscout/implementation/pump/TemporaryBasalStorageTest.kt @@ -1,8 +1,8 @@ package info.nightscout.implementation.pump +import com.google.common.truth.Truth.assertThat import info.nightscout.interfaces.pump.PumpSync import info.nightscout.sharedtests.TestBase -import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test @@ -29,9 +29,9 @@ class TemporaryBasalStorageTest : TestBase() { @Test fun add() { temporaryBasalStorage.store.clear() - Assertions.assertEquals(0, temporaryBasalStorage.store.size) + assertThat(temporaryBasalStorage.store).isEmpty() temporaryBasalStorage.add(info1) - Assertions.assertEquals(1, temporaryBasalStorage.store.size) + assertThat(temporaryBasalStorage.store).hasSize(1) } @Test @@ -40,38 +40,38 @@ class TemporaryBasalStorageTest : TestBase() { // Look for exact bolus setUp() var d = temporaryBasalStorage.findTemporaryBasal(1000000, 4.0) - Assertions.assertEquals(4.0, d!!.rate, 0.01) - Assertions.assertEquals(2, temporaryBasalStorage.store.size) + assertThat(d!!.rate).isWithin(0.01).of(4.0) + assertThat(temporaryBasalStorage.store).hasSize(2) // Look for exact bolus setUp() d = temporaryBasalStorage.findTemporaryBasal(1000000, 3.0) - Assertions.assertEquals(3.0, d!!.rate, 0.01) - Assertions.assertEquals(2, temporaryBasalStorage.store.size) + assertThat(d!!.rate).isWithin(0.01).of(3.0) + assertThat(temporaryBasalStorage.store).hasSize(2) // With less rate (bolus not delivered completely). Should return first one matching date setUp() d = temporaryBasalStorage.findTemporaryBasal(1000500, 2.0) - Assertions.assertEquals(3.0, d!!.rate, 0.01) - Assertions.assertEquals(2, temporaryBasalStorage.store.size) + assertThat(d!!.rate).isWithin(0.01).of(3.0) + assertThat(temporaryBasalStorage.store).hasSize(2) // With less rate (bolus not delivered completely). Should return first one matching date setUp() d = temporaryBasalStorage.findTemporaryBasal(1000500, 3.5) - Assertions.assertEquals(4.0, d!!.rate, 0.01) - Assertions.assertEquals(2, temporaryBasalStorage.store.size) + assertThat(d!!.rate).isWithin(0.01).of(4.0) + assertThat(temporaryBasalStorage.store).hasSize(2) // With more rate should return null setUp() d = temporaryBasalStorage.findTemporaryBasal(1000500, 4.5) - Assertions.assertNull(d) - Assertions.assertEquals(3, temporaryBasalStorage.store.size) + assertThat(d).isNull() + assertThat(temporaryBasalStorage.store).hasSize(3) // With more than one minute off should return null setUp() d = temporaryBasalStorage.findTemporaryBasal(1070000, 4.0) - Assertions.assertNull(d) - Assertions.assertEquals(3, temporaryBasalStorage.store.size) + assertThat(d).isNull() + assertThat(temporaryBasalStorage.store).hasSize(3) // Use last, if bolus size is the same setUp() d = temporaryBasalStorage.findTemporaryBasal(1070000, 5.0) - Assertions.assertEquals(5.0, d!!.rate, 0.01) - Assertions.assertEquals(2, temporaryBasalStorage.store.size) + assertThat(d!!.rate).isWithin(0.01).of(5.0) + assertThat(temporaryBasalStorage.store).hasSize(2) } -} \ No newline at end of file +}