From ff63b72707b0abc6d313455efb51502ccfae26e1 Mon Sep 17 00:00:00 2001 From: Ryan Haining Date: Tue, 19 Sep 2023 22:18:33 -0700 Subject: [PATCH 1/9] Rewrites GlucoseStatusTest with matchers Issue #2745 --- .../implementation/iob/GlucoseStatusTest.kt | 128 +++++++++--------- 1 file changed, 64 insertions(+), 64 deletions(-) diff --git a/implementation/src/test/java/info/nightscout/implementation/iob/GlucoseStatusTest.kt b/implementation/src/test/java/info/nightscout/implementation/iob/GlucoseStatusTest.kt index fb98cd1aaa..8d96814e6e 100644 --- a/implementation/src/test/java/info/nightscout/implementation/iob/GlucoseStatusTest.kt +++ b/implementation/src/test/java/info/nightscout/implementation/iob/GlucoseStatusTest.kt @@ -1,5 +1,6 @@ package info.nightscout.implementation.iob +import com.google.common.truth.Truth.assertThat import info.nightscout.core.iob.asRounded import info.nightscout.core.iob.log import info.nightscout.database.entities.GlucoseValue @@ -9,7 +10,6 @@ import info.nightscout.interfaces.iob.InMemoryGlucoseValue import info.nightscout.interfaces.iob.IobCobCalculator import info.nightscout.shared.utils.T import info.nightscout.sharedtests.TestBaseWithProfile -import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.mockito.Mock @@ -30,106 +30,106 @@ class GlucoseStatusTest : TestBaseWithProfile() { @Test fun toStringShouldBeOverloaded() { val glucoseStatus = GlucoseStatus(glucose = 0.0, noise = 0.0, delta = 0.0, shortAvgDelta = 0.0, longAvgDelta = 0.0, date = 0) - Assertions.assertEquals(true, glucoseStatus.log(decimalFormatter).contains("Delta")) + assertThat(glucoseStatus.log(decimalFormatter)).contains("Delta") } @Test fun roundTest() { val glucoseStatus = GlucoseStatus(glucose = 100.11111, noise = 0.0, delta = 0.0, shortAvgDelta = 0.0, longAvgDelta = 0.0, date = 0) - Assertions.assertEquals(100.1, glucoseStatus.asRounded().glucose, 0.0001) + assertThat(glucoseStatus.asRounded().glucose).isWithin(0.0001).of(100.1) } @Test fun calculateValidGlucoseStatus() { Mockito.`when`(autosensDataStore.getBucketedDataTableCopy()).thenReturn(generateValidBgData()) val glucoseStatus = GlucoseStatusProviderImpl(aapsLogger, iobCobCalculatorPlugin, dateUtil, decimalFormatter).glucoseStatusData!! - Assertions.assertEquals(214.0, glucoseStatus.glucose, 0.001) - Assertions.assertEquals(-2.0, glucoseStatus.delta, 0.001) - Assertions.assertEquals(-2.5, glucoseStatus.shortAvgDelta, 0.001) // -2 -2.5 -3 deltas are relative to current value - Assertions.assertEquals(-2.0, glucoseStatus.longAvgDelta, 0.001) // -2 -2 -2 -2 - Assertions.assertEquals(1514766900000L, glucoseStatus.date) // latest date + assertThat(glucoseStatus.glucose).isWithin(0.001).of(214.0) + assertThat(glucoseStatus.delta).isWithin(0.001).of(-2.0) + assertThat(glucoseStatus.shortAvgDelta).isWithin(0.001).of(-2.5) // -2 -2.5 -3 deltas are relative to current value + assertThat(glucoseStatus.longAvgDelta).isWithin(0.001).of(-2.0) // -2 -2 -2 -2 + assertThat(glucoseStatus.date).isEqualTo(1514766900000L) // latest date } -/* - Not testing anymore, not valid for bucketed data + /* + Not testing anymore, not valid for bucketed data - @Test fun calculateMostRecentGlucoseStatus() { - Mockito.`when`(autosensDataStore.getBucketedDataTableCopy()).thenReturn(generateMostRecentBgData()) - val glucoseStatus: GlucoseStatus = GlucoseStatusProviderImpl(aapsLogger, iobCobCalculatorPlugin, dateUtil).glucoseStatusData!! - Assertions.assertEquals(215.0, glucoseStatus.glucose, 0.001) // (214+216) / 2 - Assertions.assertEquals(-1.0, glucoseStatus.delta, 0.001) - Assertions.assertEquals(-1.0, glucoseStatus.shortAvgDelta, 0.001) - Assertions.assertEquals(0.0, glucoseStatus.longAvgDelta, 0.001) - Assertions.assertEquals(1514766900000L, glucoseStatus.date) // latest date, even when averaging - } + @Test fun calculateMostRecentGlucoseStatus() { + Mockito.`when`(autosensDataStore.getBucketedDataTableCopy()).thenReturn(generateMostRecentBgData()) + val glucoseStatus: GlucoseStatus = GlucoseStatusProviderImpl(aapsLogger, iobCobCalculatorPlugin, dateUtil).glucoseStatusData!! + assertThat(glucoseStatus.glucose).isWithin(0.001).of(215.0) // (214+216) / 2 + assertThat(glucoseStatus.delta).isWithin(0.001).of(-1.0) + assertThat(glucoseStatus.shortAvgDelta).isWithin(0.001).of(-1.0) + assertThat( glucoseStatus.longAvgDelta).isWithin(0.001).of(0.0) + assertThat(glucoseStatus.date).isEqualTo(1514766900000L) // latest date, even when averaging + } - private fun generateMostRecentBgData(): MutableList { - val list: MutableList = ArrayList() - list.add(InMemoryGlucoseValue(value = 214.0, timestamp = 1514766900000, trendArrow = GlucoseValue.TrendArrow.FLAT)) - list.add(InMemoryGlucoseValue(value = 216.0, timestamp = 1514766800000, trendArrow = GlucoseValue.TrendArrow.FLAT)) - list.add(InMemoryGlucoseValue(value = 216.0, timestamp = 1514766600000, trendArrow = GlucoseValue.TrendArrow.FLAT)) - return list - } -*/ + private fun generateMostRecentBgData(): MutableList { + val list: MutableList = ArrayList() + list.add(InMemoryGlucoseValue(value = 214.0, timestamp = 1514766900000, trendArrow = GlucoseValue.TrendArrow.FLAT)) + list.add(InMemoryGlucoseValue(value = 216.0, timestamp = 1514766800000, trendArrow = GlucoseValue.TrendArrow.FLAT)) + list.add(InMemoryGlucoseValue(value = 216.0, timestamp = 1514766600000, trendArrow = GlucoseValue.TrendArrow.FLAT)) + return list + } + */ @Test fun oneRecordShouldProduceZeroDeltas() { Mockito.`when`(autosensDataStore.getBucketedDataTableCopy()).thenReturn(generateOneCurrentRecordBgData()) val glucoseStatus: GlucoseStatus = GlucoseStatusProviderImpl(aapsLogger, iobCobCalculatorPlugin, dateUtil, decimalFormatter).glucoseStatusData!! - Assertions.assertEquals(214.0, glucoseStatus.glucose, 0.001) - Assertions.assertEquals(0.0, glucoseStatus.delta, 0.001) - Assertions.assertEquals(0.0, glucoseStatus.shortAvgDelta, 0.001) // -2 -2.5 -3 deltas are relative to current value - Assertions.assertEquals(0.0, glucoseStatus.longAvgDelta, 0.001) // -2 -2 -2 -2 - Assertions.assertEquals(1514766900000L, glucoseStatus.date) // latest date + assertThat(glucoseStatus.glucose).isWithin(0.001).of(214.0) + assertThat(glucoseStatus.delta).isWithin(0.001).of(0.0) + assertThat(glucoseStatus.shortAvgDelta).isWithin(0.001).of(0.0) // -2 -2.5 -3 deltas are relative to current value + assertThat(glucoseStatus.longAvgDelta).isWithin(0.001).of(0.0) // -2 -2 -2 -2 + assertThat(glucoseStatus.date).isEqualTo(1514766900000L) // latest date } @Test fun insufficientDataShouldReturnNull() { Mockito.`when`(autosensDataStore.getBucketedDataTableCopy()).thenReturn(generateInsufficientBgData()) val glucoseStatus: GlucoseStatus? = GlucoseStatusProviderImpl(aapsLogger, iobCobCalculatorPlugin, dateUtil, decimalFormatter).glucoseStatusData - Assertions.assertEquals(null, glucoseStatus) + assertThat(glucoseStatus).isNull() } @Test fun oldDataShouldReturnNull() { Mockito.`when`(autosensDataStore.getBucketedDataTableCopy()).thenReturn(generateOldBgData()) val glucoseStatus: GlucoseStatus? = GlucoseStatusProviderImpl(aapsLogger, iobCobCalculatorPlugin, dateUtil, decimalFormatter).glucoseStatusData - Assertions.assertEquals(null, glucoseStatus) + assertThat(glucoseStatus).isNull() } @Test fun returnOldDataIfAllowed() { Mockito.`when`(autosensDataStore.getBucketedDataTableCopy()).thenReturn(generateOldBgData()) val glucoseStatus: GlucoseStatus? = GlucoseStatusProviderImpl(aapsLogger, iobCobCalculatorPlugin, dateUtil, decimalFormatter).getGlucoseStatusData(true) - Assertions.assertNotEquals(null, glucoseStatus) + assertThat(glucoseStatus).isNull() } @Test fun averageShouldNotFailOnEmptyArray() { - Assertions.assertEquals(0.0, GlucoseStatusProviderImpl.average(ArrayList()), 0.001) + assertThat(GlucoseStatusProviderImpl.average(ArrayList())).isWithin(0.001).of(0.0) } -/* - Not testing anymore, not valid for bucketed data + /* + Not testing anymore, not valid for bucketed data - @Test fun calculateGlucoseStatusForLibreTestBgData() { - Mockito.`when`(autosensDataStore.getBucketedDataTableCopy()).thenReturn(generateLibreTestData()) - val glucoseStatus: GlucoseStatus = GlucoseStatusProviderImpl(aapsLogger, iobCobCalculatorPlugin, dateUtil).glucoseStatusData!! - Assertions.assertEquals(100.0, glucoseStatus.glucose, 0.001) // - Assertions.assertEquals(-10.0, glucoseStatus.delta, 0.001) - Assertions.assertEquals(-10.0, glucoseStatus.shortAvgDelta, 0.001) - Assertions.assertEquals(-10.0, glucoseStatus.longAvgDelta, 0.001) - Assertions.assertEquals(1514766900000L, glucoseStatus.date) // latest date - } + @Test fun calculateGlucoseStatusForLibreTestBgData() { + Mockito.`when`(autosensDataStore.getBucketedDataTableCopy()).thenReturn(generateLibreTestData()) + val glucoseStatus: GlucoseStatus = GlucoseStatusProviderImpl(aapsLogger, iobCobCalculatorPlugin, dateUtil).glucoseStatusData!! + assertThat(glucoseStatus.glucose).isWithin(0.001).of(100.0) + assertThat(glucoseStatus.delta).isWithin(0.001).of(-10.0) + assertThat(glucoseStatus.shortAvgDelta).isWithin(0.001).of(-10.0) + assertThat(glucoseStatus.longAvgDelta).isWithin(0.001).of(-10.0) + assertThat(glucoseStatus.date).isEqualTo(1514766900000L) // latest date + } - private fun generateLibreTestData(): MutableList { - val list: MutableList = ArrayList() - val endTime = 1514766900000L - val latestReading = 100.0 - // Now - list.add(InMemoryGlucoseValue(value = latestReading, timestamp = endTime, trendArrow = GlucoseValue.TrendArrow.FLAT)) - // One minute ago - list.add(InMemoryGlucoseValue(value = latestReading, timestamp = endTime - 1000 * 60 * 1, trendArrow = GlucoseValue.TrendArrow.FLAT)) - // Two minutes ago - list.add(InMemoryGlucoseValue(value = latestReading, timestamp = endTime - 1000 * 60 * 2, trendArrow = GlucoseValue.TrendArrow.FLAT)) - // Three minutes and beyond at constant rate - for (i in 3..49) - list.add(InMemoryGlucoseValue(value = latestReading + i * 2, timestamp = endTime - 1000 * 60 * i, trendArrow = GlucoseValue.TrendArrow.FLAT)) - return list - } -*/ + private fun generateLibreTestData(): MutableList { + val list: MutableList = ArrayList() + val endTime = 1514766900000L + val latestReading = 100.0 + // Now + list.add(InMemoryGlucoseValue(value = latestReading, timestamp = endTime, trendArrow = GlucoseValue.TrendArrow.FLAT)) + // One minute ago + list.add(InMemoryGlucoseValue(value = latestReading, timestamp = endTime - 1000 * 60 * 1, trendArrow = GlucoseValue.TrendArrow.FLAT)) + // Two minutes ago + list.add(InMemoryGlucoseValue(value = latestReading, timestamp = endTime - 1000 * 60 * 2, trendArrow = GlucoseValue.TrendArrow.FLAT)) + // Three minutes and beyond at constant rate + for (i in 3..49) + list.add(InMemoryGlucoseValue(value = latestReading + i * 2, timestamp = endTime - 1000 * 60 * i, trendArrow = GlucoseValue.TrendArrow.FLAT)) + return list + } + */ @BeforeEach fun initMocking() { @@ -166,4 +166,4 @@ class GlucoseStatusTest : TestBaseWithProfile() { list.add(InMemoryGlucoseValue(value = 214.0, timestamp = 1514766900000, trendArrow = GlucoseValue.TrendArrow.FLAT, sourceSensor = GlucoseValue.SourceSensor.UNKNOWN)) return list } -} \ No newline at end of file +} From 7f1ba7e763b0d7663552ad8233b96f4c32a59388 Mon Sep 17 00:00:00 2001 From: Ryan Haining Date: Tue, 19 Sep 2023 22:22:52 -0700 Subject: [PATCH 2/9] Rewrites OverviewDataImplTest with matchers Issue #2745 --- .../overview/OverviewDataImplTest.kt | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/implementation/src/test/java/info/nightscout/implementation/overview/OverviewDataImplTest.kt b/implementation/src/test/java/info/nightscout/implementation/overview/OverviewDataImplTest.kt index d0f483f2c9..4fce738688 100644 --- a/implementation/src/test/java/info/nightscout/implementation/overview/OverviewDataImplTest.kt +++ b/implementation/src/test/java/info/nightscout/implementation/overview/OverviewDataImplTest.kt @@ -1,5 +1,6 @@ package info.nightscout.implementation.overview +import com.google.common.truth.Truth.assertThat import info.nightscout.database.ValueWrapper import info.nightscout.database.entities.GlucoseValue import info.nightscout.database.impl.AppRepository @@ -10,7 +11,6 @@ import info.nightscout.interfaces.profile.DefaultValueHelper import info.nightscout.shared.utils.T import info.nightscout.sharedtests.TestBaseWithProfile import io.reactivex.rxjava3.core.Single -import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.mockito.Mock @@ -43,23 +43,23 @@ class OverviewDataImplTest : TestBaseWithProfile() { // no data Mockito.`when`(autosensDataStore.bucketedData).thenReturn(null) Mockito.`when`(repository.getLastGlucoseValueWrapped()).thenReturn(Single.just(ValueWrapper.Absent())) - Assertions.assertNull(sut.lastBg(autosensDataStore)) - Assertions.assertFalse(sut.isLow(autosensDataStore)) - Assertions.assertFalse(sut.isHigh(autosensDataStore)) + assertThat(sut.lastBg(autosensDataStore)).isNull() + assertThat(sut.isLow(autosensDataStore)).isFalse() + assertThat(sut.isHigh(autosensDataStore)).isFalse() // no bucketed but in db Mockito.`when`(autosensDataStore.bucketedData).thenReturn(null) Mockito.`when`(repository.getLastGlucoseValueWrapped()).thenReturn(Single.just(ValueWrapper.Existing(glucoseValue))) - Assertions.assertEquals(200.0, sut.lastBg(autosensDataStore)?.value) - Assertions.assertFalse(sut.isLow(autosensDataStore)) - Assertions.assertTrue(sut.isHigh(autosensDataStore)) + assertThat(sut.lastBg(autosensDataStore)?.value).isEqualTo(200.0) + assertThat(sut.isLow(autosensDataStore)).isFalse() + assertThat(sut.isHigh(autosensDataStore)).isTrue() // in bucketed Mockito.`when`(autosensDataStore.bucketedData).thenReturn(bucketedData) Mockito.`when`(repository.getLastGlucoseValueWrapped()).thenReturn(Single.just(ValueWrapper.Existing(glucoseValue))) - Assertions.assertEquals(70.0, sut.lastBg(autosensDataStore)?.value) - Assertions.assertTrue(sut.isLow(autosensDataStore)) - Assertions.assertFalse(sut.isHigh(autosensDataStore)) + assertThat(sut.lastBg(autosensDataStore)?.value).isEqualTo(70.0) + assertThat(sut.isLow(autosensDataStore)).isTrue() + assertThat(sut.isHigh(autosensDataStore)).isFalse() } @Test @@ -68,13 +68,13 @@ class OverviewDataImplTest : TestBaseWithProfile() { Mockito.`when`(autosensDataStore.bucketedData).thenReturn(null) Mockito.`when`(repository.getLastGlucoseValueWrapped()).thenReturn(Single.just(ValueWrapper.Existing(glucoseValue))) Mockito.`when`(dateUtil.now()).thenReturn(time + T.mins(1).msecs()) - Assertions.assertTrue(sut.isActualBg(autosensDataStore)) + assertThat(sut.isActualBg(autosensDataStore)).isTrue() Mockito.`when`(dateUtil.now()).thenReturn(time + T.mins(9).msecs() + 1) - Assertions.assertFalse(sut.isActualBg(autosensDataStore)) + assertThat(sut.isActualBg(autosensDataStore)).isFalse() // no data Mockito.`when`(autosensDataStore.bucketedData).thenReturn(null) Mockito.`when`(repository.getLastGlucoseValueWrapped()).thenReturn(Single.just(ValueWrapper.Absent())) - Assertions.assertFalse(sut.isActualBg(autosensDataStore)) + assertThat(sut.isActualBg(autosensDataStore)).isFalse() } -} \ No newline at end of file +} From d90db860f00455e0939d01dc61af3197a7d461ef Mon Sep 17 00:00:00 2001 From: Ryan Haining Date: Tue, 19 Sep 2023 22:28:55 -0700 Subject: [PATCH 3/9] Rewrites ProfileStoreTest with matchers Issue #2745 --- .../profile/ProfileStoreTest.kt | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/implementation/src/test/java/info/nightscout/implementation/profile/ProfileStoreTest.kt b/implementation/src/test/java/info/nightscout/implementation/profile/ProfileStoreTest.kt index 0f7eee5b5f..0c142e8ba7 100644 --- a/implementation/src/test/java/info/nightscout/implementation/profile/ProfileStoreTest.kt +++ b/implementation/src/test/java/info/nightscout/implementation/profile/ProfileStoreTest.kt @@ -1,47 +1,47 @@ package info.nightscout.implementation.profile +import com.google.common.truth.Truth.assertThat import info.nightscout.interfaces.profile.PureProfile import info.nightscout.sharedtests.TestBaseWithProfile -import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Test internal class ProfileStoreTest : TestBaseWithProfile() { @Test fun getStartDateTest() { - Assertions.assertEquals(0, getValidProfileStore().getStartDate()) + assertThat(getValidProfileStore().getStartDate()).isEqualTo(0) } @Test fun getDefaultProfileTest() { - Assertions.assertTrue(getValidProfileStore().getDefaultProfile() is PureProfile) + assertThat(getValidProfileStore().getDefaultProfile()).isInstanceOf(PureProfile::class.java) } @Test fun getDefaultProfileJsonTest() { - Assertions.assertTrue(getValidProfileStore().getDefaultProfileJson()?.has("dia") ?: false) - Assertions.assertEquals(null, getInvalidProfileStore2().getDefaultProfileJson()) + assertThat(getValidProfileStore().getDefaultProfileJson()?.has("dia")).isTrue() + assertThat(getInvalidProfileStore2().getDefaultProfileJson()).isNull() } @Test fun getDefaultProfileNameTest() { - Assertions.assertEquals(TESTPROFILENAME, getValidProfileStore().getDefaultProfileName()) + assertThat(getValidProfileStore().getDefaultProfileName()).isEqualTo(TESTPROFILENAME) } @Test fun getProfileListTest() { - Assertions.assertEquals(1, getValidProfileStore().getProfileList().size) + assertThat(getValidProfileStore().getProfileList()).hasSize(1) } @Test fun getSpecificProfileTest() { - Assertions.assertTrue(getValidProfileStore().getSpecificProfile(TESTPROFILENAME) is PureProfile) + assertThat(getValidProfileStore().getSpecificProfile(TESTPROFILENAME)).isInstanceOf(PureProfile::class.java) } @Test fun allProfilesValidTest() { - Assertions.assertTrue(getValidProfileStore().allProfilesValid) - Assertions.assertFalse(getInvalidProfileStore1().allProfilesValid) - Assertions.assertFalse(getInvalidProfileStore2().allProfilesValid) + assertThat(getValidProfileStore().allProfilesValid).isTrue() + assertThat(getInvalidProfileStore1().allProfilesValid).isFalse() + assertThat(getInvalidProfileStore2().allProfilesValid).isFalse() } -} \ No newline at end of file +} From 822dc0361bc3c7c114763d97b3b0dfbc982c3145 Mon Sep 17 00:00:00 2001 From: Ryan Haining Date: Tue, 19 Sep 2023 22:31:21 -0700 Subject: [PATCH 4/9] Rewrites ProfileUtilImplTest with matchers Issue #2745 --- .../profile/ProfileUtilImplTest.kt | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/implementation/src/test/java/info/nightscout/implementation/profile/ProfileUtilImplTest.kt b/implementation/src/test/java/info/nightscout/implementation/profile/ProfileUtilImplTest.kt index b90f62884a..b9b02c1847 100644 --- a/implementation/src/test/java/info/nightscout/implementation/profile/ProfileUtilImplTest.kt +++ b/implementation/src/test/java/info/nightscout/implementation/profile/ProfileUtilImplTest.kt @@ -1,12 +1,12 @@ package info.nightscout.implementation.profile +import com.google.common.truth.Truth.assertThat import info.nightscout.database.entities.GlucoseValue import info.nightscout.implementation.utils.DecimalFormatterImpl import info.nightscout.interfaces.GlucoseUnit import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.sharedPreferences.SP import info.nightscout.sharedtests.TestBase -import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.mockito.Mock @@ -29,19 +29,19 @@ class ProfileUtilImplTest : TestBase() { @Test fun toUnitsString() { - Assertions.assertEquals("100", sut.fromMgdlToStringInUnits(glucoseValue.value, GlucoseUnit.MGDL)) - Assertions.assertEquals("5.6", sut.fromMgdlToStringInUnits(glucoseValue.value, GlucoseUnit.MMOL)) - Assertions.assertEquals(0.1, sut.convertToMgdl(0.1, GlucoseUnit.MGDL), 0.01) - Assertions.assertEquals(18.0, sut.convertToMgdl(1.0, GlucoseUnit.MMOL), 0.01) - Assertions.assertEquals(1.0, sut.convertToMmol(18.0, GlucoseUnit.MGDL), 0.01) - Assertions.assertEquals(18.0, sut.convertToMmol(18.0, GlucoseUnit.MMOL), 0.01) - Assertions.assertEquals(18.0, sut.fromMgdlToUnits(18.0, GlucoseUnit.MGDL), 0.01) - Assertions.assertEquals(1.0, sut.fromMgdlToUnits(18.0, GlucoseUnit.MMOL), 0.01) - Assertions.assertEquals(18.0, sut.fromMgdlToUnits(18.0, GlucoseUnit.MGDL), 0.01) - Assertions.assertEquals(1.0, sut.fromMgdlToUnits(18.0, GlucoseUnit.MMOL), 0.01) - Assertions.assertEquals("18", sut.fromMgdlToStringInUnits(18.0, GlucoseUnit.MGDL)) - Assertions.assertEquals("1.0", sut.fromMgdlToStringInUnits(18.0, GlucoseUnit.MMOL).replace(",", ".")) - Assertions.assertEquals("5 - 6", sut.toTargetRangeString(5.0, 6.0, GlucoseUnit.MGDL, GlucoseUnit.MGDL)) - Assertions.assertEquals("4", sut.toTargetRangeString(4.0, 4.0, GlucoseUnit.MGDL, GlucoseUnit.MGDL)) + assertThat(sut.fromMgdlToStringInUnits(glucoseValue.value, GlucoseUnit.MGDL)).isEqualTo("100") + assertThat(sut.fromMgdlToStringInUnits(glucoseValue.value, GlucoseUnit.MMOL)).isEqualTo("5.6") + assertThat(sut.convertToMgdl(0.1, GlucoseUnit.MGDL)).isWithin(0.01).of(0.1) + assertThat(sut.convertToMgdl(1.0, GlucoseUnit.MMOL)).isWithin(0.01).of(18.0) + assertThat(sut.convertToMmol(18.0, GlucoseUnit.MGDL)).isWithin(0.01).of(1.0) + assertThat(sut.convertToMmol(18.0, GlucoseUnit.MMOL)).isWithin(0.01).of(18.0) + assertThat(sut.fromMgdlToUnits(18.0, GlucoseUnit.MGDL)).isWithin(0.01).of(18.0) + assertThat(sut.fromMgdlToUnits(18.0, GlucoseUnit.MMOL)).isWithin(0.01).of(1.0) + assertThat(sut.fromMgdlToUnits(18.0, GlucoseUnit.MGDL)).isWithin(0.01).of(18.0) + assertThat(sut.fromMgdlToUnits(18.0, GlucoseUnit.MMOL)).isWithin(0.01).of(1.0) + assertThat(sut.fromMgdlToStringInUnits(18.0, GlucoseUnit.MGDL)).isEqualTo("18") + assertThat(sut.fromMgdlToStringInUnits(18.0, GlucoseUnit.MMOL).replace(",", ".")).isEqualTo("1.0") + assertThat(sut.toTargetRangeString(5.0, 6.0, GlucoseUnit.MGDL, GlucoseUnit.MGDL)).isEqualTo("5 - 6") + assertThat(sut.toTargetRangeString(4.0, 4.0, GlucoseUnit.MGDL, GlucoseUnit.MGDL)).isEqualTo("4") } -} \ No newline at end of file +} From fea4d39ca7e9ceaba319db7a0e120c0608f32408 Mon Sep 17 00:00:00 2001 From: Ryan Haining Date: Tue, 19 Sep 2023 22:35:36 -0700 Subject: [PATCH 5/9] Rewrites DetailedBolusInfoStorageTest with matchers Issue #2745 --- .../pump/DetailedBolusInfoStorageTest.kt | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) 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 5f1e23593b..3de4e26a24 100644 --- a/implementation/src/test/java/info/nightscout/implementation/pump/DetailedBolusInfoStorageTest.kt +++ b/implementation/src/test/java/info/nightscout/implementation/pump/DetailedBolusInfoStorageTest.kt @@ -1,11 +1,11 @@ package info.nightscout.implementation.pump +import com.google.common.truth.Truth.assertThat import info.nightscout.implementation.R import info.nightscout.interfaces.pump.DetailedBolusInfo import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.sharedPreferences.SP import info.nightscout.sharedtests.TestBase -import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.mockito.Mock @@ -47,9 +47,9 @@ class DetailedBolusInfoStorageTest : TestBase() { @Test fun add() { detailedBolusInfoStorage.store.clear() - Assertions.assertEquals(0, detailedBolusInfoStorage.store.size) + assertThat(detailedBolusInfoStorage.store).isEmpty() detailedBolusInfoStorage.add(info1) - Assertions.assertEquals(1, detailedBolusInfoStorage.store.size) + assertThat(detailedBolusInfoStorage.store).hasSize(1) } @Test @@ -58,38 +58,38 @@ class DetailedBolusInfoStorageTest : TestBase() { // Look for exact bolus setUp() var d: DetailedBolusInfo? = detailedBolusInfoStorage.findDetailedBolusInfo(1000000, 4.0) - Assertions.assertEquals(4.0, d!!.insulin, 0.01) - Assertions.assertEquals(2, detailedBolusInfoStorage.store.size) + assertThat(d!!.insulin).isWithin(0.01).of(4.0) + assertThat(detailedBolusInfoStorage.store).hasSize(2) // Look for exact bolus setUp() d = detailedBolusInfoStorage.findDetailedBolusInfo(1000000, 3.0) - Assertions.assertEquals(3.0, d!!.insulin, 0.01) - Assertions.assertEquals(2, detailedBolusInfoStorage.store.size) + assertThat(d!!.insulin).isWithin(0.01).of(3.0) + assertThat(detailedBolusInfoStorage.store).hasSize(2) // With less insulin (bolus not delivered completely). Should return first one matching date setUp() d = detailedBolusInfoStorage.findDetailedBolusInfo(1000500, 2.0) - Assertions.assertEquals(3.0, d!!.insulin, 0.01) - Assertions.assertEquals(2, detailedBolusInfoStorage.store.size) + assertThat(d!!.insulin).isWithin(0.01).of(3.0) + assertThat(detailedBolusInfoStorage.store).hasSize(2) // With less insulin (bolus not delivered completely). Should return first one matching date setUp() d = detailedBolusInfoStorage.findDetailedBolusInfo(1000500, 3.5) - Assertions.assertEquals(4.0, d!!.insulin, 0.01) - Assertions.assertEquals(2, detailedBolusInfoStorage.store.size) + assertThat(d!!.insulin).isWithin(0.01).of(4.0) + assertThat(detailedBolusInfoStorage.store).hasSize(2) // With more insulin should return null setUp() d = detailedBolusInfoStorage.findDetailedBolusInfo(1000500, 4.5) - Assertions.assertNull(d) - Assertions.assertEquals(3, detailedBolusInfoStorage.store.size) + assertThat(d).isNull() + assertThat(detailedBolusInfoStorage.store).hasSize(3) // With more than one minute off should return null setUp() d = detailedBolusInfoStorage.findDetailedBolusInfo(1070000, 4.0) - Assertions.assertNull(d) - Assertions.assertEquals(3, detailedBolusInfoStorage.store.size) + assertThat(d).isNull() + assertThat(detailedBolusInfoStorage.store).hasSize(3) // Use last, if bolus size is the same // setUp() // d = detailedBolusInfoStorage.findDetailedBolusInfo(1070000, 5.0) -// assertEquals(5.0, d!!.insulin, 0.01) -// assertEquals(2, detailedBolusInfoStorage.store.size) +// assertThat( d!!.insulin).isWithin(0.01).of(5.0) +// assertThat(detailedBolusInfoStorage.store).hasSize(2) } -} \ No newline at end of file +} From 7a0635b6a8cac5249abe491e6ff17b3162ff658f Mon Sep 17 00:00:00 2001 From: Ryan Haining Date: Tue, 19 Sep 2023 22:39:36 -0700 Subject: [PATCH 6/9] 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 +} From 8b3e39420e9ddc79d0e4aae6bfa4694d20d25e49 Mon Sep 17 00:00:00 2001 From: Ryan Haining Date: Tue, 19 Sep 2023 22:41:56 -0700 Subject: [PATCH 7/9] Rewrites DecimalFormatterTest with matchers Issue #2745 --- .../utils/DecimalFormatterTest.kt | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/implementation/src/test/java/info/nightscout/implementation/utils/DecimalFormatterTest.kt b/implementation/src/test/java/info/nightscout/implementation/utils/DecimalFormatterTest.kt index 9ab168ff5b..2b5938656c 100644 --- a/implementation/src/test/java/info/nightscout/implementation/utils/DecimalFormatterTest.kt +++ b/implementation/src/test/java/info/nightscout/implementation/utils/DecimalFormatterTest.kt @@ -1,9 +1,9 @@ package info.nightscout.implementation.utils +import com.google.common.truth.Truth.assertThat import info.nightscout.interfaces.utils.DecimalFormatter import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.sharedtests.TestBase -import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.mockito.Mock @@ -20,22 +20,22 @@ class DecimalFormatterTest : TestBase() { } @Test fun to0DecimalTest() { - Assertions.assertEquals("1", sut.to0Decimal(1.33).replace(",", ".")) - Assertions.assertEquals("1U", sut.to0Decimal(1.33, "U").replace(",", ".")) + assertThat(sut.to0Decimal(1.33).replace(",", ".")).isEqualTo("1") + assertThat(sut.to0Decimal(1.33, "U").replace(",", ".")).isEqualTo("1U") } @Test fun to1DecimalTest() { - Assertions.assertEquals("1.3", sut.to1Decimal(1.33).replace(",", ".")) - Assertions.assertEquals("1.3U", sut.to1Decimal(1.33, "U").replace(",", ".")) + assertThat(sut.to1Decimal(1.33).replace(",", ".")).isEqualTo("1.3") + assertThat(sut.to1Decimal(1.33, "U").replace(",", ".")).isEqualTo("1.3U") } @Test fun to2DecimalTest() { - Assertions.assertEquals("1.33", sut.to2Decimal(1.3333).replace(",", ".")) - Assertions.assertEquals("1.33U", sut.to2Decimal(1.3333, "U").replace(",", ".")) + assertThat(sut.to2Decimal(1.3333).replace(",", ".")).isEqualTo("1.33") + assertThat(sut.to2Decimal(1.3333, "U").replace(",", ".")).isEqualTo("1.33U") } @Test fun to3DecimalTest() { - Assertions.assertEquals("1.333", sut.to3Decimal(1.3333).replace(",", ".")) - Assertions.assertEquals("1.333U", sut.to3Decimal(1.3333, "U").replace(",", ".")) + assertThat(sut.to3Decimal(1.3333).replace(",", ".")).isEqualTo("1.333") + assertThat(sut.to3Decimal(1.3333, "U").replace(",", ".")).isEqualTo("1.333U") } -} \ No newline at end of file +} From 8c8b492ebae070c3a1c8d31eedb0def16cce6591 Mon Sep 17 00:00:00 2001 From: Ryan Haining Date: Tue, 19 Sep 2023 23:05:38 -0700 Subject: [PATCH 8/9] Rewrites CommandQueueImplementationTest with matchers Issue #2745 --- .../queue/CommandQueueImplementationTest.kt | 204 +++++++++--------- 1 file changed, 102 insertions(+), 102 deletions(-) diff --git a/implementation/src/test/java/info/nightscout/implementation/queue/CommandQueueImplementationTest.kt b/implementation/src/test/java/info/nightscout/implementation/queue/CommandQueueImplementationTest.kt index f77ea1b704..1d5f831bfe 100644 --- a/implementation/src/test/java/info/nightscout/implementation/queue/CommandQueueImplementationTest.kt +++ b/implementation/src/test/java/info/nightscout/implementation/queue/CommandQueueImplementationTest.kt @@ -1,5 +1,6 @@ package info.nightscout.implementation.queue +import com.google.common.truth.Truth.assertThat import android.content.Context import android.os.Handler import android.os.PowerManager @@ -38,7 +39,6 @@ import info.nightscout.shared.utils.DateUtil import info.nightscout.sharedtests.TestBaseWithProfile import info.nightscout.sharedtests.TestPumpPlugin import io.reactivex.rxjava3.core.Single -import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.mockito.Mock @@ -169,121 +169,121 @@ class CommandQueueImplementationTest : TestBaseWithProfile() { commandQueue.handler = handler // start with empty queue - Assertions.assertEquals(0, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(0) // add bolus command commandQueue.bolus(DetailedBolusInfo(), null) - Assertions.assertEquals(1, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(1) commandQueue.waitForFinishedThread() Thread.sleep(1000) - Assertions.assertEquals(0, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(0) } @Test fun doTests() { // start with empty queue - Assertions.assertEquals(0, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(0) // add bolus command commandQueue.bolus(DetailedBolusInfo(), null) - Assertions.assertEquals(1, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(1) // add READSTATUS commandQueue.readStatus("anyString", null) - Assertions.assertEquals(2, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(2) // adding another bolus should remove the first one (size still == 2) commandQueue.bolus(DetailedBolusInfo(), null) - Assertions.assertEquals(2, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(2) // clear the queue should reset size commandQueue.clear() - Assertions.assertEquals(0, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(0) // add tempbasal commandQueue.tempBasalAbsolute(0.0, 30, true, validProfile, PumpSync.TemporaryBasalType.NORMAL, null) - Assertions.assertEquals(1, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(1) // add tempbasal percent. it should replace previous TEMPBASAL commandQueue.tempBasalPercent(0, 30, true, validProfile, PumpSync.TemporaryBasalType.NORMAL, null) - Assertions.assertEquals(1, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(1) // cancel tempbasal it should replace previous TEMPBASAL commandQueue.cancelTempBasal(false, null) - Assertions.assertEquals(1, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(1) // add extended bolus commandQueue.extendedBolus(1.0, 30, null) - Assertions.assertEquals(2, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(2) // add extended should remove previous extended setting commandQueue.extendedBolus(1.0, 30, null) - Assertions.assertEquals(2, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(2) // cancel extended bolus should replace previous extended commandQueue.cancelExtended(null) - Assertions.assertEquals(2, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(2) // add setProfile // TODO: this crash the test // commandQueue.setProfile(validProfile, null) - // Assertions.assertEquals(3, commandQueue.size()) + // assertThat(commandQueue.size()).isEqualTo(3) // add loadHistory commandQueue.loadHistory(0.toByte(), null) - Assertions.assertEquals(3, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(3) // add loadEvents commandQueue.loadEvents(null) - Assertions.assertEquals(4, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(4) // add clearAlarms commandQueue.clearAlarms(null) - Assertions.assertEquals(5, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(5) // add deactivate commandQueue.deactivate(null) - Assertions.assertEquals(6, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(6) // add updateTime commandQueue.updateTime(null) - Assertions.assertEquals(7, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(7) commandQueue.clear() commandQueue.tempBasalAbsolute(0.0, 30, true, validProfile, PumpSync.TemporaryBasalType.NORMAL, null) commandQueue.pickup() - Assertions.assertEquals(0, commandQueue.size()) - Assertions.assertNotNull(commandQueue.performing) - Assertions.assertEquals(Command.CommandType.TEMPBASAL, commandQueue.performing?.commandType) + assertThat(commandQueue.size()).isEqualTo(0) + assertThat(commandQueue.performing).isNotNull() + assertThat(commandQueue.performing?.commandType).isEqualTo(Command.CommandType.TEMPBASAL) commandQueue.resetPerforming() - Assertions.assertNull(commandQueue.performing) + assertThat(commandQueue.performing).isNull() } @Test fun callingCancelAllBolusesClearsQueue() { // given - Assertions.assertEquals(0, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(0) val smb = DetailedBolusInfo() smb.lastKnownBolusTime = System.currentTimeMillis() smb.bolusType = DetailedBolusInfo.BolusType.SMB commandQueue.bolus(smb, null) commandQueue.bolus(DetailedBolusInfo(), null) - Assertions.assertEquals(2, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(2) // when commandQueue.cancelAllBoluses(null) // then - Assertions.assertEquals(0, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(0) } @Test fun smbIsRejectedIfABolusIsQueued() { // given - Assertions.assertEquals(0, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(0) // when commandQueue.bolus(DetailedBolusInfo(), null) @@ -292,14 +292,14 @@ class CommandQueueImplementationTest : TestBaseWithProfile() { val queued: Boolean = commandQueue.bolus(smb, null) // then - Assertions.assertFalse(queued) - Assertions.assertEquals(commandQueue.size(), 1) + assertThat(queued).isFalse() + assertThat(commandQueue.size()).isEqualTo(1) } @Test fun smbIsRejectedIfLastKnownBolusIsOutdated() { // given - Assertions.assertEquals(0, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(0) // when val bolus = DetailedBolusInfo() @@ -308,14 +308,14 @@ class CommandQueueImplementationTest : TestBaseWithProfile() { val queued: Boolean = commandQueue.bolus(bolus, null) // then - Assertions.assertFalse(queued) - Assertions.assertEquals(commandQueue.size(), 0) + assertThat(queued).isFalse() + assertThat(commandQueue.size()).isEqualTo(0) } @Test fun isCustomCommandRunning() { // given - Assertions.assertEquals(0, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(0) // when val queued1 = commandQueue.customCommand(CustomCommand1(), null) @@ -323,249 +323,249 @@ class CommandQueueImplementationTest : TestBaseWithProfile() { commandQueue.pickup() // then - Assertions.assertTrue(queued1) - Assertions.assertTrue(queued2) - Assertions.assertTrue(commandQueue.isCustomCommandInQueue(CustomCommand1::class.java)) - Assertions.assertTrue(commandQueue.isCustomCommandInQueue(CustomCommand2::class.java)) - Assertions.assertFalse(commandQueue.isCustomCommandInQueue(CustomCommand3::class.java)) + assertThat(queued1).isTrue() + assertThat(queued2).isTrue() + assertThat(commandQueue.isCustomCommandInQueue(CustomCommand1::class.java)).isTrue() + assertThat(commandQueue.isCustomCommandInQueue(CustomCommand2::class.java)).isTrue() + assertThat(commandQueue.isCustomCommandInQueue(CustomCommand3::class.java)).isFalse() - Assertions.assertTrue(commandQueue.isCustomCommandRunning(CustomCommand1::class.java)) - Assertions.assertFalse(commandQueue.isCustomCommandRunning(CustomCommand2::class.java)) - Assertions.assertFalse(commandQueue.isCustomCommandRunning(CustomCommand3::class.java)) + assertThat(commandQueue.isCustomCommandRunning(CustomCommand1::class.java)).isTrue() + assertThat(commandQueue.isCustomCommandRunning(CustomCommand2::class.java)).isFalse() + assertThat(commandQueue.isCustomCommandRunning(CustomCommand3::class.java)).isFalse() - Assertions.assertEquals(1, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(1) } @Test fun isSetUserOptionsCommandInQueue() { // given - Assertions.assertEquals(0, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(0) // when commandQueue.setUserOptions(null) // then - Assertions.assertTrue(commandQueue.isLastScheduled(Command.CommandType.SET_USER_SETTINGS)) - Assertions.assertEquals(1, commandQueue.size()) + assertThat(commandQueue.isLastScheduled(Command.CommandType.SET_USER_SETTINGS)).isTrue() + assertThat(commandQueue.size()).isEqualTo(1) // next should be ignored commandQueue.setUserOptions(null) - Assertions.assertEquals(1, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(1) } @Test fun isLoadEventsCommandInQueue() { // given - Assertions.assertEquals(0, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(0) // when commandQueue.loadEvents(null) // then - Assertions.assertTrue(commandQueue.isLastScheduled(Command.CommandType.LOAD_EVENTS)) - Assertions.assertEquals(1, commandQueue.size()) + assertThat(commandQueue.isLastScheduled(Command.CommandType.LOAD_EVENTS)).isTrue() + assertThat(commandQueue.size()).isEqualTo(1) // next should be ignored commandQueue.loadEvents(null) - Assertions.assertEquals(1, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(1) } @Test fun isClearAlarmsCommandInQueue() { // given - Assertions.assertEquals(0, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(0) // when commandQueue.clearAlarms(null) // then - Assertions.assertTrue(commandQueue.isLastScheduled(Command.CommandType.CLEAR_ALARMS)) - Assertions.assertEquals(1, commandQueue.size()) + assertThat(commandQueue.isLastScheduled(Command.CommandType.CLEAR_ALARMS)).isTrue() + assertThat(commandQueue.size()).isEqualTo(1) // next should be ignored commandQueue.clearAlarms(null) - Assertions.assertEquals(1, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(1) } @Test fun isDeactivateCommandInQueue() { // given - Assertions.assertEquals(0, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(0) // when commandQueue.deactivate(null) // then - Assertions.assertTrue(commandQueue.isLastScheduled(Command.CommandType.DEACTIVATE)) - Assertions.assertEquals(1, commandQueue.size()) + assertThat(commandQueue.isLastScheduled(Command.CommandType.DEACTIVATE)).isTrue() + assertThat(commandQueue.size()).isEqualTo(1) // next should be ignored commandQueue.deactivate(null) - Assertions.assertEquals(1, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(1) } @Test fun isUpdateTimeCommandInQueue() { // given - Assertions.assertEquals(0, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(0) // when commandQueue.updateTime(null) // then - Assertions.assertTrue(commandQueue.isLastScheduled(Command.CommandType.UPDATE_TIME)) - Assertions.assertEquals(1, commandQueue.size()) + assertThat(commandQueue.isLastScheduled(Command.CommandType.UPDATE_TIME)).isTrue() + assertThat(commandQueue.size()).isEqualTo(1) // next should be ignored commandQueue.updateTime(null) - Assertions.assertEquals(1, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(1) } @Test fun isLoadTDDsCommandInQueue() { // given - Assertions.assertEquals(0, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(0) // when commandQueue.loadTDDs(null) // then - Assertions.assertEquals(1, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(1) // next should be ignored commandQueue.loadTDDs(null) - Assertions.assertEquals(1, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(1) } @Test fun isLoadHistoryCommandInQueue() { // given - Assertions.assertEquals(0, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(0) // when commandQueue.loadHistory(0, null) // then - Assertions.assertTrue(commandQueue.isLastScheduled(Command.CommandType.LOAD_HISTORY)) - Assertions.assertEquals(1, commandQueue.size()) + assertThat(commandQueue.isLastScheduled(Command.CommandType.LOAD_HISTORY)).isTrue() + assertThat(commandQueue.size()).isEqualTo(1) // next should be ignored commandQueue.loadHistory(0, null) - Assertions.assertEquals(1, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(1) } @Test fun isProfileSetCommandInQueue() { // given - Assertions.assertEquals(0, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(0) // when testPumpPlugin.isProfileSet = true commandQueue.setProfile(validProfile, false, object : Callback() { override fun run() { - Assertions.assertTrue(result.success) - Assertions.assertFalse(result.enacted) + assertThat(result.success).isTrue() + assertThat(result.enacted).isFalse() } }) // then // the same profile -> ignore - Assertions.assertEquals(0, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(0) // different should be added testPumpPlugin.isProfileSet = false commandQueue.setProfile(validProfile, false, object : Callback() { override fun run() { - Assertions.assertTrue(result.success) - Assertions.assertTrue(result.enacted) + assertThat(result.success).isTrue() + assertThat(result.enacted).isTrue() } }) - Assertions.assertEquals(1, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(1) // next should be ignored commandQueue.setProfile(validProfile, false, object : Callback() { override fun run() { - Assertions.assertTrue(result.success) + assertThat(result.success).isTrue() } }) - Assertions.assertEquals(1, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(1) testPumpPlugin.isProfileSet = true } @Test fun isStopCommandInQueue() { // given - Assertions.assertEquals(0, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(0) // when commandQueue.stopPump(null) // then - Assertions.assertTrue(commandQueue.isLastScheduled(Command.CommandType.STOP_PUMP)) - Assertions.assertEquals(1, commandQueue.size()) + assertThat(commandQueue.isLastScheduled(Command.CommandType.STOP_PUMP)).isTrue() + assertThat(commandQueue.size()).isEqualTo(1) } @Test fun isStarCommandInQueue() { // given - Assertions.assertEquals(0, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(0) // when commandQueue.startPump(null) // then - Assertions.assertTrue(commandQueue.isLastScheduled(Command.CommandType.START_PUMP)) - Assertions.assertEquals(1, commandQueue.size()) + assertThat(commandQueue.isLastScheduled(Command.CommandType.START_PUMP)).isTrue() + assertThat(commandQueue.size()).isEqualTo(1) } @Test fun isSetTbrNotificationCommandInQueue() { // given - Assertions.assertEquals(0, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(0) // when commandQueue.setTBROverNotification(null, true) // then - Assertions.assertTrue(commandQueue.isLastScheduled(Command.CommandType.INSIGHT_SET_TBR_OVER_ALARM)) - Assertions.assertEquals(1, commandQueue.size()) + assertThat(commandQueue.isLastScheduled(Command.CommandType.INSIGHT_SET_TBR_OVER_ALARM)).isTrue() + assertThat(commandQueue.size()).isEqualTo(1) } @Test fun differentCustomCommandsAllowed() { // given - Assertions.assertEquals(0, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(0) // when val queued1 = commandQueue.customCommand(CustomCommand1(), null) val queued2 = commandQueue.customCommand(CustomCommand2(), null) // then - Assertions.assertTrue(queued1) - Assertions.assertTrue(queued2) - Assertions.assertEquals(2, commandQueue.size()) + assertThat(queued1).isTrue() + assertThat(queued2).isTrue() + assertThat(commandQueue.size()).isEqualTo(2) } @Test fun sameCustomCommandNotAllowed() { // given - Assertions.assertEquals(0, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(0) // when val queued1 = commandQueue.customCommand(CustomCommand1(), null) val queued2 = commandQueue.customCommand(CustomCommand1(), null) // then - Assertions.assertTrue(queued1) - Assertions.assertFalse(queued2) - Assertions.assertEquals(1, commandQueue.size()) + assertThat(queued1).isTrue() + assertThat(queued2).isFalse() + assertThat(commandQueue.size()).isEqualTo(1) } @Test fun readStatusTwiceIsNotAllowed() { // given - Assertions.assertEquals(0, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(0) // when val queued1 = commandQueue.readStatus("1", null) val queued2 = commandQueue.readStatus("2", null) // then - Assertions.assertTrue(queued1) - Assertions.assertFalse(queued2) - Assertions.assertEquals(1, commandQueue.size()) - Assertions.assertTrue(commandQueue.statusInQueue()) + assertThat(queued1).isTrue() + assertThat(queued2).isFalse() + assertThat(commandQueue.size()).isEqualTo(1) + assertThat(commandQueue.statusInQueue()).isTrue() } private class CustomCommand1 : CustomCommand { From 61c41b42fa105fbef450030a9494997c6ae03ff5 Mon Sep 17 00:00:00 2001 From: Ryan Haining Date: Tue, 19 Sep 2023 23:07:57 -0700 Subject: [PATCH 9/9] Rewrites QueueThreadTest with matchers Issue #2745 --- .../info/nightscout/implementation/queue/QueueThreadTest.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/implementation/src/test/java/info/nightscout/implementation/queue/QueueThreadTest.kt b/implementation/src/test/java/info/nightscout/implementation/queue/QueueThreadTest.kt index f8e3494ac5..d0d131d27f 100644 --- a/implementation/src/test/java/info/nightscout/implementation/queue/QueueThreadTest.kt +++ b/implementation/src/test/java/info/nightscout/implementation/queue/QueueThreadTest.kt @@ -1,5 +1,6 @@ package info.nightscout.implementation.queue +import com.google.common.truth.Truth.assertThat import android.content.Context import android.os.PowerManager import dagger.android.AndroidInjector @@ -16,7 +17,6 @@ import info.nightscout.interfaces.queue.Command import info.nightscout.interfaces.ui.UiInteraction import info.nightscout.sharedtests.TestBaseWithProfile import info.nightscout.sharedtests.TestPumpPlugin -import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.mockito.ArgumentMatchers @@ -84,6 +84,6 @@ class QueueThreadTest : TestBaseWithProfile() { commandQueue.tempBasalAbsolute(2.0, 60, true, validProfile, PumpSync.TemporaryBasalType.NORMAL, null) @Suppress("CallToThreadRun") sut.run() - Assertions.assertEquals(0, commandQueue.size()) + assertThat(commandQueue.size()).isEqualTo(0) } -} \ No newline at end of file +}