Merge pull request #2807 from ryanhaining/assertthat_implementation
Rewrites implementation/ tests with matchers
This commit is contained in:
commit
a1517462ac
9 changed files with 257 additions and 257 deletions
|
@ -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<InMemoryGlucoseValue> {
|
||||
val list: MutableList<InMemoryGlucoseValue> = 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<InMemoryGlucoseValue> {
|
||||
val list: MutableList<InMemoryGlucoseValue> = 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<InMemoryGlucoseValue> {
|
||||
val list: MutableList<InMemoryGlucoseValue> = 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<InMemoryGlucoseValue> {
|
||||
val list: MutableList<InMemoryGlucoseValue> = 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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue