:plugins:support
This commit is contained in:
parent
450494fb4c
commit
8b7ceabaf3
16 changed files with 157 additions and 106 deletions
|
@ -196,13 +196,6 @@
|
|||
<string name="target_short">TARG</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 -->
|
||||
<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>
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
|
@ -20,6 +20,7 @@ dependencies {
|
|||
implementation project(':core:interfaces')
|
||||
implementation project(':core:ui')
|
||||
implementation project(':core:utils')
|
||||
implementation project(':database:entities')
|
||||
|
||||
// Phone checker
|
||||
api 'com.scottyab:rootbeer-lib:0.1.0'
|
||||
|
|
|
@ -8,7 +8,7 @@ import info.nightscout.interfaces.iob.IobCobCalculator
|
|||
import info.nightscout.interfaces.plugin.PluginBase
|
||||
import info.nightscout.interfaces.plugin.PluginDescription
|
||||
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.bus.RxBus
|
||||
import info.nightscout.rx.events.EventBucketedDataCreated
|
||||
|
@ -77,8 +77,7 @@ class BgQualityCheckPlugin @Inject constructor(
|
|||
else
|
||||
maxIob
|
||||
|
||||
@Suppress("CascadeIf")
|
||||
fun processBgData() {
|
||||
@Suppress("CascadeIf") fun processBgData() {
|
||||
val readings = iobCobCalculator.ads.getBgReadingsDataTableCopy()
|
||||
for (i in readings.indices)
|
||||
// Deltas are calculated from last ~50 min. Detect RED state only on this interval
|
|
@ -79,13 +79,13 @@ class DstHelperPlugin @Inject constructor(
|
|||
return value
|
||||
}
|
||||
|
||||
private fun wasDST(now: Calendar): Boolean {
|
||||
fun wasDST(now: Calendar): Boolean {
|
||||
val ago = now.clone() as Calendar
|
||||
ago.add(Calendar.HOUR, DISABLE_TIME_FRAME_HOURS)
|
||||
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
|
||||
ago.add(Calendar.HOUR, WARN_PRIOR_TIME_FRAME_HOURS)
|
||||
return now[Calendar.DST_OFFSET] != ago[Calendar.DST_OFFSET]
|
||||
|
|
|
@ -168,18 +168,6 @@ class SignatureVerifierPlugin @Inject constructor(
|
|||
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 {
|
||||
return System.currentTimeMillis() - sp.getLong(R.string.key_last_revoked_certs_check, 0L) >= UPDATE_INTERVAL
|
||||
}
|
||||
|
|
|
@ -33,4 +33,11 @@
|
|||
<!-- Signature verifier -->
|
||||
<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>
|
|
@ -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
|
||||
}
|
|
@ -3,12 +3,12 @@ package info.nightscout.plugins.constraints.bgQualityCheck
|
|||
import dagger.android.AndroidInjector
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.TestBase
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensDataStoreObject
|
||||
import info.nightscout.core.utils.fabric.FabricPrivacy
|
||||
import info.nightscout.database.entities.GlucoseValue
|
||||
import info.nightscout.interfaces.aps.AutosensDataStore
|
||||
import info.nightscout.interfaces.constraints.Constraint
|
||||
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.shared.interfaces.ResourceHelper
|
||||
import info.nightscout.shared.utils.DateUtil
|
||||
|
@ -17,7 +17,7 @@ import org.junit.Assert
|
|||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.Mockito.`when`
|
||||
|
||||
class BgQualityCheckPluginTest : TestBase() {
|
||||
|
||||
|
@ -25,29 +25,40 @@ class BgQualityCheckPluginTest : TestBase() {
|
|||
@Mock lateinit var iobCobCalculator: IobCobCalculator
|
||||
@Mock lateinit var fabricPrivacy: FabricPrivacy
|
||||
@Mock lateinit var dateUtil: DateUtil
|
||||
@Mock lateinit var autosensDataStore: AutosensDataStore
|
||||
|
||||
private lateinit var plugin: BgQualityCheckPlugin
|
||||
|
||||
val injector = HasAndroidInjector { AndroidInjector { } }
|
||||
private val autosensDataStore = AutosensDataStoreObject()
|
||||
//private val autosensDataStore = AutosensDataStoreObject()
|
||||
|
||||
@Before
|
||||
fun mock() {
|
||||
plugin = BgQualityCheckPlugin(injector, aapsLogger, rh, RxBus(aapsSchedulers, aapsLogger), iobCobCalculator, aapsSchedulers, fabricPrivacy, dateUtil)
|
||||
Mockito.`when`(iobCobCalculator.ads).thenReturn(autosensDataStore)
|
||||
plugin =
|
||||
BgQualityCheckPlugin(
|
||||
injector,
|
||||
aapsLogger,
|
||||
rh,
|
||||
RxBus(aapsSchedulers, aapsLogger),
|
||||
iobCobCalculator,
|
||||
aapsSchedulers,
|
||||
fabricPrivacy,
|
||||
dateUtil
|
||||
)
|
||||
`when`(iobCobCalculator.ads).thenReturn(autosensDataStore)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun runTest() {
|
||||
autosensDataStore.lastUsed5minCalculation = null
|
||||
`when`(autosensDataStore.lastUsed5minCalculation).thenReturn(null)
|
||||
plugin.processBgData()
|
||||
Assert.assertEquals(BgQualityCheckPlugin.State.UNKNOWN, plugin.state)
|
||||
Assert.assertEquals(0, plugin.icon())
|
||||
autosensDataStore.lastUsed5minCalculation = true
|
||||
`when`(autosensDataStore.lastUsed5minCalculation).thenReturn(true)
|
||||
plugin.processBgData()
|
||||
Assert.assertEquals(BgQualityCheckPlugin.State.FIVE_MIN_DATA, plugin.state)
|
||||
Assert.assertEquals(0, plugin.icon())
|
||||
autosensDataStore.lastUsed5minCalculation = false
|
||||
`when`(autosensDataStore.lastUsed5minCalculation).thenReturn(false)
|
||||
plugin.processBgData()
|
||||
Assert.assertEquals(BgQualityCheckPlugin.State.RECALCULATED, plugin.state)
|
||||
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(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))
|
||||
autosensDataStore.bgReadings = superData
|
||||
`when`(autosensDataStore.getBgReadingsDataTableCopy()).thenReturn(superData)
|
||||
|
||||
autosensDataStore.lastUsed5minCalculation = true
|
||||
`when`(autosensDataStore.lastUsed5minCalculation).thenReturn(true)
|
||||
plugin.processBgData()
|
||||
Assert.assertEquals(BgQualityCheckPlugin.State.FIVE_MIN_DATA, plugin.state)
|
||||
autosensDataStore.lastUsed5minCalculation = false
|
||||
`when`(autosensDataStore.lastUsed5minCalculation).thenReturn(false)
|
||||
plugin.processBgData()
|
||||
Assert.assertEquals(BgQualityCheckPlugin.State.RECALCULATED, plugin.state)
|
||||
|
||||
|
@ -117,9 +128,9 @@ class BgQualityCheckPluginTest : TestBase() {
|
|||
trendArrow = GlucoseValue.TrendArrow.FLAT
|
||||
)
|
||||
)
|
||||
autosensDataStore.bgReadings = duplicatedData
|
||||
`when`(autosensDataStore.getBgReadingsDataTableCopy()).thenReturn(duplicatedData)
|
||||
|
||||
autosensDataStore.lastUsed5minCalculation = true
|
||||
`when`(autosensDataStore.lastUsed5minCalculation).thenReturn(true)
|
||||
plugin.processBgData()
|
||||
Assert.assertEquals(BgQualityCheckPlugin.State.DOUBLED, plugin.state)
|
||||
Assert.assertEquals(R.drawable.ic_baseline_warning_24_red, plugin.icon())
|
||||
|
@ -175,9 +186,9 @@ class BgQualityCheckPluginTest : TestBase() {
|
|||
trendArrow = GlucoseValue.TrendArrow.FLAT
|
||||
)
|
||||
)
|
||||
autosensDataStore.bgReadings = identicalData
|
||||
`when`(autosensDataStore.getBgReadingsDataTableCopy()).thenReturn(identicalData)
|
||||
|
||||
autosensDataStore.lastUsed5minCalculation = false
|
||||
`when`(autosensDataStore.lastUsed5minCalculation).thenReturn(false)
|
||||
plugin.processBgData()
|
||||
Assert.assertEquals(BgQualityCheckPlugin.State.DOUBLED, plugin.state)
|
||||
}
|
|
@ -24,13 +24,13 @@ class DstHelperPluginTest : TestBase() {
|
|||
@Mock lateinit var activePlugin: ActivePlugin
|
||||
@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
|
||||
fun mock() {
|
||||
plugin = info.nightscout.plugins.constraints.dstHelper.DstHelperPlugin(injector, aapsLogger, rh, sp, activePlugin, loop)
|
||||
plugin = DstHelperPlugin(injector, aapsLogger, rh, sp, activePlugin, loop)
|
||||
}
|
||||
|
||||
@Test
|
|
@ -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)
|
||||
}
|
||||
}
|
|
@ -1,12 +1,13 @@
|
|||
package info.nightscout.androidaps.plugins.contraints.versionChecker
|
||||
package info.nightscout.plugins.constraints.signatureVerifier
|
||||
|
||||
import dagger.Lazy
|
||||
import info.nightscout.androidaps.TestBase
|
||||
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.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.sharedPreferences.SP
|
||||
import info.nightscout.shared.utils.DateUtil
|
||||
|
@ -30,10 +31,10 @@ import org.mockito.Mockito.`when`
|
|||
@Mock lateinit var receiverStatusStore: ReceiverStatusStore
|
||||
@Mock lateinit var config: Lazy<Config>
|
||||
@Mock lateinit var dateUtil: DateUtil
|
||||
@Mock lateinit var rxBus: RxBus
|
||||
@Mock lateinit var activityNames: ActivityNames
|
||||
|
||||
@Before fun setup() {
|
||||
versionCheckerUtils = VersionCheckerUtils(aapsLogger, sp, rh, rxBus, config, receiverStatusStore, dateUtil)
|
||||
versionCheckerUtils = VersionCheckerUtilsImpl(aapsLogger, sp, rh, config, receiverStatusStore, dateUtil, activityNames)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -169,49 +170,49 @@ import org.mockito.Mockito.`when`
|
|||
@Test
|
||||
fun `should find update1`() {
|
||||
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
|
||||
fun `should find update2`() {
|
||||
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
|
||||
fun `should find update3`() {
|
||||
versionCheckerUtils.compareWithCurrentVersion(newVersion = "2.2.3", currentVersion = "2.1")
|
||||
verify(rxBus, times(1)).send(anyObject())
|
||||
verify(activityNames, times(1)).addNotification(anyInt(), anyString(), anyInt())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should find update4`() {
|
||||
versionCheckerUtils.compareWithCurrentVersion(newVersion = "2.2", currentVersion = "2.1.1")
|
||||
verify(rxBus, times(1)).send(anyObject())
|
||||
verify(activityNames, times(1)).addNotification(anyInt(), anyString(), anyInt())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should find update5`() {
|
||||
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
|
||||
fun `should find update6`() {
|
||||
versionCheckerUtils.compareWithCurrentVersion(newVersion = "2.2.1", currentVersion = "2.2dev")
|
||||
verify(rxBus, times(1)).send(anyObject())
|
||||
verify(activityNames, times(1)).addNotification(anyInt(), anyString(), anyInt())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should not find update on fourth version digit`() {
|
||||
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
|
||||
fun `should not find update on personal version with same number`() {
|
||||
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
|
||||
|
@ -225,7 +226,7 @@ import org.mockito.Mockito.`when`
|
|||
""".trimMargin()
|
||||
versionCheckerUtils.compareWithCurrentVersion(versionCheckerUtils.findVersion(buildGradle), currentVersion = "2.2.2")
|
||||
|
||||
verify(rxBus, times(0)).send(anyObject())
|
||||
verify(activityNames, times(0)).addNotification(anyInt(), anyString(), anyInt())
|
||||
}
|
||||
@Test
|
||||
fun `find higher version`() {
|
||||
|
@ -237,7 +238,7 @@ import org.mockito.Mockito.`when`
|
|||
| appName = "Aaoeu"
|
||||
""".trimMargin()
|
||||
versionCheckerUtils.compareWithCurrentVersion(versionCheckerUtils.findVersion(buildGradle), currentVersion = "2.2.2")
|
||||
verify(rxBus, times(1)).send(anyObject())
|
||||
verify(activityNames, times(1)).addNotification(anyInt(), anyString(), anyInt())
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -250,7 +251,7 @@ import org.mockito.Mockito.`when`
|
|||
| appName = "Aaoeu"
|
||||
""".trimMargin()
|
||||
versionCheckerUtils.compareWithCurrentVersion(versionCheckerUtils.findVersion(buildGradle), currentVersion = "2.2.2")
|
||||
verify(rxBus, times(1)).send(anyObject())
|
||||
verify(activityNames, times(1)).addNotification(anyInt(), anyString(), anyInt())
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -263,7 +264,7 @@ import org.mockito.Mockito.`when`
|
|||
| appName = "Aaoeu"
|
||||
""".trimMargin()
|
||||
versionCheckerUtils.compareWithCurrentVersion(versionCheckerUtils.findVersion(buildGradle), currentVersion = "3.0-RC04")
|
||||
verify(rxBus, times(1)).send(anyObject())
|
||||
verify(activityNames, times(1)).addNotification(anyInt(), anyString(), anyInt())
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -276,7 +277,7 @@ import org.mockito.Mockito.`when`
|
|||
| appName = "Aaoeu"
|
||||
""".trimMargin()
|
||||
versionCheckerUtils.compareWithCurrentVersion(versionCheckerUtils.findVersion(buildGradle), currentVersion = "3.0RC04")
|
||||
verify(rxBus, times(1)).send(anyObject())
|
||||
verify(activityNames, times(1)).addNotification(anyInt(), anyString(), anyInt())
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -289,7 +290,7 @@ import org.mockito.Mockito.`when`
|
|||
| appName = "Aaoeu"
|
||||
""".trimMargin()
|
||||
versionCheckerUtils.compareWithCurrentVersion(versionCheckerUtils.findVersion(buildGradle), currentVersion = "3.RC04")
|
||||
verify(rxBus, times(1)).send(anyObject())
|
||||
verify(activityNames, times(1)).addNotification(anyInt(), anyString(), anyInt())
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -302,7 +303,7 @@ import org.mockito.Mockito.`when`
|
|||
| appName = "Aaoeu"
|
||||
""".trimMargin()
|
||||
versionCheckerUtils.compareWithCurrentVersion(versionCheckerUtils.findVersion(buildGradle), currentVersion = "3.0.RC04")
|
||||
verify(rxBus, times(1)).send(anyObject())
|
||||
verify(activityNames, times(1)).addNotification(anyInt(), anyString(), anyInt())
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -315,7 +316,7 @@ import org.mockito.Mockito.`when`
|
|||
| appName = "Aaoeu"
|
||||
""".trimMargin()
|
||||
versionCheckerUtils.compareWithCurrentVersion(versionCheckerUtils.findVersion(buildGradle), currentVersion = "3.7.9")
|
||||
verify(rxBus, times(1)).send(anyObject())
|
||||
verify(activityNames, times(1)).addNotification(anyInt(), anyString(), anyInt())
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -328,7 +329,7 @@ import org.mockito.Mockito.`when`
|
|||
| appName = "Aaoeu"
|
||||
""".trimMargin()
|
||||
versionCheckerUtils.compareWithCurrentVersion(versionCheckerUtils.findVersion(buildGradle), currentVersion = "2.3")
|
||||
verify(rxBus, times(0)).send(anyObject())
|
||||
verify(activityNames, times(0)).addNotification(anyInt(), anyString(), anyInt())
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -341,7 +342,7 @@ import org.mockito.Mockito.`when`
|
|||
| appName = "Aaoeu"
|
||||
""".trimMargin()
|
||||
versionCheckerUtils.compareWithCurrentVersion(versionCheckerUtils.findVersion(buildGradle), currentVersion = "2.3-RC")
|
||||
verify(rxBus, times(0)).send(anyObject())
|
||||
verify(activityNames, times(0)).addNotification(anyInt(), anyString(), anyInt())
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -354,7 +355,7 @@ import org.mockito.Mockito.`when`
|
|||
| appName = "Aaoeu"
|
||||
""".trimMargin()
|
||||
versionCheckerUtils.compareWithCurrentVersion(versionCheckerUtils.findVersion(buildGradle), currentVersion = "2.2-beta1")
|
||||
verify(rxBus, times(1)).send(anyObject())
|
||||
verify(activityNames, times(1)).addNotification(anyInt(), anyString(), anyInt())
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -367,7 +368,7 @@ import org.mockito.Mockito.`when`
|
|||
| appName = "Aaoeu"
|
||||
""".trimMargin()
|
||||
versionCheckerUtils.compareWithCurrentVersion(versionCheckerUtils.findVersion(buildGradle), currentVersion = "2.2-rc1")
|
||||
verify(rxBus, times(1)).send(anyObject())
|
||||
verify(activityNames, times(1)).addNotification(anyInt(), anyString(), anyInt())
|
||||
}
|
||||
|
||||
@Before
|
|
@ -4,7 +4,7 @@ import dagger.android.AndroidInjector
|
|||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.TestBase
|
||||
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.shared.interfaces.ResourceHelper
|
||||
import org.junit.Assert
|
||||
|
@ -18,12 +18,12 @@ import org.mockito.Mockito.`when`
|
|||
class StorageConstraintPluginTest : TestBase() {
|
||||
|
||||
@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() {
|
||||
storageConstraintPlugin = info.nightscout.plugins.constraints.storage.StorageConstraintPlugin({ AndroidInjector { } }, aapsLogger, rh, rxBusWrapper)
|
||||
storageConstraintPlugin = StorageConstraintPlugin({ AndroidInjector { } }, aapsLogger, rh, activityNames)
|
||||
`when`(rh.gs(anyInt(), anyLong())).thenReturn("")
|
||||
}
|
||||
|
||||
|
@ -31,15 +31,15 @@ class StorageConstraintPluginTest : TestBase() {
|
|||
injector: HasAndroidInjector,
|
||||
aapsLogger: AAPSLogger,
|
||||
rh: ResourceHelper,
|
||||
rxBus: RxBus
|
||||
) : info.nightscout.plugins.constraints.storage.StorageConstraintPlugin(injector, aapsLogger, rh, rxBus) {
|
||||
activityNames: ActivityNames
|
||||
) : StorageConstraintPlugin(injector, aapsLogger, rh, activityNames) {
|
||||
|
||||
var memSize = 150L
|
||||
override fun availableInternalMemorySize(): Long = memSize
|
||||
}
|
||||
|
||||
@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
|
||||
mocked.memSize = 150L
|
||||
Assert.assertEquals(false, mocked.isClosedLoopAllowed(Constraint(true)).value())
|
Loading…
Reference in a new issue