:plugins:support

This commit is contained in:
Milos Kozak 2022-11-27 09:53:19 +01:00
parent 450494fb4c
commit 8b7ceabaf3
16 changed files with 157 additions and 106 deletions

View file

@ -196,13 +196,6 @@
<string name="target_short">TARG</string> <string name="target_short">TARG</string>
<string name="basal_short">BAS</string> <string name="basal_short">BAS</string>
<!-- BG Quality -->
<string name="bg_quality" translatable="false">BG Quality</string>
<string name="recalculated_data_used">Recalculated data used</string>
<string name="bg_too_close">BG too close:\n%1$s\n%2$s</string>
<string name="a11y_bg_quality_recalculated">recalculated</string>
<string name="a11y_bg_quality_doubles">double entries</string>
<!-- Objectives --> <!-- Objectives -->
<string name="key_objectives_bg_is_available_in_ns" translatable="false">ObjectivesbgIsAvailableInNS</string> <string name="key_objectives_bg_is_available_in_ns" translatable="false">ObjectivesbgIsAvailableInNS</string>
<string name="key_objectives_pump_status_is_available_in_ns" translatable="false">ObjectivespumpStatusIsAvailableInNS</string> <string name="key_objectives_pump_status_is_available_in_ns" translatable="false">ObjectivespumpStatusIsAvailableInNS</string>

View file

@ -1,30 +0,0 @@
package info.nightscout.plugins.constraints.signatureVerifier
import android.content.Context
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBase
import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.rx.bus.RxBus
import info.nightscout.shared.sharedPreferences.SP
import org.junit.Assert
import org.junit.Test
import org.mockito.Mock
class SignatureVerifierPluginTest : TestBase() {
@Mock lateinit var rh: ResourceHelper
@Mock lateinit var sp: SP
@Mock lateinit var context: Context
private val rxBus = RxBus(aapsSchedulers, aapsLogger)
val injector = HasAndroidInjector { AndroidInjector { } }
@Test
fun singleCharUnMapTest() {
val plugin = info.nightscout.plugins.constraints.signatureVerifier.SignatureVerifierPlugin(injector, aapsLogger, rh, sp, rxBus, context)
val key = "2ΙšÄΠΒϨÒÇeЄtЄЗž-*Ж*ZcHijЊÄœ<|x\"Ε"
val unmapped = plugin.singleCharUnMap(key)
Assert.assertEquals("32:99:61:C4:A0:92:E8:D2:C7:65:04:74:04:17:7E:2D:2A:16:2A:5A:63:48:69:6A:0A:C4:53:3C:7C:78:22:95", unmapped)
}
}

View file

@ -20,6 +20,7 @@ dependencies {
implementation project(':core:interfaces') implementation project(':core:interfaces')
implementation project(':core:ui') implementation project(':core:ui')
implementation project(':core:utils') implementation project(':core:utils')
implementation project(':database:entities')
// Phone checker // Phone checker
api 'com.scottyab:rootbeer-lib:0.1.0' api 'com.scottyab:rootbeer-lib:0.1.0'

View file

@ -8,7 +8,7 @@ import info.nightscout.interfaces.iob.IobCobCalculator
import info.nightscout.interfaces.plugin.PluginBase import info.nightscout.interfaces.plugin.PluginBase
import info.nightscout.interfaces.plugin.PluginDescription import info.nightscout.interfaces.plugin.PluginDescription
import info.nightscout.interfaces.plugin.PluginType import info.nightscout.interfaces.plugin.PluginType
import info.nightscout.plugins.R import info.nightscout.plugins.support.R
import info.nightscout.rx.AapsSchedulers import info.nightscout.rx.AapsSchedulers
import info.nightscout.rx.bus.RxBus import info.nightscout.rx.bus.RxBus
import info.nightscout.rx.events.EventBucketedDataCreated import info.nightscout.rx.events.EventBucketedDataCreated
@ -77,8 +77,7 @@ class BgQualityCheckPlugin @Inject constructor(
else else
maxIob maxIob
@Suppress("CascadeIf") @Suppress("CascadeIf") fun processBgData() {
fun processBgData() {
val readings = iobCobCalculator.ads.getBgReadingsDataTableCopy() val readings = iobCobCalculator.ads.getBgReadingsDataTableCopy()
for (i in readings.indices) for (i in readings.indices)
// Deltas are calculated from last ~50 min. Detect RED state only on this interval // Deltas are calculated from last ~50 min. Detect RED state only on this interval

View file

@ -79,13 +79,13 @@ class DstHelperPlugin @Inject constructor(
return value return value
} }
private fun wasDST(now: Calendar): Boolean { fun wasDST(now: Calendar): Boolean {
val ago = now.clone() as Calendar val ago = now.clone() as Calendar
ago.add(Calendar.HOUR, DISABLE_TIME_FRAME_HOURS) ago.add(Calendar.HOUR, DISABLE_TIME_FRAME_HOURS)
return now[Calendar.DST_OFFSET] != ago[Calendar.DST_OFFSET] return now[Calendar.DST_OFFSET] != ago[Calendar.DST_OFFSET]
} }
private fun willBeDST(now: Calendar): Boolean { fun willBeDST(now: Calendar): Boolean {
val ago = now.clone() as Calendar val ago = now.clone() as Calendar
ago.add(Calendar.HOUR, WARN_PRIOR_TIME_FRAME_HOURS) ago.add(Calendar.HOUR, WARN_PRIOR_TIME_FRAME_HOURS)
return now[Calendar.DST_OFFSET] != ago[Calendar.DST_OFFSET] return now[Calendar.DST_OFFSET] != ago[Calendar.DST_OFFSET]

View file

@ -168,18 +168,6 @@ class SignatureVerifierPlugin @Inject constructor(
return sb.toString() return sb.toString()
} }
/*
fun singleCharUnMap(shortHash: String): String {
val array = ByteArray(shortHash.length)
val sb = StringBuilder()
for (i in array.indices) {
if (i != 0) sb.append(":")
sb.append(String.format("%02X", 0xFF and map[map.indexOf(shortHash[i])].code))
}
return sb.toString()
}
*/
private fun shouldDownloadCerts(): Boolean { private fun shouldDownloadCerts(): Boolean {
return System.currentTimeMillis() - sp.getLong(R.string.key_last_revoked_certs_check, 0L) >= UPDATE_INTERVAL return System.currentTimeMillis() - sp.getLong(R.string.key_last_revoked_certs_check, 0L) >= UPDATE_INTERVAL
} }

View file

@ -33,4 +33,11 @@
<!-- Signature verifier --> <!-- Signature verifier -->
<string name="signature_verifier" translatable="false">Signature verifier</string> <string name="signature_verifier" translatable="false">Signature verifier</string>
<!-- BG Quality -->
<string name="bg_quality" translatable="false">BG Quality</string>
<string name="recalculated_data_used">Recalculated data used</string>
<string name="bg_too_close">BG too close:\n%1$s\n%2$s</string>
<string name="a11y_bg_quality_recalculated">recalculated</string>
<string name="a11y_bg_quality_doubles">double entries</string>
</resources> </resources>

View file

@ -0,0 +1,39 @@
package info.nightscout.androidaps
import info.nightscout.rx.AapsSchedulers
import info.nightscout.rx.TestAapsSchedulers
import info.nightscout.rx.logging.AAPSLoggerTest
import org.junit.Before
import org.junit.Rule
import org.mockito.Mockito
import org.mockito.junit.MockitoJUnit
import org.mockito.junit.MockitoRule
import java.util.Locale
open class TestBase {
val aapsLogger = AAPSLoggerTest()
val aapsSchedulers: AapsSchedulers = TestAapsSchedulers()
// Add a JUnit rule that will setup the @Mock annotated vars and log.
// Another possibility would be to add `MockitoAnnotations.initMocks(this) to the setup method.
@get:Rule
val mockitoRule: MockitoRule = MockitoJUnit.rule()
@Before
fun setupLocale() {
Locale.setDefault(Locale.ENGLISH)
System.setProperty("disableFirebase", "true")
}
// Workaround for Kotlin nullability.
// https://medium.com/@elye.project/befriending-kotlin-and-mockito-1c2e7b0ef791
// https://stackoverflow.com/questions/30305217/is-it-possible-to-use-mockito-in-kotlin
fun <T> anyObject(): T {
Mockito.any<T>()
return uninitialized()
}
@Suppress("Unchecked_Cast")
fun <T> uninitialized(): T = null as T
}

View file

@ -3,12 +3,12 @@ package info.nightscout.plugins.constraints.bgQualityCheck
import dagger.android.AndroidInjector import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBase import info.nightscout.androidaps.TestBase
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensDataStoreObject
import info.nightscout.core.utils.fabric.FabricPrivacy import info.nightscout.core.utils.fabric.FabricPrivacy
import info.nightscout.database.entities.GlucoseValue import info.nightscout.database.entities.GlucoseValue
import info.nightscout.interfaces.aps.AutosensDataStore
import info.nightscout.interfaces.constraints.Constraint import info.nightscout.interfaces.constraints.Constraint
import info.nightscout.interfaces.iob.IobCobCalculator import info.nightscout.interfaces.iob.IobCobCalculator
import info.nightscout.plugins.R import info.nightscout.plugins.support.R
import info.nightscout.rx.bus.RxBus import info.nightscout.rx.bus.RxBus
import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.utils.DateUtil import info.nightscout.shared.utils.DateUtil
@ -17,7 +17,7 @@ import org.junit.Assert
import org.junit.Before import org.junit.Before
import org.junit.Test import org.junit.Test
import org.mockito.Mock import org.mockito.Mock
import org.mockito.Mockito import org.mockito.Mockito.`when`
class BgQualityCheckPluginTest : TestBase() { class BgQualityCheckPluginTest : TestBase() {
@ -25,29 +25,40 @@ class BgQualityCheckPluginTest : TestBase() {
@Mock lateinit var iobCobCalculator: IobCobCalculator @Mock lateinit var iobCobCalculator: IobCobCalculator
@Mock lateinit var fabricPrivacy: FabricPrivacy @Mock lateinit var fabricPrivacy: FabricPrivacy
@Mock lateinit var dateUtil: DateUtil @Mock lateinit var dateUtil: DateUtil
@Mock lateinit var autosensDataStore: AutosensDataStore
private lateinit var plugin: BgQualityCheckPlugin private lateinit var plugin: BgQualityCheckPlugin
val injector = HasAndroidInjector { AndroidInjector { } } val injector = HasAndroidInjector { AndroidInjector { } }
private val autosensDataStore = AutosensDataStoreObject() //private val autosensDataStore = AutosensDataStoreObject()
@Before @Before
fun mock() { fun mock() {
plugin = BgQualityCheckPlugin(injector, aapsLogger, rh, RxBus(aapsSchedulers, aapsLogger), iobCobCalculator, aapsSchedulers, fabricPrivacy, dateUtil) plugin =
Mockito.`when`(iobCobCalculator.ads).thenReturn(autosensDataStore) BgQualityCheckPlugin(
injector,
aapsLogger,
rh,
RxBus(aapsSchedulers, aapsLogger),
iobCobCalculator,
aapsSchedulers,
fabricPrivacy,
dateUtil
)
`when`(iobCobCalculator.ads).thenReturn(autosensDataStore)
} }
@Test @Test
fun runTest() { fun runTest() {
autosensDataStore.lastUsed5minCalculation = null `when`(autosensDataStore.lastUsed5minCalculation).thenReturn(null)
plugin.processBgData() plugin.processBgData()
Assert.assertEquals(BgQualityCheckPlugin.State.UNKNOWN, plugin.state) Assert.assertEquals(BgQualityCheckPlugin.State.UNKNOWN, plugin.state)
Assert.assertEquals(0, plugin.icon()) Assert.assertEquals(0, plugin.icon())
autosensDataStore.lastUsed5minCalculation = true `when`(autosensDataStore.lastUsed5minCalculation).thenReturn(true)
plugin.processBgData() plugin.processBgData()
Assert.assertEquals(BgQualityCheckPlugin.State.FIVE_MIN_DATA, plugin.state) Assert.assertEquals(BgQualityCheckPlugin.State.FIVE_MIN_DATA, plugin.state)
Assert.assertEquals(0, plugin.icon()) Assert.assertEquals(0, plugin.icon())
autosensDataStore.lastUsed5minCalculation = false `when`(autosensDataStore.lastUsed5minCalculation).thenReturn(false)
plugin.processBgData() plugin.processBgData()
Assert.assertEquals(BgQualityCheckPlugin.State.RECALCULATED, plugin.state) Assert.assertEquals(BgQualityCheckPlugin.State.RECALCULATED, plugin.state)
Assert.assertEquals(R.drawable.ic_baseline_warning_24_yellow, plugin.icon()) Assert.assertEquals(R.drawable.ic_baseline_warning_24_yellow, plugin.icon())
@ -57,12 +68,12 @@ class BgQualityCheckPluginTest : TestBase() {
superData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = T.mins(15).msecs(), sourceSensor = GlucoseValue.SourceSensor.UNKNOWN, trendArrow = GlucoseValue.TrendArrow.FLAT)) superData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = T.mins(15).msecs(), sourceSensor = GlucoseValue.SourceSensor.UNKNOWN, trendArrow = GlucoseValue.TrendArrow.FLAT))
superData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = T.mins(10).msecs(), sourceSensor = GlucoseValue.SourceSensor.UNKNOWN, trendArrow = GlucoseValue.TrendArrow.FLAT)) superData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = T.mins(10).msecs(), sourceSensor = GlucoseValue.SourceSensor.UNKNOWN, trendArrow = GlucoseValue.TrendArrow.FLAT))
superData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = T.mins(5).msecs(), sourceSensor = GlucoseValue.SourceSensor.UNKNOWN, trendArrow = GlucoseValue.TrendArrow.FLAT)) superData.add(GlucoseValue(raw = 0.0, noise = 0.0, value = 100.0, timestamp = T.mins(5).msecs(), sourceSensor = GlucoseValue.SourceSensor.UNKNOWN, trendArrow = GlucoseValue.TrendArrow.FLAT))
autosensDataStore.bgReadings = superData `when`(autosensDataStore.getBgReadingsDataTableCopy()).thenReturn(superData)
autosensDataStore.lastUsed5minCalculation = true `when`(autosensDataStore.lastUsed5minCalculation).thenReturn(true)
plugin.processBgData() plugin.processBgData()
Assert.assertEquals(BgQualityCheckPlugin.State.FIVE_MIN_DATA, plugin.state) Assert.assertEquals(BgQualityCheckPlugin.State.FIVE_MIN_DATA, plugin.state)
autosensDataStore.lastUsed5minCalculation = false `when`(autosensDataStore.lastUsed5minCalculation).thenReturn(false)
plugin.processBgData() plugin.processBgData()
Assert.assertEquals(BgQualityCheckPlugin.State.RECALCULATED, plugin.state) Assert.assertEquals(BgQualityCheckPlugin.State.RECALCULATED, plugin.state)
@ -117,9 +128,9 @@ class BgQualityCheckPluginTest : TestBase() {
trendArrow = GlucoseValue.TrendArrow.FLAT trendArrow = GlucoseValue.TrendArrow.FLAT
) )
) )
autosensDataStore.bgReadings = duplicatedData `when`(autosensDataStore.getBgReadingsDataTableCopy()).thenReturn(duplicatedData)
autosensDataStore.lastUsed5minCalculation = true `when`(autosensDataStore.lastUsed5minCalculation).thenReturn(true)
plugin.processBgData() plugin.processBgData()
Assert.assertEquals(BgQualityCheckPlugin.State.DOUBLED, plugin.state) Assert.assertEquals(BgQualityCheckPlugin.State.DOUBLED, plugin.state)
Assert.assertEquals(R.drawable.ic_baseline_warning_24_red, plugin.icon()) Assert.assertEquals(R.drawable.ic_baseline_warning_24_red, plugin.icon())
@ -175,9 +186,9 @@ class BgQualityCheckPluginTest : TestBase() {
trendArrow = GlucoseValue.TrendArrow.FLAT trendArrow = GlucoseValue.TrendArrow.FLAT
) )
) )
autosensDataStore.bgReadings = identicalData `when`(autosensDataStore.getBgReadingsDataTableCopy()).thenReturn(identicalData)
autosensDataStore.lastUsed5minCalculation = false `when`(autosensDataStore.lastUsed5minCalculation).thenReturn(false)
plugin.processBgData() plugin.processBgData()
Assert.assertEquals(BgQualityCheckPlugin.State.DOUBLED, plugin.state) Assert.assertEquals(BgQualityCheckPlugin.State.DOUBLED, plugin.state)
} }

View file

@ -24,13 +24,13 @@ class DstHelperPluginTest : TestBase() {
@Mock lateinit var activePlugin: ActivePlugin @Mock lateinit var activePlugin: ActivePlugin
@Mock lateinit var loop: Loop @Mock lateinit var loop: Loop
private lateinit var plugin: info.nightscout.plugins.constraints.dstHelper.DstHelperPlugin private lateinit var plugin: DstHelperPlugin
val injector = HasAndroidInjector { AndroidInjector { } } private val injector = HasAndroidInjector { AndroidInjector { } }
@Before @Before
fun mock() { fun mock() {
plugin = info.nightscout.plugins.constraints.dstHelper.DstHelperPlugin(injector, aapsLogger, rh, sp, activePlugin, loop) plugin = DstHelperPlugin(injector, aapsLogger, rh, sp, activePlugin, loop)
} }
@Test @Test

View file

@ -0,0 +1,42 @@
package info.nightscout.plugins.constraints.signatureVerifier
import android.content.Context
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBase
import info.nightscout.interfaces.ui.ActivityNames
import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.sharedPreferences.SP
import org.junit.Assert
import org.junit.Test
import org.mockito.Mock
class SignatureVerifierPluginTest : TestBase() {
@Mock lateinit var rh: ResourceHelper
@Mock lateinit var sp: SP
@Mock lateinit var context: Context
@Mock lateinit var activityNames: ActivityNames
val injector = HasAndroidInjector { AndroidInjector { } }
fun singleCharUnMap(shortHash: String): String {
val array = ByteArray(shortHash.length)
val sb = StringBuilder()
for (i in array.indices) {
if (i != 0) sb.append(":")
sb.append(String.format("%02X", 0xFF and map[map.indexOf(shortHash[i])].code))
}
return sb.toString()
}
var map =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!\"§$%&/()=?,.-;:_<>|°^`´\\@€*'#+~{}[]¿¡áéíóúàèìòùöäü`ÁÉÍÓÚÀÈÌÒÙÖÄÜßÆÇÊËÎÏԌ۟æçêëîïôœûÿĆČĐŠŽćđšžñΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡ\u03A2ΣΤΥΦΧΨΩαβγδεζηθικλμνξοπρςστυφχψωϨϩϪϫϬϭϮϯϰϱϲϳϴϵ϶ϷϸϹϺϻϼϽϾϿЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗ"
@Test
fun singleCharUnMapTest() {
val key = "2ΙšÄΠΒϨÒÇeЄtЄЗž-*Ж*ZcHijЊÄœ<|x\"Ε"
val unmapped = singleCharUnMap(key)
Assert.assertEquals("32:99:61:C4:A0:92:E8:D2:C7:65:04:74:04:17:7E:2D:2A:16:2A:5A:63:48:69:6A:0A:C4:53:3C:7C:78:22:95", unmapped)
}
}

View file

@ -1,12 +1,13 @@
package info.nightscout.androidaps.plugins.contraints.versionChecker package info.nightscout.plugins.constraints.signatureVerifier
import dagger.Lazy import dagger.Lazy
import info.nightscout.androidaps.TestBase import info.nightscout.androidaps.TestBase
import info.nightscout.core.utils.receivers.ReceiverStatusStore import info.nightscout.core.utils.receivers.ReceiverStatusStore
import info.nightscout.interfaces.versionChecker.VersionCheckerUtils
import info.nightscout.core.versionChecker.numericVersionPart
import info.nightscout.interfaces.Config import info.nightscout.interfaces.Config
import info.nightscout.rx.bus.RxBus import info.nightscout.interfaces.ui.ActivityNames
import info.nightscout.interfaces.versionChecker.VersionCheckerUtils
import info.nightscout.plugins.constraints.versionChecker.VersionCheckerUtilsImpl
import info.nightscout.plugins.constraints.versionChecker.numericVersionPart
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.shared.utils.DateUtil import info.nightscout.shared.utils.DateUtil
@ -30,10 +31,10 @@ import org.mockito.Mockito.`when`
@Mock lateinit var receiverStatusStore: ReceiverStatusStore @Mock lateinit var receiverStatusStore: ReceiverStatusStore
@Mock lateinit var config: Lazy<Config> @Mock lateinit var config: Lazy<Config>
@Mock lateinit var dateUtil: DateUtil @Mock lateinit var dateUtil: DateUtil
@Mock lateinit var rxBus: RxBus @Mock lateinit var activityNames: ActivityNames
@Before fun setup() { @Before fun setup() {
versionCheckerUtils = VersionCheckerUtils(aapsLogger, sp, rh, rxBus, config, receiverStatusStore, dateUtil) versionCheckerUtils = VersionCheckerUtilsImpl(aapsLogger, sp, rh, config, receiverStatusStore, dateUtil, activityNames)
} }
@Test @Test
@ -169,49 +170,49 @@ import org.mockito.Mockito.`when`
@Test @Test
fun `should find update1`() { fun `should find update1`() {
versionCheckerUtils.compareWithCurrentVersion(newVersion = "2.2.3", currentVersion = "2.2.1") versionCheckerUtils.compareWithCurrentVersion(newVersion = "2.2.3", currentVersion = "2.2.1")
verify(rxBus, times(1)).send(anyObject()) verify(activityNames, times(1)).addNotification(anyInt(), anyString(), anyInt())
} }
@Test @Test
fun `should find update2`() { fun `should find update2`() {
versionCheckerUtils.compareWithCurrentVersion(newVersion = "2.2.3", currentVersion = "2.2.1-dev") versionCheckerUtils.compareWithCurrentVersion(newVersion = "2.2.3", currentVersion = "2.2.1-dev")
verify(rxBus, times(1)).send(anyObject()) verify(activityNames, times(1)).addNotification(anyInt(), anyString(), anyInt())
} }
@Test @Test
fun `should find update3`() { fun `should find update3`() {
versionCheckerUtils.compareWithCurrentVersion(newVersion = "2.2.3", currentVersion = "2.1") versionCheckerUtils.compareWithCurrentVersion(newVersion = "2.2.3", currentVersion = "2.1")
verify(rxBus, times(1)).send(anyObject()) verify(activityNames, times(1)).addNotification(anyInt(), anyString(), anyInt())
} }
@Test @Test
fun `should find update4`() { fun `should find update4`() {
versionCheckerUtils.compareWithCurrentVersion(newVersion = "2.2", currentVersion = "2.1.1") versionCheckerUtils.compareWithCurrentVersion(newVersion = "2.2", currentVersion = "2.1.1")
verify(rxBus, times(1)).send(anyObject()) verify(activityNames, times(1)).addNotification(anyInt(), anyString(), anyInt())
} }
@Test @Test
fun `should find update5`() { fun `should find update5`() {
versionCheckerUtils.compareWithCurrentVersion(newVersion = "2.2.1", currentVersion = "2.2-dev") versionCheckerUtils.compareWithCurrentVersion(newVersion = "2.2.1", currentVersion = "2.2-dev")
verify(rxBus, times(1)).send(anyObject()) verify(activityNames, times(1)).addNotification(anyInt(), anyString(), anyInt())
} }
@Test @Test
fun `should find update6`() { fun `should find update6`() {
versionCheckerUtils.compareWithCurrentVersion(newVersion = "2.2.1", currentVersion = "2.2dev") versionCheckerUtils.compareWithCurrentVersion(newVersion = "2.2.1", currentVersion = "2.2dev")
verify(rxBus, times(1)).send(anyObject()) verify(activityNames, times(1)).addNotification(anyInt(), anyString(), anyInt())
} }
@Test @Test
fun `should not find update on fourth version digit`() { fun `should not find update on fourth version digit`() {
versionCheckerUtils.compareWithCurrentVersion(newVersion = "2.5.0", currentVersion = "2.5.0.1") versionCheckerUtils.compareWithCurrentVersion(newVersion = "2.5.0", currentVersion = "2.5.0.1")
verify(rxBus, times(0)).send(anyObject()) verify(activityNames, times(0)).addNotification(anyInt(), anyString(), anyInt())
} }
@Test @Test
fun `should not find update on personal version with same number`() { fun `should not find update on personal version with same number`() {
versionCheckerUtils.compareWithCurrentVersion(newVersion = "2.5.0", currentVersion = "2.5.0-myversion") versionCheckerUtils.compareWithCurrentVersion(newVersion = "2.5.0", currentVersion = "2.5.0-myversion")
verify(rxBus, times(0)).send(anyObject()) verify(activityNames, times(0)).addNotification(anyInt(), anyString(), anyInt())
} }
@Test @Test
@ -225,7 +226,7 @@ import org.mockito.Mockito.`when`
""".trimMargin() """.trimMargin()
versionCheckerUtils.compareWithCurrentVersion(versionCheckerUtils.findVersion(buildGradle), currentVersion = "2.2.2") versionCheckerUtils.compareWithCurrentVersion(versionCheckerUtils.findVersion(buildGradle), currentVersion = "2.2.2")
verify(rxBus, times(0)).send(anyObject()) verify(activityNames, times(0)).addNotification(anyInt(), anyString(), anyInt())
} }
@Test @Test
fun `find higher version`() { fun `find higher version`() {
@ -237,7 +238,7 @@ import org.mockito.Mockito.`when`
| appName = "Aaoeu" | appName = "Aaoeu"
""".trimMargin() """.trimMargin()
versionCheckerUtils.compareWithCurrentVersion(versionCheckerUtils.findVersion(buildGradle), currentVersion = "2.2.2") versionCheckerUtils.compareWithCurrentVersion(versionCheckerUtils.findVersion(buildGradle), currentVersion = "2.2.2")
verify(rxBus, times(1)).send(anyObject()) verify(activityNames, times(1)).addNotification(anyInt(), anyString(), anyInt())
} }
@Test @Test
@ -250,7 +251,7 @@ import org.mockito.Mockito.`when`
| appName = "Aaoeu" | appName = "Aaoeu"
""".trimMargin() """.trimMargin()
versionCheckerUtils.compareWithCurrentVersion(versionCheckerUtils.findVersion(buildGradle), currentVersion = "2.2.2") versionCheckerUtils.compareWithCurrentVersion(versionCheckerUtils.findVersion(buildGradle), currentVersion = "2.2.2")
verify(rxBus, times(1)).send(anyObject()) verify(activityNames, times(1)).addNotification(anyInt(), anyString(), anyInt())
} }
@Test @Test
@ -263,7 +264,7 @@ import org.mockito.Mockito.`when`
| appName = "Aaoeu" | appName = "Aaoeu"
""".trimMargin() """.trimMargin()
versionCheckerUtils.compareWithCurrentVersion(versionCheckerUtils.findVersion(buildGradle), currentVersion = "3.0-RC04") versionCheckerUtils.compareWithCurrentVersion(versionCheckerUtils.findVersion(buildGradle), currentVersion = "3.0-RC04")
verify(rxBus, times(1)).send(anyObject()) verify(activityNames, times(1)).addNotification(anyInt(), anyString(), anyInt())
} }
@Test @Test
@ -276,7 +277,7 @@ import org.mockito.Mockito.`when`
| appName = "Aaoeu" | appName = "Aaoeu"
""".trimMargin() """.trimMargin()
versionCheckerUtils.compareWithCurrentVersion(versionCheckerUtils.findVersion(buildGradle), currentVersion = "3.0RC04") versionCheckerUtils.compareWithCurrentVersion(versionCheckerUtils.findVersion(buildGradle), currentVersion = "3.0RC04")
verify(rxBus, times(1)).send(anyObject()) verify(activityNames, times(1)).addNotification(anyInt(), anyString(), anyInt())
} }
@Test @Test
@ -289,7 +290,7 @@ import org.mockito.Mockito.`when`
| appName = "Aaoeu" | appName = "Aaoeu"
""".trimMargin() """.trimMargin()
versionCheckerUtils.compareWithCurrentVersion(versionCheckerUtils.findVersion(buildGradle), currentVersion = "3.RC04") versionCheckerUtils.compareWithCurrentVersion(versionCheckerUtils.findVersion(buildGradle), currentVersion = "3.RC04")
verify(rxBus, times(1)).send(anyObject()) verify(activityNames, times(1)).addNotification(anyInt(), anyString(), anyInt())
} }
@Test @Test
@ -302,7 +303,7 @@ import org.mockito.Mockito.`when`
| appName = "Aaoeu" | appName = "Aaoeu"
""".trimMargin() """.trimMargin()
versionCheckerUtils.compareWithCurrentVersion(versionCheckerUtils.findVersion(buildGradle), currentVersion = "3.0.RC04") versionCheckerUtils.compareWithCurrentVersion(versionCheckerUtils.findVersion(buildGradle), currentVersion = "3.0.RC04")
verify(rxBus, times(1)).send(anyObject()) verify(activityNames, times(1)).addNotification(anyInt(), anyString(), anyInt())
} }
@Test @Test
@ -315,7 +316,7 @@ import org.mockito.Mockito.`when`
| appName = "Aaoeu" | appName = "Aaoeu"
""".trimMargin() """.trimMargin()
versionCheckerUtils.compareWithCurrentVersion(versionCheckerUtils.findVersion(buildGradle), currentVersion = "3.7.9") versionCheckerUtils.compareWithCurrentVersion(versionCheckerUtils.findVersion(buildGradle), currentVersion = "3.7.9")
verify(rxBus, times(1)).send(anyObject()) verify(activityNames, times(1)).addNotification(anyInt(), anyString(), anyInt())
} }
@Test @Test
@ -328,7 +329,7 @@ import org.mockito.Mockito.`when`
| appName = "Aaoeu" | appName = "Aaoeu"
""".trimMargin() """.trimMargin()
versionCheckerUtils.compareWithCurrentVersion(versionCheckerUtils.findVersion(buildGradle), currentVersion = "2.3") versionCheckerUtils.compareWithCurrentVersion(versionCheckerUtils.findVersion(buildGradle), currentVersion = "2.3")
verify(rxBus, times(0)).send(anyObject()) verify(activityNames, times(0)).addNotification(anyInt(), anyString(), anyInt())
} }
@Test @Test
@ -341,7 +342,7 @@ import org.mockito.Mockito.`when`
| appName = "Aaoeu" | appName = "Aaoeu"
""".trimMargin() """.trimMargin()
versionCheckerUtils.compareWithCurrentVersion(versionCheckerUtils.findVersion(buildGradle), currentVersion = "2.3-RC") versionCheckerUtils.compareWithCurrentVersion(versionCheckerUtils.findVersion(buildGradle), currentVersion = "2.3-RC")
verify(rxBus, times(0)).send(anyObject()) verify(activityNames, times(0)).addNotification(anyInt(), anyString(), anyInt())
} }
@Test @Test
@ -354,7 +355,7 @@ import org.mockito.Mockito.`when`
| appName = "Aaoeu" | appName = "Aaoeu"
""".trimMargin() """.trimMargin()
versionCheckerUtils.compareWithCurrentVersion(versionCheckerUtils.findVersion(buildGradle), currentVersion = "2.2-beta1") versionCheckerUtils.compareWithCurrentVersion(versionCheckerUtils.findVersion(buildGradle), currentVersion = "2.2-beta1")
verify(rxBus, times(1)).send(anyObject()) verify(activityNames, times(1)).addNotification(anyInt(), anyString(), anyInt())
} }
@Test @Test
@ -367,7 +368,7 @@ import org.mockito.Mockito.`when`
| appName = "Aaoeu" | appName = "Aaoeu"
""".trimMargin() """.trimMargin()
versionCheckerUtils.compareWithCurrentVersion(versionCheckerUtils.findVersion(buildGradle), currentVersion = "2.2-rc1") versionCheckerUtils.compareWithCurrentVersion(versionCheckerUtils.findVersion(buildGradle), currentVersion = "2.2-rc1")
verify(rxBus, times(1)).send(anyObject()) verify(activityNames, times(1)).addNotification(anyInt(), anyString(), anyInt())
} }
@Before @Before

View file

@ -4,7 +4,7 @@ import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBase import info.nightscout.androidaps.TestBase
import info.nightscout.interfaces.constraints.Constraint import info.nightscout.interfaces.constraints.Constraint
import info.nightscout.rx.bus.RxBus import info.nightscout.interfaces.ui.ActivityNames
import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.interfaces.ResourceHelper
import org.junit.Assert import org.junit.Assert
@ -18,12 +18,12 @@ import org.mockito.Mockito.`when`
class StorageConstraintPluginTest : TestBase() { class StorageConstraintPluginTest : TestBase() {
@Mock lateinit var rh: ResourceHelper @Mock lateinit var rh: ResourceHelper
private val rxBusWrapper = RxBus(aapsSchedulers, aapsLogger) @Mock lateinit var activityNames: ActivityNames
private lateinit var storageConstraintPlugin: info.nightscout.plugins.constraints.storage.StorageConstraintPlugin private lateinit var storageConstraintPlugin: StorageConstraintPlugin
@Before fun prepareMock() { @Before fun prepareMock() {
storageConstraintPlugin = info.nightscout.plugins.constraints.storage.StorageConstraintPlugin({ AndroidInjector { } }, aapsLogger, rh, rxBusWrapper) storageConstraintPlugin = StorageConstraintPlugin({ AndroidInjector { } }, aapsLogger, rh, activityNames)
`when`(rh.gs(anyInt(), anyLong())).thenReturn("") `when`(rh.gs(anyInt(), anyLong())).thenReturn("")
} }
@ -31,15 +31,15 @@ class StorageConstraintPluginTest : TestBase() {
injector: HasAndroidInjector, injector: HasAndroidInjector,
aapsLogger: AAPSLogger, aapsLogger: AAPSLogger,
rh: ResourceHelper, rh: ResourceHelper,
rxBus: RxBus activityNames: ActivityNames
) : info.nightscout.plugins.constraints.storage.StorageConstraintPlugin(injector, aapsLogger, rh, rxBus) { ) : StorageConstraintPlugin(injector, aapsLogger, rh, activityNames) {
var memSize = 150L var memSize = 150L
override fun availableInternalMemorySize(): Long = memSize override fun availableInternalMemorySize(): Long = memSize
} }
@Test fun isLoopInvocationAllowedTest() { @Test fun isLoopInvocationAllowedTest() {
val mocked = MockedStorageConstraintPlugin({ AndroidInjector { } }, aapsLogger, rh, rxBusWrapper) val mocked = MockedStorageConstraintPlugin({ AndroidInjector { } }, aapsLogger, rh, activityNames)
// Set free space under 200(Mb) to disable loop // Set free space under 200(Mb) to disable loop
mocked.memSize = 150L mocked.memSize = 150L
Assert.assertEquals(false, mocked.isClosedLoopAllowed(Constraint(true)).value()) Assert.assertEquals(false, mocked.isClosedLoopAllowed(Constraint(true)).value())