Merge pull request #2807 from ryanhaining/assertthat_implementation

Rewrites implementation/ tests with matchers
This commit is contained in:
Milos Kozak 2023-09-20 13:25:20 +02:00 committed by GitHub
commit a1517462ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 257 additions and 257 deletions

View file

@ -1,5 +1,6 @@
package info.nightscout.implementation.iob package info.nightscout.implementation.iob
import com.google.common.truth.Truth.assertThat
import info.nightscout.core.iob.asRounded import info.nightscout.core.iob.asRounded
import info.nightscout.core.iob.log import info.nightscout.core.iob.log
import info.nightscout.database.entities.GlucoseValue 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.interfaces.iob.IobCobCalculator
import info.nightscout.shared.utils.T import info.nightscout.shared.utils.T
import info.nightscout.sharedtests.TestBaseWithProfile import info.nightscout.sharedtests.TestBaseWithProfile
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
@ -30,106 +30,106 @@ class GlucoseStatusTest : TestBaseWithProfile() {
@Test fun toStringShouldBeOverloaded() { @Test fun toStringShouldBeOverloaded() {
val glucoseStatus = GlucoseStatus(glucose = 0.0, noise = 0.0, delta = 0.0, shortAvgDelta = 0.0, longAvgDelta = 0.0, date = 0) 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() { @Test fun roundTest() {
val glucoseStatus = GlucoseStatus(glucose = 100.11111, noise = 0.0, delta = 0.0, shortAvgDelta = 0.0, longAvgDelta = 0.0, date = 0) 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() { @Test fun calculateValidGlucoseStatus() {
Mockito.`when`(autosensDataStore.getBucketedDataTableCopy()).thenReturn(generateValidBgData()) Mockito.`when`(autosensDataStore.getBucketedDataTableCopy()).thenReturn(generateValidBgData())
val glucoseStatus = GlucoseStatusProviderImpl(aapsLogger, iobCobCalculatorPlugin, dateUtil, decimalFormatter).glucoseStatusData!! val glucoseStatus = GlucoseStatusProviderImpl(aapsLogger, iobCobCalculatorPlugin, dateUtil, decimalFormatter).glucoseStatusData!!
Assertions.assertEquals(214.0, glucoseStatus.glucose, 0.001) assertThat(glucoseStatus.glucose).isWithin(0.001).of(214.0)
Assertions.assertEquals(-2.0, glucoseStatus.delta, 0.001) assertThat(glucoseStatus.delta).isWithin(0.001).of(-2.0)
Assertions.assertEquals(-2.5, glucoseStatus.shortAvgDelta, 0.001) // -2 -2.5 -3 deltas are relative to current value assertThat(glucoseStatus.shortAvgDelta).isWithin(0.001).of(-2.5) // -2 -2.5 -3 deltas are relative to current value
Assertions.assertEquals(-2.0, glucoseStatus.longAvgDelta, 0.001) // -2 -2 -2 -2 assertThat(glucoseStatus.longAvgDelta).isWithin(0.001).of(-2.0) // -2 -2 -2 -2
Assertions.assertEquals(1514766900000L, glucoseStatus.date) // latest date 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() { @Test fun calculateMostRecentGlucoseStatus() {
Mockito.`when`(autosensDataStore.getBucketedDataTableCopy()).thenReturn(generateMostRecentBgData()) Mockito.`when`(autosensDataStore.getBucketedDataTableCopy()).thenReturn(generateMostRecentBgData())
val glucoseStatus: GlucoseStatus = GlucoseStatusProviderImpl(aapsLogger, iobCobCalculatorPlugin, dateUtil).glucoseStatusData!! val glucoseStatus: GlucoseStatus = GlucoseStatusProviderImpl(aapsLogger, iobCobCalculatorPlugin, dateUtil).glucoseStatusData!!
Assertions.assertEquals(215.0, glucoseStatus.glucose, 0.001) // (214+216) / 2 assertThat(glucoseStatus.glucose).isWithin(0.001).of(215.0) // (214+216) / 2
Assertions.assertEquals(-1.0, glucoseStatus.delta, 0.001) assertThat(glucoseStatus.delta).isWithin(0.001).of(-1.0)
Assertions.assertEquals(-1.0, glucoseStatus.shortAvgDelta, 0.001) assertThat(glucoseStatus.shortAvgDelta).isWithin(0.001).of(-1.0)
Assertions.assertEquals(0.0, glucoseStatus.longAvgDelta, 0.001) assertThat( glucoseStatus.longAvgDelta).isWithin(0.001).of(0.0)
Assertions.assertEquals(1514766900000L, glucoseStatus.date) // latest date, even when averaging assertThat(glucoseStatus.date).isEqualTo(1514766900000L) // latest date, even when averaging
} }
private fun generateMostRecentBgData(): MutableList<InMemoryGlucoseValue> { private fun generateMostRecentBgData(): MutableList<InMemoryGlucoseValue> {
val list: MutableList<InMemoryGlucoseValue> = ArrayList() val list: MutableList<InMemoryGlucoseValue> = ArrayList()
list.add(InMemoryGlucoseValue(value = 214.0, timestamp = 1514766900000, trendArrow = GlucoseValue.TrendArrow.FLAT)) 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 = 1514766800000, trendArrow = GlucoseValue.TrendArrow.FLAT))
list.add(InMemoryGlucoseValue(value = 216.0, timestamp = 1514766600000, trendArrow = GlucoseValue.TrendArrow.FLAT)) list.add(InMemoryGlucoseValue(value = 216.0, timestamp = 1514766600000, trendArrow = GlucoseValue.TrendArrow.FLAT))
return list return list
} }
*/ */
@Test fun oneRecordShouldProduceZeroDeltas() { @Test fun oneRecordShouldProduceZeroDeltas() {
Mockito.`when`(autosensDataStore.getBucketedDataTableCopy()).thenReturn(generateOneCurrentRecordBgData()) Mockito.`when`(autosensDataStore.getBucketedDataTableCopy()).thenReturn(generateOneCurrentRecordBgData())
val glucoseStatus: GlucoseStatus = GlucoseStatusProviderImpl(aapsLogger, iobCobCalculatorPlugin, dateUtil, decimalFormatter).glucoseStatusData!! val glucoseStatus: GlucoseStatus = GlucoseStatusProviderImpl(aapsLogger, iobCobCalculatorPlugin, dateUtil, decimalFormatter).glucoseStatusData!!
Assertions.assertEquals(214.0, glucoseStatus.glucose, 0.001) assertThat(glucoseStatus.glucose).isWithin(0.001).of(214.0)
Assertions.assertEquals(0.0, glucoseStatus.delta, 0.001) assertThat(glucoseStatus.delta).isWithin(0.001).of(0.0)
Assertions.assertEquals(0.0, glucoseStatus.shortAvgDelta, 0.001) // -2 -2.5 -3 deltas are relative to current value assertThat(glucoseStatus.shortAvgDelta).isWithin(0.001).of(0.0) // -2 -2.5 -3 deltas are relative to current value
Assertions.assertEquals(0.0, glucoseStatus.longAvgDelta, 0.001) // -2 -2 -2 -2 assertThat(glucoseStatus.longAvgDelta).isWithin(0.001).of(0.0) // -2 -2 -2 -2
Assertions.assertEquals(1514766900000L, glucoseStatus.date) // latest date assertThat(glucoseStatus.date).isEqualTo(1514766900000L) // latest date
} }
@Test fun insufficientDataShouldReturnNull() { @Test fun insufficientDataShouldReturnNull() {
Mockito.`when`(autosensDataStore.getBucketedDataTableCopy()).thenReturn(generateInsufficientBgData()) Mockito.`when`(autosensDataStore.getBucketedDataTableCopy()).thenReturn(generateInsufficientBgData())
val glucoseStatus: GlucoseStatus? = GlucoseStatusProviderImpl(aapsLogger, iobCobCalculatorPlugin, dateUtil, decimalFormatter).glucoseStatusData val glucoseStatus: GlucoseStatus? = GlucoseStatusProviderImpl(aapsLogger, iobCobCalculatorPlugin, dateUtil, decimalFormatter).glucoseStatusData
Assertions.assertEquals(null, glucoseStatus) assertThat(glucoseStatus).isNull()
} }
@Test fun oldDataShouldReturnNull() { @Test fun oldDataShouldReturnNull() {
Mockito.`when`(autosensDataStore.getBucketedDataTableCopy()).thenReturn(generateOldBgData()) Mockito.`when`(autosensDataStore.getBucketedDataTableCopy()).thenReturn(generateOldBgData())
val glucoseStatus: GlucoseStatus? = GlucoseStatusProviderImpl(aapsLogger, iobCobCalculatorPlugin, dateUtil, decimalFormatter).glucoseStatusData val glucoseStatus: GlucoseStatus? = GlucoseStatusProviderImpl(aapsLogger, iobCobCalculatorPlugin, dateUtil, decimalFormatter).glucoseStatusData
Assertions.assertEquals(null, glucoseStatus) assertThat(glucoseStatus).isNull()
} }
@Test fun returnOldDataIfAllowed() { @Test fun returnOldDataIfAllowed() {
Mockito.`when`(autosensDataStore.getBucketedDataTableCopy()).thenReturn(generateOldBgData()) Mockito.`when`(autosensDataStore.getBucketedDataTableCopy()).thenReturn(generateOldBgData())
val glucoseStatus: GlucoseStatus? = GlucoseStatusProviderImpl(aapsLogger, iobCobCalculatorPlugin, dateUtil, decimalFormatter).getGlucoseStatusData(true) val glucoseStatus: GlucoseStatus? = GlucoseStatusProviderImpl(aapsLogger, iobCobCalculatorPlugin, dateUtil, decimalFormatter).getGlucoseStatusData(true)
Assertions.assertNotEquals(null, glucoseStatus) assertThat(glucoseStatus).isNull()
} }
@Test fun averageShouldNotFailOnEmptyArray() { @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() { @Test fun calculateGlucoseStatusForLibreTestBgData() {
Mockito.`when`(autosensDataStore.getBucketedDataTableCopy()).thenReturn(generateLibreTestData()) Mockito.`when`(autosensDataStore.getBucketedDataTableCopy()).thenReturn(generateLibreTestData())
val glucoseStatus: GlucoseStatus = GlucoseStatusProviderImpl(aapsLogger, iobCobCalculatorPlugin, dateUtil).glucoseStatusData!! val glucoseStatus: GlucoseStatus = GlucoseStatusProviderImpl(aapsLogger, iobCobCalculatorPlugin, dateUtil).glucoseStatusData!!
Assertions.assertEquals(100.0, glucoseStatus.glucose, 0.001) // assertThat(glucoseStatus.glucose).isWithin(0.001).of(100.0)
Assertions.assertEquals(-10.0, glucoseStatus.delta, 0.001) assertThat(glucoseStatus.delta).isWithin(0.001).of(-10.0)
Assertions.assertEquals(-10.0, glucoseStatus.shortAvgDelta, 0.001) assertThat(glucoseStatus.shortAvgDelta).isWithin(0.001).of(-10.0)
Assertions.assertEquals(-10.0, glucoseStatus.longAvgDelta, 0.001) assertThat(glucoseStatus.longAvgDelta).isWithin(0.001).of(-10.0)
Assertions.assertEquals(1514766900000L, glucoseStatus.date) // latest date assertThat(glucoseStatus.date).isEqualTo(1514766900000L) // latest date
} }
private fun generateLibreTestData(): MutableList<InMemoryGlucoseValue> { private fun generateLibreTestData(): MutableList<InMemoryGlucoseValue> {
val list: MutableList<InMemoryGlucoseValue> = ArrayList() val list: MutableList<InMemoryGlucoseValue> = ArrayList()
val endTime = 1514766900000L val endTime = 1514766900000L
val latestReading = 100.0 val latestReading = 100.0
// Now // Now
list.add(InMemoryGlucoseValue(value = latestReading, timestamp = endTime, trendArrow = GlucoseValue.TrendArrow.FLAT)) list.add(InMemoryGlucoseValue(value = latestReading, timestamp = endTime, trendArrow = GlucoseValue.TrendArrow.FLAT))
// One minute ago // One minute ago
list.add(InMemoryGlucoseValue(value = latestReading, timestamp = endTime - 1000 * 60 * 1, trendArrow = GlucoseValue.TrendArrow.FLAT)) list.add(InMemoryGlucoseValue(value = latestReading, timestamp = endTime - 1000 * 60 * 1, trendArrow = GlucoseValue.TrendArrow.FLAT))
// Two minutes ago // Two minutes ago
list.add(InMemoryGlucoseValue(value = latestReading, timestamp = endTime - 1000 * 60 * 2, trendArrow = GlucoseValue.TrendArrow.FLAT)) list.add(InMemoryGlucoseValue(value = latestReading, timestamp = endTime - 1000 * 60 * 2, trendArrow = GlucoseValue.TrendArrow.FLAT))
// Three minutes and beyond at constant rate // Three minutes and beyond at constant rate
for (i in 3..49) for (i in 3..49)
list.add(InMemoryGlucoseValue(value = latestReading + i * 2, timestamp = endTime - 1000 * 60 * i, trendArrow = GlucoseValue.TrendArrow.FLAT)) list.add(InMemoryGlucoseValue(value = latestReading + i * 2, timestamp = endTime - 1000 * 60 * i, trendArrow = GlucoseValue.TrendArrow.FLAT))
return list return list
} }
*/ */
@BeforeEach @BeforeEach
fun initMocking() { fun initMocking() {

View file

@ -1,5 +1,6 @@
package info.nightscout.implementation.overview package info.nightscout.implementation.overview
import com.google.common.truth.Truth.assertThat
import info.nightscout.database.ValueWrapper import info.nightscout.database.ValueWrapper
import info.nightscout.database.entities.GlucoseValue import info.nightscout.database.entities.GlucoseValue
import info.nightscout.database.impl.AppRepository 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.shared.utils.T
import info.nightscout.sharedtests.TestBaseWithProfile import info.nightscout.sharedtests.TestBaseWithProfile
import io.reactivex.rxjava3.core.Single import io.reactivex.rxjava3.core.Single
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
@ -43,23 +43,23 @@ class OverviewDataImplTest : TestBaseWithProfile() {
// no data // no data
Mockito.`when`(autosensDataStore.bucketedData).thenReturn(null) Mockito.`when`(autosensDataStore.bucketedData).thenReturn(null)
Mockito.`when`(repository.getLastGlucoseValueWrapped()).thenReturn(Single.just(ValueWrapper.Absent())) Mockito.`when`(repository.getLastGlucoseValueWrapped()).thenReturn(Single.just(ValueWrapper.Absent()))
Assertions.assertNull(sut.lastBg(autosensDataStore)) assertThat(sut.lastBg(autosensDataStore)).isNull()
Assertions.assertFalse(sut.isLow(autosensDataStore)) assertThat(sut.isLow(autosensDataStore)).isFalse()
Assertions.assertFalse(sut.isHigh(autosensDataStore)) assertThat(sut.isHigh(autosensDataStore)).isFalse()
// no bucketed but in db // no bucketed but in db
Mockito.`when`(autosensDataStore.bucketedData).thenReturn(null) Mockito.`when`(autosensDataStore.bucketedData).thenReturn(null)
Mockito.`when`(repository.getLastGlucoseValueWrapped()).thenReturn(Single.just(ValueWrapper.Existing(glucoseValue))) Mockito.`when`(repository.getLastGlucoseValueWrapped()).thenReturn(Single.just(ValueWrapper.Existing(glucoseValue)))
Assertions.assertEquals(200.0, sut.lastBg(autosensDataStore)?.value) assertThat(sut.lastBg(autosensDataStore)?.value).isEqualTo(200.0)
Assertions.assertFalse(sut.isLow(autosensDataStore)) assertThat(sut.isLow(autosensDataStore)).isFalse()
Assertions.assertTrue(sut.isHigh(autosensDataStore)) assertThat(sut.isHigh(autosensDataStore)).isTrue()
// in bucketed // in bucketed
Mockito.`when`(autosensDataStore.bucketedData).thenReturn(bucketedData) Mockito.`when`(autosensDataStore.bucketedData).thenReturn(bucketedData)
Mockito.`when`(repository.getLastGlucoseValueWrapped()).thenReturn(Single.just(ValueWrapper.Existing(glucoseValue))) Mockito.`when`(repository.getLastGlucoseValueWrapped()).thenReturn(Single.just(ValueWrapper.Existing(glucoseValue)))
Assertions.assertEquals(70.0, sut.lastBg(autosensDataStore)?.value) assertThat(sut.lastBg(autosensDataStore)?.value).isEqualTo(70.0)
Assertions.assertTrue(sut.isLow(autosensDataStore)) assertThat(sut.isLow(autosensDataStore)).isTrue()
Assertions.assertFalse(sut.isHigh(autosensDataStore)) assertThat(sut.isHigh(autosensDataStore)).isFalse()
} }
@Test @Test
@ -68,13 +68,13 @@ class OverviewDataImplTest : TestBaseWithProfile() {
Mockito.`when`(autosensDataStore.bucketedData).thenReturn(null) Mockito.`when`(autosensDataStore.bucketedData).thenReturn(null)
Mockito.`when`(repository.getLastGlucoseValueWrapped()).thenReturn(Single.just(ValueWrapper.Existing(glucoseValue))) Mockito.`when`(repository.getLastGlucoseValueWrapped()).thenReturn(Single.just(ValueWrapper.Existing(glucoseValue)))
Mockito.`when`(dateUtil.now()).thenReturn(time + T.mins(1).msecs()) 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) Mockito.`when`(dateUtil.now()).thenReturn(time + T.mins(9).msecs() + 1)
Assertions.assertFalse(sut.isActualBg(autosensDataStore)) assertThat(sut.isActualBg(autosensDataStore)).isFalse()
// no data // no data
Mockito.`when`(autosensDataStore.bucketedData).thenReturn(null) Mockito.`when`(autosensDataStore.bucketedData).thenReturn(null)
Mockito.`when`(repository.getLastGlucoseValueWrapped()).thenReturn(Single.just(ValueWrapper.Absent())) Mockito.`when`(repository.getLastGlucoseValueWrapped()).thenReturn(Single.just(ValueWrapper.Absent()))
Assertions.assertFalse(sut.isActualBg(autosensDataStore)) assertThat(sut.isActualBg(autosensDataStore)).isFalse()
} }
} }

View file

@ -1,47 +1,47 @@
package info.nightscout.implementation.profile package info.nightscout.implementation.profile
import com.google.common.truth.Truth.assertThat
import info.nightscout.interfaces.profile.PureProfile import info.nightscout.interfaces.profile.PureProfile
import info.nightscout.sharedtests.TestBaseWithProfile import info.nightscout.sharedtests.TestBaseWithProfile
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
internal class ProfileStoreTest : TestBaseWithProfile() { internal class ProfileStoreTest : TestBaseWithProfile() {
@Test @Test
fun getStartDateTest() { fun getStartDateTest() {
Assertions.assertEquals(0, getValidProfileStore().getStartDate()) assertThat(getValidProfileStore().getStartDate()).isEqualTo(0)
} }
@Test @Test
fun getDefaultProfileTest() { fun getDefaultProfileTest() {
Assertions.assertTrue(getValidProfileStore().getDefaultProfile() is PureProfile) assertThat(getValidProfileStore().getDefaultProfile()).isInstanceOf(PureProfile::class.java)
} }
@Test @Test
fun getDefaultProfileJsonTest() { fun getDefaultProfileJsonTest() {
Assertions.assertTrue(getValidProfileStore().getDefaultProfileJson()?.has("dia") ?: false) assertThat(getValidProfileStore().getDefaultProfileJson()?.has("dia")).isTrue()
Assertions.assertEquals(null, getInvalidProfileStore2().getDefaultProfileJson()) assertThat(getInvalidProfileStore2().getDefaultProfileJson()).isNull()
} }
@Test @Test
fun getDefaultProfileNameTest() { fun getDefaultProfileNameTest() {
Assertions.assertEquals(TESTPROFILENAME, getValidProfileStore().getDefaultProfileName()) assertThat(getValidProfileStore().getDefaultProfileName()).isEqualTo(TESTPROFILENAME)
} }
@Test @Test
fun getProfileListTest() { fun getProfileListTest() {
Assertions.assertEquals(1, getValidProfileStore().getProfileList().size) assertThat(getValidProfileStore().getProfileList()).hasSize(1)
} }
@Test @Test
fun getSpecificProfileTest() { fun getSpecificProfileTest() {
Assertions.assertTrue(getValidProfileStore().getSpecificProfile(TESTPROFILENAME) is PureProfile) assertThat(getValidProfileStore().getSpecificProfile(TESTPROFILENAME)).isInstanceOf(PureProfile::class.java)
} }
@Test @Test
fun allProfilesValidTest() { fun allProfilesValidTest() {
Assertions.assertTrue(getValidProfileStore().allProfilesValid) assertThat(getValidProfileStore().allProfilesValid).isTrue()
Assertions.assertFalse(getInvalidProfileStore1().allProfilesValid) assertThat(getInvalidProfileStore1().allProfilesValid).isFalse()
Assertions.assertFalse(getInvalidProfileStore2().allProfilesValid) assertThat(getInvalidProfileStore2().allProfilesValid).isFalse()
} }
} }

View file

@ -1,12 +1,12 @@
package info.nightscout.implementation.profile package info.nightscout.implementation.profile
import com.google.common.truth.Truth.assertThat
import info.nightscout.database.entities.GlucoseValue import info.nightscout.database.entities.GlucoseValue
import info.nightscout.implementation.utils.DecimalFormatterImpl import info.nightscout.implementation.utils.DecimalFormatterImpl
import info.nightscout.interfaces.GlucoseUnit import info.nightscout.interfaces.GlucoseUnit
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
@ -29,19 +29,19 @@ class ProfileUtilImplTest : TestBase() {
@Test @Test
fun toUnitsString() { fun toUnitsString() {
Assertions.assertEquals("100", sut.fromMgdlToStringInUnits(glucoseValue.value, GlucoseUnit.MGDL)) assertThat(sut.fromMgdlToStringInUnits(glucoseValue.value, GlucoseUnit.MGDL)).isEqualTo("100")
Assertions.assertEquals("5.6", sut.fromMgdlToStringInUnits(glucoseValue.value, GlucoseUnit.MMOL)) assertThat(sut.fromMgdlToStringInUnits(glucoseValue.value, GlucoseUnit.MMOL)).isEqualTo("5.6")
Assertions.assertEquals(0.1, sut.convertToMgdl(0.1, GlucoseUnit.MGDL), 0.01) assertThat(sut.convertToMgdl(0.1, GlucoseUnit.MGDL)).isWithin(0.01).of(0.1)
Assertions.assertEquals(18.0, sut.convertToMgdl(1.0, GlucoseUnit.MMOL), 0.01) assertThat(sut.convertToMgdl(1.0, GlucoseUnit.MMOL)).isWithin(0.01).of(18.0)
Assertions.assertEquals(1.0, sut.convertToMmol(18.0, GlucoseUnit.MGDL), 0.01) assertThat(sut.convertToMmol(18.0, GlucoseUnit.MGDL)).isWithin(0.01).of(1.0)
Assertions.assertEquals(18.0, sut.convertToMmol(18.0, GlucoseUnit.MMOL), 0.01) assertThat(sut.convertToMmol(18.0, GlucoseUnit.MMOL)).isWithin(0.01).of(18.0)
Assertions.assertEquals(18.0, sut.fromMgdlToUnits(18.0, GlucoseUnit.MGDL), 0.01) assertThat(sut.fromMgdlToUnits(18.0, GlucoseUnit.MGDL)).isWithin(0.01).of(18.0)
Assertions.assertEquals(1.0, sut.fromMgdlToUnits(18.0, GlucoseUnit.MMOL), 0.01) assertThat(sut.fromMgdlToUnits(18.0, GlucoseUnit.MMOL)).isWithin(0.01).of(1.0)
Assertions.assertEquals(18.0, sut.fromMgdlToUnits(18.0, GlucoseUnit.MGDL), 0.01) assertThat(sut.fromMgdlToUnits(18.0, GlucoseUnit.MGDL)).isWithin(0.01).of(18.0)
Assertions.assertEquals(1.0, sut.fromMgdlToUnits(18.0, GlucoseUnit.MMOL), 0.01) assertThat(sut.fromMgdlToUnits(18.0, GlucoseUnit.MMOL)).isWithin(0.01).of(1.0)
Assertions.assertEquals("18", sut.fromMgdlToStringInUnits(18.0, GlucoseUnit.MGDL)) assertThat(sut.fromMgdlToStringInUnits(18.0, GlucoseUnit.MGDL)).isEqualTo("18")
Assertions.assertEquals("1.0", sut.fromMgdlToStringInUnits(18.0, GlucoseUnit.MMOL).replace(",", ".")) assertThat(sut.fromMgdlToStringInUnits(18.0, GlucoseUnit.MMOL).replace(",", ".")).isEqualTo("1.0")
Assertions.assertEquals("5 - 6", sut.toTargetRangeString(5.0, 6.0, GlucoseUnit.MGDL, GlucoseUnit.MGDL)) assertThat(sut.toTargetRangeString(5.0, 6.0, GlucoseUnit.MGDL, GlucoseUnit.MGDL)).isEqualTo("5 - 6")
Assertions.assertEquals("4", sut.toTargetRangeString(4.0, 4.0, GlucoseUnit.MGDL, GlucoseUnit.MGDL)) assertThat(sut.toTargetRangeString(4.0, 4.0, GlucoseUnit.MGDL, GlucoseUnit.MGDL)).isEqualTo("4")
} }
} }

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)
} }
} }

View file

@ -1,8 +1,8 @@
package info.nightscout.implementation.pump package info.nightscout.implementation.pump
import com.google.common.truth.Truth.assertThat
import info.nightscout.interfaces.pump.PumpSync import info.nightscout.interfaces.pump.PumpSync
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
@ -29,9 +29,9 @@ class TemporaryBasalStorageTest : TestBase() {
@Test @Test
fun add() { fun add() {
temporaryBasalStorage.store.clear() temporaryBasalStorage.store.clear()
Assertions.assertEquals(0, temporaryBasalStorage.store.size) assertThat(temporaryBasalStorage.store).isEmpty()
temporaryBasalStorage.add(info1) temporaryBasalStorage.add(info1)
Assertions.assertEquals(1, temporaryBasalStorage.store.size) assertThat(temporaryBasalStorage.store).hasSize(1)
} }
@Test @Test
@ -40,38 +40,38 @@ class TemporaryBasalStorageTest : TestBase() {
// Look for exact bolus // Look for exact bolus
setUp() setUp()
var d = temporaryBasalStorage.findTemporaryBasal(1000000, 4.0) var d = temporaryBasalStorage.findTemporaryBasal(1000000, 4.0)
Assertions.assertEquals(4.0, d!!.rate, 0.01) assertThat(d!!.rate).isWithin(0.01).of(4.0)
Assertions.assertEquals(2, temporaryBasalStorage.store.size) assertThat(temporaryBasalStorage.store).hasSize(2)
// Look for exact bolus // Look for exact bolus
setUp() setUp()
d = temporaryBasalStorage.findTemporaryBasal(1000000, 3.0) d = temporaryBasalStorage.findTemporaryBasal(1000000, 3.0)
Assertions.assertEquals(3.0, d!!.rate, 0.01) assertThat(d!!.rate).isWithin(0.01).of(3.0)
Assertions.assertEquals(2, temporaryBasalStorage.store.size) assertThat(temporaryBasalStorage.store).hasSize(2)
// With less rate (bolus not delivered completely). Should return first one matching date // With less rate (bolus not delivered completely). Should return first one matching date
setUp() setUp()
d = temporaryBasalStorage.findTemporaryBasal(1000500, 2.0) d = temporaryBasalStorage.findTemporaryBasal(1000500, 2.0)
Assertions.assertEquals(3.0, d!!.rate, 0.01) assertThat(d!!.rate).isWithin(0.01).of(3.0)
Assertions.assertEquals(2, temporaryBasalStorage.store.size) assertThat(temporaryBasalStorage.store).hasSize(2)
// With less rate (bolus not delivered completely). Should return first one matching date // With less rate (bolus not delivered completely). Should return first one matching date
setUp() setUp()
d = temporaryBasalStorage.findTemporaryBasal(1000500, 3.5) d = temporaryBasalStorage.findTemporaryBasal(1000500, 3.5)
Assertions.assertEquals(4.0, d!!.rate, 0.01) assertThat(d!!.rate).isWithin(0.01).of(4.0)
Assertions.assertEquals(2, temporaryBasalStorage.store.size) assertThat(temporaryBasalStorage.store).hasSize(2)
// With more rate should return null // With more rate should return null
setUp() setUp()
d = temporaryBasalStorage.findTemporaryBasal(1000500, 4.5) d = temporaryBasalStorage.findTemporaryBasal(1000500, 4.5)
Assertions.assertNull(d) assertThat(d).isNull()
Assertions.assertEquals(3, temporaryBasalStorage.store.size) assertThat(temporaryBasalStorage.store).hasSize(3)
// With more than one minute off should return null // With more than one minute off should return null
setUp() setUp()
d = temporaryBasalStorage.findTemporaryBasal(1070000, 4.0) d = temporaryBasalStorage.findTemporaryBasal(1070000, 4.0)
Assertions.assertNull(d) assertThat(d).isNull()
Assertions.assertEquals(3, temporaryBasalStorage.store.size) assertThat(temporaryBasalStorage.store).hasSize(3)
// Use last, if bolus size is the same // Use last, if bolus size is the same
setUp() setUp()
d = temporaryBasalStorage.findTemporaryBasal(1070000, 5.0) d = temporaryBasalStorage.findTemporaryBasal(1070000, 5.0)
Assertions.assertEquals(5.0, d!!.rate, 0.01) assertThat(d!!.rate).isWithin(0.01).of(5.0)
Assertions.assertEquals(2, temporaryBasalStorage.store.size) assertThat(temporaryBasalStorage.store).hasSize(2)
} }
} }

View file

@ -1,5 +1,6 @@
package info.nightscout.implementation.queue package info.nightscout.implementation.queue
import com.google.common.truth.Truth.assertThat
import android.content.Context import android.content.Context
import android.os.Handler import android.os.Handler
import android.os.PowerManager import android.os.PowerManager
@ -38,7 +39,6 @@ import info.nightscout.shared.utils.DateUtil
import info.nightscout.sharedtests.TestBaseWithProfile import info.nightscout.sharedtests.TestBaseWithProfile
import info.nightscout.sharedtests.TestPumpPlugin import info.nightscout.sharedtests.TestPumpPlugin
import io.reactivex.rxjava3.core.Single import io.reactivex.rxjava3.core.Single
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
@ -169,121 +169,121 @@ class CommandQueueImplementationTest : TestBaseWithProfile() {
commandQueue.handler = handler commandQueue.handler = handler
// start with empty queue // start with empty queue
Assertions.assertEquals(0, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(0)
// add bolus command // add bolus command
commandQueue.bolus(DetailedBolusInfo(), null) commandQueue.bolus(DetailedBolusInfo(), null)
Assertions.assertEquals(1, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(1)
commandQueue.waitForFinishedThread() commandQueue.waitForFinishedThread()
Thread.sleep(1000) Thread.sleep(1000)
Assertions.assertEquals(0, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(0)
} }
@Test @Test
fun doTests() { fun doTests() {
// start with empty queue // start with empty queue
Assertions.assertEquals(0, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(0)
// add bolus command // add bolus command
commandQueue.bolus(DetailedBolusInfo(), null) commandQueue.bolus(DetailedBolusInfo(), null)
Assertions.assertEquals(1, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(1)
// add READSTATUS // add READSTATUS
commandQueue.readStatus("anyString", null) 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) // adding another bolus should remove the first one (size still == 2)
commandQueue.bolus(DetailedBolusInfo(), null) commandQueue.bolus(DetailedBolusInfo(), null)
Assertions.assertEquals(2, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(2)
// clear the queue should reset size // clear the queue should reset size
commandQueue.clear() commandQueue.clear()
Assertions.assertEquals(0, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(0)
// add tempbasal // add tempbasal
commandQueue.tempBasalAbsolute(0.0, 30, true, validProfile, PumpSync.TemporaryBasalType.NORMAL, null) 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 // add tempbasal percent. it should replace previous TEMPBASAL
commandQueue.tempBasalPercent(0, 30, true, validProfile, PumpSync.TemporaryBasalType.NORMAL, null) 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 // cancel tempbasal it should replace previous TEMPBASAL
commandQueue.cancelTempBasal(false, null) commandQueue.cancelTempBasal(false, null)
Assertions.assertEquals(1, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(1)
// add extended bolus // add extended bolus
commandQueue.extendedBolus(1.0, 30, null) commandQueue.extendedBolus(1.0, 30, null)
Assertions.assertEquals(2, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(2)
// add extended should remove previous extended setting // add extended should remove previous extended setting
commandQueue.extendedBolus(1.0, 30, null) commandQueue.extendedBolus(1.0, 30, null)
Assertions.assertEquals(2, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(2)
// cancel extended bolus should replace previous extended // cancel extended bolus should replace previous extended
commandQueue.cancelExtended(null) commandQueue.cancelExtended(null)
Assertions.assertEquals(2, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(2)
// add setProfile // add setProfile
// TODO: this crash the test // TODO: this crash the test
// commandQueue.setProfile(validProfile, null) // commandQueue.setProfile(validProfile, null)
// Assertions.assertEquals(3, commandQueue.size()) // assertThat(commandQueue.size()).isEqualTo(3)
// add loadHistory // add loadHistory
commandQueue.loadHistory(0.toByte(), null) commandQueue.loadHistory(0.toByte(), null)
Assertions.assertEquals(3, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(3)
// add loadEvents // add loadEvents
commandQueue.loadEvents(null) commandQueue.loadEvents(null)
Assertions.assertEquals(4, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(4)
// add clearAlarms // add clearAlarms
commandQueue.clearAlarms(null) commandQueue.clearAlarms(null)
Assertions.assertEquals(5, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(5)
// add deactivate // add deactivate
commandQueue.deactivate(null) commandQueue.deactivate(null)
Assertions.assertEquals(6, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(6)
// add updateTime // add updateTime
commandQueue.updateTime(null) commandQueue.updateTime(null)
Assertions.assertEquals(7, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(7)
commandQueue.clear() commandQueue.clear()
commandQueue.tempBasalAbsolute(0.0, 30, true, validProfile, PumpSync.TemporaryBasalType.NORMAL, null) commandQueue.tempBasalAbsolute(0.0, 30, true, validProfile, PumpSync.TemporaryBasalType.NORMAL, null)
commandQueue.pickup() commandQueue.pickup()
Assertions.assertEquals(0, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(0)
Assertions.assertNotNull(commandQueue.performing) assertThat(commandQueue.performing).isNotNull()
Assertions.assertEquals(Command.CommandType.TEMPBASAL, commandQueue.performing?.commandType) assertThat(commandQueue.performing?.commandType).isEqualTo(Command.CommandType.TEMPBASAL)
commandQueue.resetPerforming() commandQueue.resetPerforming()
Assertions.assertNull(commandQueue.performing) assertThat(commandQueue.performing).isNull()
} }
@Test @Test
fun callingCancelAllBolusesClearsQueue() { fun callingCancelAllBolusesClearsQueue() {
// given // given
Assertions.assertEquals(0, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(0)
val smb = DetailedBolusInfo() val smb = DetailedBolusInfo()
smb.lastKnownBolusTime = System.currentTimeMillis() smb.lastKnownBolusTime = System.currentTimeMillis()
smb.bolusType = DetailedBolusInfo.BolusType.SMB smb.bolusType = DetailedBolusInfo.BolusType.SMB
commandQueue.bolus(smb, null) commandQueue.bolus(smb, null)
commandQueue.bolus(DetailedBolusInfo(), null) commandQueue.bolus(DetailedBolusInfo(), null)
Assertions.assertEquals(2, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(2)
// when // when
commandQueue.cancelAllBoluses(null) commandQueue.cancelAllBoluses(null)
// then // then
Assertions.assertEquals(0, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(0)
} }
@Test @Test
fun smbIsRejectedIfABolusIsQueued() { fun smbIsRejectedIfABolusIsQueued() {
// given // given
Assertions.assertEquals(0, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(0)
// when // when
commandQueue.bolus(DetailedBolusInfo(), null) commandQueue.bolus(DetailedBolusInfo(), null)
@ -292,14 +292,14 @@ class CommandQueueImplementationTest : TestBaseWithProfile() {
val queued: Boolean = commandQueue.bolus(smb, null) val queued: Boolean = commandQueue.bolus(smb, null)
// then // then
Assertions.assertFalse(queued) assertThat(queued).isFalse()
Assertions.assertEquals(commandQueue.size(), 1) assertThat(commandQueue.size()).isEqualTo(1)
} }
@Test @Test
fun smbIsRejectedIfLastKnownBolusIsOutdated() { fun smbIsRejectedIfLastKnownBolusIsOutdated() {
// given // given
Assertions.assertEquals(0, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(0)
// when // when
val bolus = DetailedBolusInfo() val bolus = DetailedBolusInfo()
@ -308,14 +308,14 @@ class CommandQueueImplementationTest : TestBaseWithProfile() {
val queued: Boolean = commandQueue.bolus(bolus, null) val queued: Boolean = commandQueue.bolus(bolus, null)
// then // then
Assertions.assertFalse(queued) assertThat(queued).isFalse()
Assertions.assertEquals(commandQueue.size(), 0) assertThat(commandQueue.size()).isEqualTo(0)
} }
@Test @Test
fun isCustomCommandRunning() { fun isCustomCommandRunning() {
// given // given
Assertions.assertEquals(0, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(0)
// when // when
val queued1 = commandQueue.customCommand(CustomCommand1(), null) val queued1 = commandQueue.customCommand(CustomCommand1(), null)
@ -323,249 +323,249 @@ class CommandQueueImplementationTest : TestBaseWithProfile() {
commandQueue.pickup() commandQueue.pickup()
// then // then
Assertions.assertTrue(queued1) assertThat(queued1).isTrue()
Assertions.assertTrue(queued2) assertThat(queued2).isTrue()
Assertions.assertTrue(commandQueue.isCustomCommandInQueue(CustomCommand1::class.java)) assertThat(commandQueue.isCustomCommandInQueue(CustomCommand1::class.java)).isTrue()
Assertions.assertTrue(commandQueue.isCustomCommandInQueue(CustomCommand2::class.java)) assertThat(commandQueue.isCustomCommandInQueue(CustomCommand2::class.java)).isTrue()
Assertions.assertFalse(commandQueue.isCustomCommandInQueue(CustomCommand3::class.java)) assertThat(commandQueue.isCustomCommandInQueue(CustomCommand3::class.java)).isFalse()
Assertions.assertTrue(commandQueue.isCustomCommandRunning(CustomCommand1::class.java)) assertThat(commandQueue.isCustomCommandRunning(CustomCommand1::class.java)).isTrue()
Assertions.assertFalse(commandQueue.isCustomCommandRunning(CustomCommand2::class.java)) assertThat(commandQueue.isCustomCommandRunning(CustomCommand2::class.java)).isFalse()
Assertions.assertFalse(commandQueue.isCustomCommandRunning(CustomCommand3::class.java)) assertThat(commandQueue.isCustomCommandRunning(CustomCommand3::class.java)).isFalse()
Assertions.assertEquals(1, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(1)
} }
@Test @Test
fun isSetUserOptionsCommandInQueue() { fun isSetUserOptionsCommandInQueue() {
// given // given
Assertions.assertEquals(0, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(0)
// when // when
commandQueue.setUserOptions(null) commandQueue.setUserOptions(null)
// then // then
Assertions.assertTrue(commandQueue.isLastScheduled(Command.CommandType.SET_USER_SETTINGS)) assertThat(commandQueue.isLastScheduled(Command.CommandType.SET_USER_SETTINGS)).isTrue()
Assertions.assertEquals(1, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(1)
// next should be ignored // next should be ignored
commandQueue.setUserOptions(null) commandQueue.setUserOptions(null)
Assertions.assertEquals(1, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(1)
} }
@Test @Test
fun isLoadEventsCommandInQueue() { fun isLoadEventsCommandInQueue() {
// given // given
Assertions.assertEquals(0, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(0)
// when // when
commandQueue.loadEvents(null) commandQueue.loadEvents(null)
// then // then
Assertions.assertTrue(commandQueue.isLastScheduled(Command.CommandType.LOAD_EVENTS)) assertThat(commandQueue.isLastScheduled(Command.CommandType.LOAD_EVENTS)).isTrue()
Assertions.assertEquals(1, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(1)
// next should be ignored // next should be ignored
commandQueue.loadEvents(null) commandQueue.loadEvents(null)
Assertions.assertEquals(1, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(1)
} }
@Test @Test
fun isClearAlarmsCommandInQueue() { fun isClearAlarmsCommandInQueue() {
// given // given
Assertions.assertEquals(0, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(0)
// when // when
commandQueue.clearAlarms(null) commandQueue.clearAlarms(null)
// then // then
Assertions.assertTrue(commandQueue.isLastScheduled(Command.CommandType.CLEAR_ALARMS)) assertThat(commandQueue.isLastScheduled(Command.CommandType.CLEAR_ALARMS)).isTrue()
Assertions.assertEquals(1, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(1)
// next should be ignored // next should be ignored
commandQueue.clearAlarms(null) commandQueue.clearAlarms(null)
Assertions.assertEquals(1, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(1)
} }
@Test @Test
fun isDeactivateCommandInQueue() { fun isDeactivateCommandInQueue() {
// given // given
Assertions.assertEquals(0, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(0)
// when // when
commandQueue.deactivate(null) commandQueue.deactivate(null)
// then // then
Assertions.assertTrue(commandQueue.isLastScheduled(Command.CommandType.DEACTIVATE)) assertThat(commandQueue.isLastScheduled(Command.CommandType.DEACTIVATE)).isTrue()
Assertions.assertEquals(1, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(1)
// next should be ignored // next should be ignored
commandQueue.deactivate(null) commandQueue.deactivate(null)
Assertions.assertEquals(1, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(1)
} }
@Test @Test
fun isUpdateTimeCommandInQueue() { fun isUpdateTimeCommandInQueue() {
// given // given
Assertions.assertEquals(0, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(0)
// when // when
commandQueue.updateTime(null) commandQueue.updateTime(null)
// then // then
Assertions.assertTrue(commandQueue.isLastScheduled(Command.CommandType.UPDATE_TIME)) assertThat(commandQueue.isLastScheduled(Command.CommandType.UPDATE_TIME)).isTrue()
Assertions.assertEquals(1, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(1)
// next should be ignored // next should be ignored
commandQueue.updateTime(null) commandQueue.updateTime(null)
Assertions.assertEquals(1, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(1)
} }
@Test @Test
fun isLoadTDDsCommandInQueue() { fun isLoadTDDsCommandInQueue() {
// given // given
Assertions.assertEquals(0, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(0)
// when // when
commandQueue.loadTDDs(null) commandQueue.loadTDDs(null)
// then // then
Assertions.assertEquals(1, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(1)
// next should be ignored // next should be ignored
commandQueue.loadTDDs(null) commandQueue.loadTDDs(null)
Assertions.assertEquals(1, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(1)
} }
@Test @Test
fun isLoadHistoryCommandInQueue() { fun isLoadHistoryCommandInQueue() {
// given // given
Assertions.assertEquals(0, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(0)
// when // when
commandQueue.loadHistory(0, null) commandQueue.loadHistory(0, null)
// then // then
Assertions.assertTrue(commandQueue.isLastScheduled(Command.CommandType.LOAD_HISTORY)) assertThat(commandQueue.isLastScheduled(Command.CommandType.LOAD_HISTORY)).isTrue()
Assertions.assertEquals(1, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(1)
// next should be ignored // next should be ignored
commandQueue.loadHistory(0, null) commandQueue.loadHistory(0, null)
Assertions.assertEquals(1, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(1)
} }
@Test @Test
fun isProfileSetCommandInQueue() { fun isProfileSetCommandInQueue() {
// given // given
Assertions.assertEquals(0, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(0)
// when // when
testPumpPlugin.isProfileSet = true testPumpPlugin.isProfileSet = true
commandQueue.setProfile(validProfile, false, object : Callback() { commandQueue.setProfile(validProfile, false, object : Callback() {
override fun run() { override fun run() {
Assertions.assertTrue(result.success) assertThat(result.success).isTrue()
Assertions.assertFalse(result.enacted) assertThat(result.enacted).isFalse()
} }
}) })
// then // then
// the same profile -> ignore // the same profile -> ignore
Assertions.assertEquals(0, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(0)
// different should be added // different should be added
testPumpPlugin.isProfileSet = false testPumpPlugin.isProfileSet = false
commandQueue.setProfile(validProfile, false, object : Callback() { commandQueue.setProfile(validProfile, false, object : Callback() {
override fun run() { override fun run() {
Assertions.assertTrue(result.success) assertThat(result.success).isTrue()
Assertions.assertTrue(result.enacted) assertThat(result.enacted).isTrue()
} }
}) })
Assertions.assertEquals(1, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(1)
// next should be ignored // next should be ignored
commandQueue.setProfile(validProfile, false, object : Callback() { commandQueue.setProfile(validProfile, false, object : Callback() {
override fun run() { override fun run() {
Assertions.assertTrue(result.success) assertThat(result.success).isTrue()
} }
}) })
Assertions.assertEquals(1, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(1)
testPumpPlugin.isProfileSet = true testPumpPlugin.isProfileSet = true
} }
@Test @Test
fun isStopCommandInQueue() { fun isStopCommandInQueue() {
// given // given
Assertions.assertEquals(0, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(0)
// when // when
commandQueue.stopPump(null) commandQueue.stopPump(null)
// then // then
Assertions.assertTrue(commandQueue.isLastScheduled(Command.CommandType.STOP_PUMP)) assertThat(commandQueue.isLastScheduled(Command.CommandType.STOP_PUMP)).isTrue()
Assertions.assertEquals(1, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(1)
} }
@Test @Test
fun isStarCommandInQueue() { fun isStarCommandInQueue() {
// given // given
Assertions.assertEquals(0, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(0)
// when // when
commandQueue.startPump(null) commandQueue.startPump(null)
// then // then
Assertions.assertTrue(commandQueue.isLastScheduled(Command.CommandType.START_PUMP)) assertThat(commandQueue.isLastScheduled(Command.CommandType.START_PUMP)).isTrue()
Assertions.assertEquals(1, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(1)
} }
@Test @Test
fun isSetTbrNotificationCommandInQueue() { fun isSetTbrNotificationCommandInQueue() {
// given // given
Assertions.assertEquals(0, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(0)
// when // when
commandQueue.setTBROverNotification(null, true) commandQueue.setTBROverNotification(null, true)
// then // then
Assertions.assertTrue(commandQueue.isLastScheduled(Command.CommandType.INSIGHT_SET_TBR_OVER_ALARM)) assertThat(commandQueue.isLastScheduled(Command.CommandType.INSIGHT_SET_TBR_OVER_ALARM)).isTrue()
Assertions.assertEquals(1, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(1)
} }
@Test @Test
fun differentCustomCommandsAllowed() { fun differentCustomCommandsAllowed() {
// given // given
Assertions.assertEquals(0, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(0)
// when // when
val queued1 = commandQueue.customCommand(CustomCommand1(), null) val queued1 = commandQueue.customCommand(CustomCommand1(), null)
val queued2 = commandQueue.customCommand(CustomCommand2(), null) val queued2 = commandQueue.customCommand(CustomCommand2(), null)
// then // then
Assertions.assertTrue(queued1) assertThat(queued1).isTrue()
Assertions.assertTrue(queued2) assertThat(queued2).isTrue()
Assertions.assertEquals(2, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(2)
} }
@Test @Test
fun sameCustomCommandNotAllowed() { fun sameCustomCommandNotAllowed() {
// given // given
Assertions.assertEquals(0, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(0)
// when // when
val queued1 = commandQueue.customCommand(CustomCommand1(), null) val queued1 = commandQueue.customCommand(CustomCommand1(), null)
val queued2 = commandQueue.customCommand(CustomCommand1(), null) val queued2 = commandQueue.customCommand(CustomCommand1(), null)
// then // then
Assertions.assertTrue(queued1) assertThat(queued1).isTrue()
Assertions.assertFalse(queued2) assertThat(queued2).isFalse()
Assertions.assertEquals(1, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(1)
} }
@Test @Test
fun readStatusTwiceIsNotAllowed() { fun readStatusTwiceIsNotAllowed() {
// given // given
Assertions.assertEquals(0, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(0)
// when // when
val queued1 = commandQueue.readStatus("1", null) val queued1 = commandQueue.readStatus("1", null)
val queued2 = commandQueue.readStatus("2", null) val queued2 = commandQueue.readStatus("2", null)
// then // then
Assertions.assertTrue(queued1) assertThat(queued1).isTrue()
Assertions.assertFalse(queued2) assertThat(queued2).isFalse()
Assertions.assertEquals(1, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(1)
Assertions.assertTrue(commandQueue.statusInQueue()) assertThat(commandQueue.statusInQueue()).isTrue()
} }
private class CustomCommand1 : CustomCommand { private class CustomCommand1 : CustomCommand {

View file

@ -1,5 +1,6 @@
package info.nightscout.implementation.queue package info.nightscout.implementation.queue
import com.google.common.truth.Truth.assertThat
import android.content.Context import android.content.Context
import android.os.PowerManager import android.os.PowerManager
import dagger.android.AndroidInjector import dagger.android.AndroidInjector
@ -16,7 +17,6 @@ import info.nightscout.interfaces.queue.Command
import info.nightscout.interfaces.ui.UiInteraction import info.nightscout.interfaces.ui.UiInteraction
import info.nightscout.sharedtests.TestBaseWithProfile import info.nightscout.sharedtests.TestBaseWithProfile
import info.nightscout.sharedtests.TestPumpPlugin import info.nightscout.sharedtests.TestPumpPlugin
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.ArgumentMatchers import org.mockito.ArgumentMatchers
@ -84,6 +84,6 @@ class QueueThreadTest : TestBaseWithProfile() {
commandQueue.tempBasalAbsolute(2.0, 60, true, validProfile, PumpSync.TemporaryBasalType.NORMAL, null) commandQueue.tempBasalAbsolute(2.0, 60, true, validProfile, PumpSync.TemporaryBasalType.NORMAL, null)
@Suppress("CallToThreadRun") @Suppress("CallToThreadRun")
sut.run() sut.run()
Assertions.assertEquals(0, commandQueue.size()) assertThat(commandQueue.size()).isEqualTo(0)
} }
} }

View file

@ -1,9 +1,9 @@
package info.nightscout.implementation.utils package info.nightscout.implementation.utils
import com.google.common.truth.Truth.assertThat
import info.nightscout.interfaces.utils.DecimalFormatter import info.nightscout.interfaces.utils.DecimalFormatter
import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.interfaces.ResourceHelper
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
@ -20,22 +20,22 @@ class DecimalFormatterTest : TestBase() {
} }
@Test fun to0DecimalTest() { @Test fun to0DecimalTest() {
Assertions.assertEquals("1", sut.to0Decimal(1.33).replace(",", ".")) assertThat(sut.to0Decimal(1.33).replace(",", ".")).isEqualTo("1")
Assertions.assertEquals("1U", sut.to0Decimal(1.33, "U").replace(",", ".")) assertThat(sut.to0Decimal(1.33, "U").replace(",", ".")).isEqualTo("1U")
} }
@Test fun to1DecimalTest() { @Test fun to1DecimalTest() {
Assertions.assertEquals("1.3", sut.to1Decimal(1.33).replace(",", ".")) assertThat(sut.to1Decimal(1.33).replace(",", ".")).isEqualTo("1.3")
Assertions.assertEquals("1.3U", sut.to1Decimal(1.33, "U").replace(",", ".")) assertThat(sut.to1Decimal(1.33, "U").replace(",", ".")).isEqualTo("1.3U")
} }
@Test fun to2DecimalTest() { @Test fun to2DecimalTest() {
Assertions.assertEquals("1.33", sut.to2Decimal(1.3333).replace(",", ".")) assertThat(sut.to2Decimal(1.3333).replace(",", ".")).isEqualTo("1.33")
Assertions.assertEquals("1.33U", sut.to2Decimal(1.3333, "U").replace(",", ".")) assertThat(sut.to2Decimal(1.3333, "U").replace(",", ".")).isEqualTo("1.33U")
} }
@Test fun to3DecimalTest() { @Test fun to3DecimalTest() {
Assertions.assertEquals("1.333", sut.to3Decimal(1.3333).replace(",", ".")) assertThat(sut.to3Decimal(1.3333).replace(",", ".")).isEqualTo("1.333")
Assertions.assertEquals("1.333U", sut.to3Decimal(1.3333, "U").replace(",", ".")) assertThat(sut.to3Decimal(1.3333, "U").replace(",", ".")).isEqualTo("1.333U")
} }
} }