TherapyEventExtensionKtTest
This commit is contained in:
parent
d47e826ecc
commit
f17b37e8df
3 changed files with 51 additions and 9 deletions
|
@ -2,13 +2,14 @@ package info.nightscout.core.extensions
|
||||||
|
|
||||||
import info.nightscout.database.entities.TherapyEvent
|
import info.nightscout.database.entities.TherapyEvent
|
||||||
import info.nightscout.interfaces.GlucoseUnit
|
import info.nightscout.interfaces.GlucoseUnit
|
||||||
|
import info.nightscout.shared.utils.DateUtil
|
||||||
|
|
||||||
fun TherapyEvent.isOlderThan(hours: Double): Boolean {
|
fun TherapyEvent.isOlderThan(hours: Double, dateUtil: DateUtil): Boolean {
|
||||||
return getHoursFromStart() > hours
|
return getHoursFromStart(dateUtil) > hours
|
||||||
}
|
}
|
||||||
|
|
||||||
fun TherapyEvent.getHoursFromStart(): Double {
|
fun TherapyEvent.getHoursFromStart(dateUtil: DateUtil): Double {
|
||||||
return (System.currentTimeMillis() - timestamp) / (60 * 60 * 1000.0)
|
return (dateUtil.now() - timestamp) / (60 * 60 * 1000.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun TherapyEvent.GlucoseUnit.Companion.fromConstant(units: GlucoseUnit): TherapyEvent.GlucoseUnit =
|
fun TherapyEvent.GlucoseUnit.Companion.fromConstant(units: GlucoseUnit): TherapyEvent.GlucoseUnit =
|
||||||
|
|
|
@ -5,11 +5,13 @@ import info.nightscout.core.extensions.isOlderThan
|
||||||
import info.nightscout.database.entities.TherapyEvent
|
import info.nightscout.database.entities.TherapyEvent
|
||||||
import info.nightscout.interfaces.pump.WarnColors
|
import info.nightscout.interfaces.pump.WarnColors
|
||||||
import info.nightscout.shared.interfaces.ResourceHelper
|
import info.nightscout.shared.interfaces.ResourceHelper
|
||||||
|
import info.nightscout.shared.utils.DateUtil
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
@Singleton
|
@Singleton class WarnColorsImpl @Inject constructor(
|
||||||
class WarnColorsImpl @Inject constructor(val rh: ResourceHelper): WarnColors {
|
private val rh: ResourceHelper, private val dateUtil: DateUtil
|
||||||
|
) : WarnColors {
|
||||||
|
|
||||||
override fun setColor(view: TextView?, value: Double, warnLevel: Double, urgentLevel: Double) {
|
override fun setColor(view: TextView?, value: Double, warnLevel: Double, urgentLevel: Double) {
|
||||||
view?.setTextColor(
|
view?.setTextColor(
|
||||||
|
@ -39,9 +41,9 @@ class WarnColorsImpl @Inject constructor(val rh: ResourceHelper): WarnColors {
|
||||||
view?.setTextColor(
|
view?.setTextColor(
|
||||||
rh.gac(
|
rh.gac(
|
||||||
view.context, when {
|
view.context, when {
|
||||||
therapyEvent.isOlderThan(urgentThreshold) -> info.nightscout.core.ui.R.attr.lowColor
|
therapyEvent.isOlderThan(urgentThreshold, dateUtil) -> info.nightscout.core.ui.R.attr.lowColor
|
||||||
therapyEvent.isOlderThan(warnThreshold) -> info.nightscout.core.ui.R.attr.highColor
|
therapyEvent.isOlderThan(warnThreshold, dateUtil) -> info.nightscout.core.ui.R.attr.highColor
|
||||||
else -> info.nightscout.core.ui.R.attr.defaultTextColor
|
else -> info.nightscout.core.ui.R.attr.defaultTextColor
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
package info.nightscout.core.extensions
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.TestBaseWithProfile
|
||||||
|
import info.nightscout.database.entities.TherapyEvent
|
||||||
|
import info.nightscout.database.entities.embedments.InterfaceIDs
|
||||||
|
import info.nightscout.shared.utils.T
|
||||||
|
import org.junit.jupiter.api.Assertions
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
import org.mockito.Mockito
|
||||||
|
|
||||||
|
class TherapyEventExtensionKtTest : TestBaseWithProfile() {
|
||||||
|
|
||||||
|
private val now = 1000000L
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun isOlderThan() {
|
||||||
|
val therapyEvent = TherapyEvent(
|
||||||
|
timestamp = now,
|
||||||
|
isValid = true,
|
||||||
|
type = TherapyEvent.Type.ANNOUNCEMENT,
|
||||||
|
note = "c",
|
||||||
|
enteredBy = "dddd",
|
||||||
|
glucose = 101.0,
|
||||||
|
glucoseType = TherapyEvent.MeterType.FINGER,
|
||||||
|
glucoseUnit = TherapyEvent.GlucoseUnit.MGDL,
|
||||||
|
duration = 3600000,
|
||||||
|
interfaceIDs_backing = InterfaceIDs(
|
||||||
|
nightscoutId = "nightscoutId",
|
||||||
|
pumpId = 11000,
|
||||||
|
pumpType = InterfaceIDs.PumpType.DANA_I,
|
||||||
|
pumpSerial = "b"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
Mockito.`when`(dateUtil.now()).thenReturn(now + T.mins(30).msecs())
|
||||||
|
Assertions.assertFalse(therapyEvent.isOlderThan(1.0, dateUtil))
|
||||||
|
Mockito.`when`(dateUtil.now()).thenReturn(now + T.hours(2).msecs())
|
||||||
|
Assertions.assertTrue(therapyEvent.isOlderThan(1.0, dateUtil))
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue