shared-tests #6
This commit is contained in:
parent
d1694e9763
commit
53beed4e14
13 changed files with 120 additions and 201 deletions
|
@ -25,6 +25,9 @@ dependencies {
|
|||
implementation project(':core:utils')
|
||||
implementation project(':core:ui')
|
||||
implementation project(':core:validators')
|
||||
|
||||
testImplementation project(':app-wear-shared:shared-tests')
|
||||
|
||||
//WorkManager
|
||||
api "androidx.work:work-runtime-ktx:$work_version"
|
||||
// Maintenance
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
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.jupiter.api.extension.ExtendWith
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.junit.jupiter.MockitoExtension
|
||||
import org.mockito.junit.jupiter.MockitoSettings
|
||||
import org.mockito.quality.Strictness
|
||||
import java.util.Locale
|
||||
|
||||
@ExtendWith(MockitoExtension::class)
|
||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||
open class TestBase {
|
||||
|
||||
val aapsLogger = AAPSLoggerTest()
|
||||
val aapsSchedulers: AapsSchedulers = TestAapsSchedulers()
|
||||
|
||||
@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
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
package info.nightscout.configuration.maintenance.formats
|
||||
|
||||
import info.nightscout.androidaps.TestBase
|
||||
import info.nightscout.core.utils.CryptoUtil
|
||||
import info.nightscout.interfaces.maintenance.PrefFormatError
|
||||
import info.nightscout.interfaces.maintenance.PrefMetadata
|
||||
|
@ -9,10 +8,10 @@ import info.nightscout.interfaces.maintenance.PrefsFormat
|
|||
import info.nightscout.interfaces.maintenance.PrefsMetadataKey
|
||||
import info.nightscout.interfaces.maintenance.PrefsStatus
|
||||
import info.nightscout.shared.interfaces.ResourceHelper
|
||||
import info.nightscout.sharedtests.TestBase
|
||||
import org.hamcrest.CoreMatchers
|
||||
import org.junit.Assert
|
||||
import org.junit.Assume
|
||||
import org.junit.Before
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.mockito.ArgumentMatchers
|
||||
|
@ -63,13 +62,13 @@ open class EncryptedPrefsFormatTest : TestBase() {
|
|||
|
||||
assumeAES256isSupported(cryptoUtil)
|
||||
|
||||
Assert.assertEquals(prefs.values.size, 2)
|
||||
Assert.assertEquals(prefs.values["key1"], "A")
|
||||
Assert.assertEquals(prefs.values["keyB"], "2")
|
||||
Assertions.assertEquals(prefs.values.size, 2)
|
||||
Assertions.assertEquals(prefs.values["key1"], "A")
|
||||
Assertions.assertEquals(prefs.values["keyB"], "2")
|
||||
|
||||
Assert.assertEquals(prefs.metadata[PrefsMetadataKey.FILE_FORMAT]?.status, PrefsStatus.OK)
|
||||
Assert.assertEquals(prefs.metadata[PrefsMetadataKey.FILE_FORMAT]?.value, PrefsFormat.FORMAT_KEY_ENC)
|
||||
Assert.assertEquals(prefs.metadata[PrefsMetadataKey.ENCRYPTION]?.status, PrefsStatus.OK)
|
||||
Assertions.assertEquals(prefs.metadata[PrefsMetadataKey.FILE_FORMAT]?.status, PrefsStatus.OK)
|
||||
Assertions.assertEquals(prefs.metadata[PrefsMetadataKey.FILE_FORMAT]?.value, PrefsFormat.FORMAT_KEY_ENC)
|
||||
Assertions.assertEquals(prefs.metadata[PrefsMetadataKey.ENCRYPTION]?.status, PrefsStatus.OK)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -107,13 +106,13 @@ open class EncryptedPrefsFormatTest : TestBase() {
|
|||
|
||||
assumeAES256isSupported(cryptoUtil)
|
||||
|
||||
Assert.assertEquals(prefsOut.values.size, 2)
|
||||
Assert.assertEquals(prefsOut.values["testpref1"], "--1--")
|
||||
Assert.assertEquals(prefsOut.values["testpref2"], "another")
|
||||
Assertions.assertEquals(prefsOut.values.size, 2)
|
||||
Assertions.assertEquals(prefsOut.values["testpref1"], "--1--")
|
||||
Assertions.assertEquals(prefsOut.values["testpref2"], "another")
|
||||
|
||||
Assert.assertEquals(prefsOut.metadata[PrefsMetadataKey.FILE_FORMAT]?.status, PrefsStatus.OK)
|
||||
Assert.assertEquals(prefsOut.metadata[PrefsMetadataKey.FILE_FORMAT]?.value, PrefsFormat.FORMAT_KEY_ENC)
|
||||
Assert.assertEquals(prefsOut.metadata[PrefsMetadataKey.ENCRYPTION]?.status, PrefsStatus.OK)
|
||||
Assertions.assertEquals(prefsOut.metadata[PrefsMetadataKey.FILE_FORMAT]?.status, PrefsStatus.OK)
|
||||
Assertions.assertEquals(prefsOut.metadata[PrefsMetadataKey.FILE_FORMAT]?.value, PrefsFormat.FORMAT_KEY_ENC)
|
||||
Assertions.assertEquals(prefsOut.metadata[PrefsMetadataKey.ENCRYPTION]?.status, PrefsStatus.OK)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -134,11 +133,11 @@ open class EncryptedPrefsFormatTest : TestBase() {
|
|||
val encryptedFormat = EncryptedPrefsFormat(rh, cryptoUtil, storage)
|
||||
val prefs = encryptedFormat.loadPreferences(getMockedFile(), "it-is-NOT-right-secret")
|
||||
|
||||
Assert.assertEquals(prefs.values.size, 0)
|
||||
Assertions.assertEquals(prefs.values.size, 0)
|
||||
|
||||
Assert.assertEquals(prefs.metadata[PrefsMetadataKey.FILE_FORMAT]?.status, PrefsStatus.OK)
|
||||
Assert.assertEquals(prefs.metadata[PrefsMetadataKey.FILE_FORMAT]?.value, PrefsFormat.FORMAT_KEY_ENC)
|
||||
Assert.assertEquals(prefs.metadata[PrefsMetadataKey.ENCRYPTION]?.status, PrefsStatus.ERROR)
|
||||
Assertions.assertEquals(prefs.metadata[PrefsMetadataKey.FILE_FORMAT]?.status, PrefsStatus.OK)
|
||||
Assertions.assertEquals(prefs.metadata[PrefsMetadataKey.FILE_FORMAT]?.value, PrefsFormat.FORMAT_KEY_ENC)
|
||||
Assertions.assertEquals(prefs.metadata[PrefsMetadataKey.ENCRYPTION]?.status, PrefsStatus.ERROR)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -164,10 +163,10 @@ open class EncryptedPrefsFormatTest : TestBase() {
|
|||
assumeAES256isSupported(cryptoUtil)
|
||||
|
||||
// contents were not tampered and we can decrypt them
|
||||
Assert.assertEquals(prefs.values.size, 2)
|
||||
Assertions.assertEquals(prefs.values.size, 2)
|
||||
|
||||
// but checksum fails on metadata, so overall security fails
|
||||
Assert.assertEquals(prefs.metadata[PrefsMetadataKey.ENCRYPTION]?.status, PrefsStatus.ERROR)
|
||||
Assertions.assertEquals(prefs.metadata[PrefsMetadataKey.ENCRYPTION]?.status, PrefsStatus.ERROR)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -188,8 +187,8 @@ open class EncryptedPrefsFormatTest : TestBase() {
|
|||
val encryptedFormat = EncryptedPrefsFormat(rh, cryptoUtil, storage)
|
||||
val prefs = encryptedFormat.loadPreferences(getMockedFile(), "sikret")
|
||||
|
||||
Assert.assertEquals(prefs.values.size, 0)
|
||||
Assert.assertEquals(prefs.metadata[PrefsMetadataKey.ENCRYPTION]?.status, PrefsStatus.ERROR)
|
||||
Assertions.assertEquals(prefs.values.size, 0)
|
||||
Assertions.assertEquals(prefs.metadata[PrefsMetadataKey.ENCRYPTION]?.status, PrefsStatus.ERROR)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -203,13 +202,13 @@ open class EncryptedPrefsFormatTest : TestBase() {
|
|||
val encryptedFormat = EncryptedPrefsFormat(rh, cryptoUtil, storage)
|
||||
val prefs = encryptedFormat.loadPreferences(getMockedFile(), "sikret")
|
||||
|
||||
Assert.assertEquals(prefs.values.size, 0)
|
||||
Assert.assertEquals(prefs.metadata[PrefsMetadataKey.FILE_FORMAT]?.status, PrefsStatus.ERROR)
|
||||
Assertions.assertEquals(prefs.values.size, 0)
|
||||
Assertions.assertEquals(prefs.metadata[PrefsMetadataKey.FILE_FORMAT]?.status, PrefsStatus.ERROR)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun garbageInputTest() {
|
||||
Assert.assertThrows(PrefFormatError::class.java) {
|
||||
Assertions.assertThrows(PrefFormatError::class.java) {
|
||||
val frozenPrefs = "whatever man, i duno care"
|
||||
|
||||
val storage = SingleStringStorage(frozenPrefs)
|
||||
|
@ -220,7 +219,7 @@ open class EncryptedPrefsFormatTest : TestBase() {
|
|||
|
||||
@Test
|
||||
fun unknownFormatTest() {
|
||||
Assert.assertThrows(PrefFormatError::class.java) {
|
||||
Assertions.assertThrows(PrefFormatError::class.java) {
|
||||
val frozenPrefs = "{\n" +
|
||||
" \"metadata\": {},\n" +
|
||||
" \"security\": {\n" +
|
||||
|
|
|
@ -23,6 +23,8 @@ dependencies {
|
|||
implementation project(':core:validators')
|
||||
implementation project(':database:entities')
|
||||
|
||||
testImplementation project(':app-wear-shared:shared-tests')
|
||||
|
||||
// Phone checker
|
||||
api 'com.scottyab:rootbeer-lib:0.1.0'
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
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.jupiter.api.extension.ExtendWith
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.junit.jupiter.MockitoExtension
|
||||
import org.mockito.junit.jupiter.MockitoSettings
|
||||
import org.mockito.quality.Strictness
|
||||
import java.util.Locale
|
||||
|
||||
@ExtendWith(MockitoExtension::class)
|
||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||
open class TestBase {
|
||||
|
||||
val aapsLogger = AAPSLoggerTest()
|
||||
val aapsSchedulers: AapsSchedulers = TestAapsSchedulers()
|
||||
|
||||
@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
|
||||
}
|
|
@ -2,7 +2,6 @@ package info.nightscout.plugins.constraints.bgQualityCheck
|
|||
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.TestBase
|
||||
import info.nightscout.core.utils.fabric.FabricPrivacy
|
||||
import info.nightscout.database.entities.GlucoseValue
|
||||
import info.nightscout.interfaces.aps.AutosensDataStore
|
||||
|
@ -16,6 +15,7 @@ import info.nightscout.rx.bus.RxBus
|
|||
import info.nightscout.shared.interfaces.ResourceHelper
|
||||
import info.nightscout.shared.utils.DateUtil
|
||||
import info.nightscout.shared.utils.T
|
||||
import info.nightscout.sharedtests.TestBase
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
|
|
|
@ -2,12 +2,12 @@ package info.nightscout.plugins.constraints.dstHelper
|
|||
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.TestBase
|
||||
import info.nightscout.interfaces.aps.Loop
|
||||
import info.nightscout.interfaces.plugin.ActivePlugin
|
||||
import info.nightscout.shared.interfaces.ResourceHelper
|
||||
import info.nightscout.shared.sharedPreferences.SP
|
||||
import org.junit.Assert
|
||||
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
|
||||
|
@ -34,38 +34,38 @@ class DstHelperPluginTest : TestBase() {
|
|||
}
|
||||
|
||||
@Test
|
||||
private fun runTest() {
|
||||
fun runTest() {
|
||||
val tz = TimeZone.getTimeZone("Europe/Rome")
|
||||
TimeZone.setDefault(tz)
|
||||
var cal = Calendar.getInstance(tz, Locale.ITALIAN)
|
||||
val df: DateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.ITALIAN)
|
||||
var dateBeforeDST = df.parse("2018-03-25 01:55")
|
||||
cal.time = dateBeforeDST!!
|
||||
Assert.assertEquals(false, plugin.wasDST(cal))
|
||||
Assert.assertEquals(true, plugin.willBeDST(cal))
|
||||
Assertions.assertEquals(false, plugin.wasDST(cal))
|
||||
Assertions.assertEquals(true, plugin.willBeDST(cal))
|
||||
TimeZone.setDefault(tz)
|
||||
cal = Calendar.getInstance(tz, Locale.ITALIAN)
|
||||
dateBeforeDST = df.parse("2018-03-25 03:05")
|
||||
cal.time = dateBeforeDST!!
|
||||
Assert.assertEquals(true, plugin.wasDST(cal))
|
||||
Assert.assertEquals(false, plugin.willBeDST(cal))
|
||||
Assertions.assertEquals(true, plugin.wasDST(cal))
|
||||
Assertions.assertEquals(false, plugin.willBeDST(cal))
|
||||
TimeZone.setDefault(tz)
|
||||
cal = Calendar.getInstance(tz, Locale.ITALIAN)
|
||||
dateBeforeDST = df.parse("2018-03-25 02:05") //Cannot happen!!!
|
||||
cal.time = dateBeforeDST!!
|
||||
Assert.assertEquals(true, plugin.wasDST(cal))
|
||||
Assert.assertEquals(false, plugin.willBeDST(cal))
|
||||
Assertions.assertEquals(true, plugin.wasDST(cal))
|
||||
Assertions.assertEquals(false, plugin.willBeDST(cal))
|
||||
TimeZone.setDefault(tz)
|
||||
cal = Calendar.getInstance(tz, Locale.ITALIAN)
|
||||
dateBeforeDST = df.parse("2018-03-25 05:55") //Cannot happen!!!
|
||||
cal.time = dateBeforeDST!!
|
||||
Assert.assertEquals(true, plugin.wasDST(cal))
|
||||
Assert.assertEquals(false, plugin.willBeDST(cal))
|
||||
Assertions.assertEquals(true, plugin.wasDST(cal))
|
||||
Assertions.assertEquals(false, plugin.willBeDST(cal))
|
||||
TimeZone.setDefault(tz)
|
||||
cal = Calendar.getInstance(tz, Locale.ITALIAN)
|
||||
dateBeforeDST = df.parse("2018-03-25 06:05") //Cannot happen!!!
|
||||
cal.time = dateBeforeDST!!
|
||||
Assert.assertEquals(false, plugin.wasDST(cal))
|
||||
Assert.assertEquals(false, plugin.willBeDST(cal))
|
||||
Assertions.assertEquals(false, plugin.wasDST(cal))
|
||||
Assertions.assertEquals(false, plugin.willBeDST(cal))
|
||||
}
|
||||
}
|
|
@ -2,15 +2,16 @@ package info.nightscout.plugins.constraints.objectives
|
|||
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.TestBase
|
||||
import info.nightscout.interfaces.Config
|
||||
import info.nightscout.interfaces.constraints.Constraint
|
||||
import info.nightscout.interfaces.constraints.Objectives
|
||||
import info.nightscout.interfaces.plugin.ActivePlugin
|
||||
import info.nightscout.plugins.constraints.R
|
||||
import info.nightscout.plugins.constraints.objectives.objectives.Objective
|
||||
import info.nightscout.shared.interfaces.ResourceHelper
|
||||
import info.nightscout.shared.sharedPreferences.SP
|
||||
import info.nightscout.shared.utils.DateUtil
|
||||
import info.nightscout.sharedtests.TestBase
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
|
@ -27,9 +28,9 @@ class ObjectivesPluginTest : TestBase() {
|
|||
|
||||
private lateinit var objectivesPlugin: ObjectivesPlugin
|
||||
|
||||
val injector = HasAndroidInjector {
|
||||
private val injector = HasAndroidInjector {
|
||||
AndroidInjector {
|
||||
if (it is info.nightscout.plugins.constraints.objectives.objectives.Objective) {
|
||||
if (it is Objective) {
|
||||
it.sp = sp
|
||||
it.rh = rh
|
||||
it.dateUtil = dateUtil
|
||||
|
|
|
@ -1,30 +1,31 @@
|
|||
package info.nightscout.plugins.constraints.objectives
|
||||
|
||||
import info.nightscout.androidaps.TestBase
|
||||
import info.nightscout.shared.utils.DateUtil
|
||||
import org.junit.Assert
|
||||
import info.nightscout.sharedtests.TestBase
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.mockito.Mock
|
||||
import kotlin.math.abs
|
||||
|
||||
class SntpClientTest : TestBase() {
|
||||
|
||||
@Mock lateinit var dateUtil: DateUtil
|
||||
|
||||
@Test
|
||||
fun ntpTimeTest() {
|
||||
// no internet
|
||||
info.nightscout.plugins.constraints.objectives.SntpClient(aapsLogger, dateUtil).ntpTime(object : info.nightscout.plugins.constraints.objectives.SntpClient.Callback() {
|
||||
SntpClient(aapsLogger, dateUtil).ntpTime(object : SntpClient.Callback() {
|
||||
override fun run() {
|
||||
Assert.assertFalse(networkConnected)
|
||||
Assert.assertFalse(success)
|
||||
Assert.assertEquals(0L, time)
|
||||
Assertions.assertFalse(networkConnected)
|
||||
Assertions.assertFalse(success)
|
||||
Assertions.assertEquals(0L, time)
|
||||
}
|
||||
}, false)
|
||||
// internet
|
||||
info.nightscout.plugins.constraints.objectives.SntpClient(aapsLogger, dateUtil).doNtpTime(object : info.nightscout.plugins.constraints.objectives.SntpClient.Callback() {
|
||||
SntpClient(aapsLogger, dateUtil).doNtpTime(object : SntpClient.Callback() {
|
||||
override fun run() {
|
||||
Assert.assertTrue(success)
|
||||
Assert.assertTrue(abs(time - System.currentTimeMillis()) < 60000)
|
||||
Assertions.assertTrue(success)
|
||||
Assertions.assertTrue(abs(time - System.currentTimeMillis()) < 60000)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,26 +1,13 @@
|
|||
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.UiInteraction
|
||||
import info.nightscout.shared.interfaces.ResourceHelper
|
||||
import info.nightscout.shared.sharedPreferences.SP
|
||||
import org.junit.Assert
|
||||
import info.nightscout.sharedtests.TestBase
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.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 uiInteraction: UiInteraction
|
||||
|
||||
val injector = HasAndroidInjector { AndroidInjector { } }
|
||||
|
||||
fun singleCharUnMap(shortHash: String): String {
|
||||
@Suppress("SameParameterValue")
|
||||
private fun singleCharUnMap(shortHash: String): String {
|
||||
val array = ByteArray(shortHash.length)
|
||||
val sb = StringBuilder()
|
||||
for (i in array.indices) {
|
||||
|
@ -30,13 +17,14 @@ class SignatureVerifierPluginTest : TestBase() {
|
|||
return sb.toString()
|
||||
}
|
||||
|
||||
var map =
|
||||
@Suppress("SpellCheckingInspection")
|
||||
private var map =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!\"§$%&/()=?,.-;:_<>|°^`´\\@€*'#+~{}[]¿¡áéíóúàèìòùöäü`ÁÉÍÓÚÀÈÌÒÙÖÄÜßÆÇÊËÎÏԌ۟æçêëîïôœûÿĆČĐŠŽćđšžñΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡ\u03A2ΣΤΥΦΧΨΩαβγδεζηθικλμνξοπρςστυφχψωϨϩϪϫϬϭϮϯϰϱϲϳϴϵ϶ϷϸϹϺϻϼϽϾϿЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗ"
|
||||
|
||||
@Test
|
||||
fun singleCharUnMapTest() {
|
||||
val key = "2ΙšÄΠΒϨÒÇeЄtЄЗž-*Ж*ZcHijЊÄœ<|x\"Ε"
|
||||
@Suppress("SpellCheckingInspection") 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)
|
||||
Assertions.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,7 +1,6 @@
|
|||
package info.nightscout.plugins.constraints.signatureVerifier
|
||||
|
||||
import dagger.Lazy
|
||||
import info.nightscout.androidaps.TestBase
|
||||
import info.nightscout.interfaces.Config
|
||||
import info.nightscout.interfaces.receivers.ReceiverStatusStore
|
||||
import info.nightscout.interfaces.ui.UiInteraction
|
||||
|
@ -11,8 +10,8 @@ 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
|
||||
import org.junit.Assert.assertArrayEquals
|
||||
import org.junit.Assert.assertEquals
|
||||
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.ArgumentMatchers.anyInt
|
||||
|
@ -22,7 +21,8 @@ import org.mockito.Mockito.times
|
|||
import org.mockito.Mockito.verify
|
||||
import org.mockito.Mockito.`when`
|
||||
|
||||
@Suppress("SpellCheckingInspection") class VersionCheckerUtilsKtTest : TestBase() {
|
||||
@Suppress("SpellCheckingInspection")
|
||||
class VersionCheckerUtilsKtTest : TestBase() {
|
||||
|
||||
private lateinit var versionCheckerUtils: VersionCheckerUtils
|
||||
|
||||
|
@ -39,97 +39,97 @@ import org.mockito.Mockito.`when`
|
|||
|
||||
@Test
|
||||
fun `should handle invalid version`() {
|
||||
assertArrayEquals(intArrayOf(), versionCheckerUtils.versionDigits("definitely not version string"))
|
||||
Assertions.assertArrayEquals(intArrayOf(), versionCheckerUtils.versionDigits("definitely not version string"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should handle empty version`() {
|
||||
assertArrayEquals(intArrayOf(), versionCheckerUtils.versionDigits(""))
|
||||
Assertions.assertArrayEquals(intArrayOf(), versionCheckerUtils.versionDigits(""))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should parse 2 digit version`() {
|
||||
assertArrayEquals(intArrayOf(0, 999), versionCheckerUtils.versionDigits("0.999-beta"))
|
||||
Assertions.assertArrayEquals(intArrayOf(0, 999), versionCheckerUtils.versionDigits("0.999-beta"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should parse 3 digit version`() {
|
||||
assertArrayEquals(intArrayOf(6, 83, 93), versionCheckerUtils.versionDigits("6.83.93"))
|
||||
Assertions.assertArrayEquals(intArrayOf(6, 83, 93), versionCheckerUtils.versionDigits("6.83.93"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should parse 4 digit version`() {
|
||||
assertArrayEquals(intArrayOf(42, 7, 13, 101), versionCheckerUtils.versionDigits("42.7.13.101"))
|
||||
Assertions.assertArrayEquals(intArrayOf(42, 7, 13, 101), versionCheckerUtils.versionDigits("42.7.13.101"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should parse 4 digit version with extra`() {
|
||||
assertArrayEquals(intArrayOf(1, 2, 3, 4), versionCheckerUtils.versionDigits("1.2.3.4-RC5"))
|
||||
Assertions.assertArrayEquals(intArrayOf(1, 2, 3, 4), versionCheckerUtils.versionDigits("1.2.3.4-RC5"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should parse version but only 4 digits are taken`() {
|
||||
assertArrayEquals(intArrayOf(67, 8, 31, 5), versionCheckerUtils.versionDigits("67.8.31.5.153.4.2"))
|
||||
Assertions.assertArrayEquals(intArrayOf(67, 8, 31, 5), versionCheckerUtils.versionDigits("67.8.31.5.153.4.2"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should keep 2 digit version`() {
|
||||
assertEquals("1.2", "1.2".numericVersionPart())
|
||||
Assertions.assertEquals("1.2", "1.2".numericVersionPart())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should keep 3 digit version`() {
|
||||
assertEquals("1.2.3", "1.2.3".numericVersionPart())
|
||||
Assertions.assertEquals("1.2.3", "1.2.3".numericVersionPart())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should keep 4 digit version`() {
|
||||
assertEquals("1.2.3.4", "1.2.3.4".numericVersionPart())
|
||||
Assertions.assertEquals("1.2.3.4", "1.2.3.4".numericVersionPart())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should strip 2 digit version RC`() {
|
||||
assertEquals("1.2", "1.2-RC1".numericVersionPart())
|
||||
Assertions.assertEquals("1.2", "1.2-RC1".numericVersionPart())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should strip 2 digit version RC old format`() {
|
||||
assertEquals("1.2", "1.2RC1".numericVersionPart())
|
||||
Assertions.assertEquals("1.2", "1.2RC1".numericVersionPart())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should strip 2 digit version RC without digit`() {
|
||||
assertEquals("1.2", "1.2-RC".numericVersionPart())
|
||||
Assertions.assertEquals("1.2", "1.2-RC".numericVersionPart())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should strip 2 digit version dev`() {
|
||||
assertEquals("1.2", "1.2-dev".numericVersionPart())
|
||||
Assertions.assertEquals("1.2", "1.2-dev".numericVersionPart())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should strip 2 digit version dev old format 1`() {
|
||||
assertEquals("1.2", "1.2dev".numericVersionPart())
|
||||
Assertions.assertEquals("1.2", "1.2dev".numericVersionPart())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should strip 2 digit version dev old format 2`() {
|
||||
assertEquals("1.2", "1.2dev-a3".numericVersionPart())
|
||||
Assertions.assertEquals("1.2", "1.2dev-a3".numericVersionPart())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should strip 3 digit version RC`() {
|
||||
assertEquals("1.2.3", "1.2.3-RC1".numericVersionPart())
|
||||
Assertions.assertEquals("1.2.3", "1.2.3-RC1".numericVersionPart())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should strip 4 digit version RC`() {
|
||||
assertEquals("1.2.3.4", "1.2.3.4-RC5".numericVersionPart())
|
||||
Assertions.assertEquals("1.2.3.4", "1.2.3.4-RC5".numericVersionPart())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should strip even with dot`() {
|
||||
assertEquals("1.2", "1.2.RC5".numericVersionPart())
|
||||
Assertions.assertEquals("1.2", "1.2.RC5".numericVersionPart())
|
||||
}
|
||||
|
||||
@Suppress("SpellCheckingInspection")
|
||||
|
@ -143,7 +143,7 @@ import org.mockito.Mockito.`when`
|
|||
| appName = "Aaoeu"
|
||||
""".trimMargin()
|
||||
val detectedVersion: String? = versionCheckerUtils.findVersion(buildGradle)
|
||||
assertEquals("2.2.2", detectedVersion)
|
||||
Assertions.assertEquals("2.2.2", detectedVersion)
|
||||
}
|
||||
|
||||
// In case we merge a "x.x.x-dev" into master, don't see it as update.
|
||||
|
@ -157,14 +157,14 @@ import org.mockito.Mockito.`when`
|
|||
| appName = "Aaoeu"
|
||||
""".trimMargin()
|
||||
val detectedVersion: String? = versionCheckerUtils.findVersion(buildGradle)
|
||||
assertEquals(null, detectedVersion)
|
||||
Assertions.assertEquals(null, detectedVersion)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun findVersionMatchesDoesNotMatchErrorResponse() {
|
||||
val buildGradle = """<html><body>Balls! No build.gradle here. Move along</body><html>"""
|
||||
val detectedVersion: String? = versionCheckerUtils.findVersion(buildGradle)
|
||||
assertEquals(null, detectedVersion)
|
||||
Assertions.assertEquals(null, detectedVersion)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -228,6 +228,7 @@ import org.mockito.Mockito.`when`
|
|||
|
||||
verify(uiInteraction, times(0)).addNotification(anyInt(), anyString(), anyInt())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `find higher version`() {
|
||||
val buildGradle = """blabla
|
||||
|
@ -345,7 +346,7 @@ import org.mockito.Mockito.`when`
|
|||
verify(uiInteraction, times(0)).addNotification(anyInt(), anyString(), anyInt())
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test
|
||||
fun `warn on beta`() {
|
||||
val buildGradle = """blabla
|
||||
| android {
|
||||
|
@ -355,10 +356,10 @@ import org.mockito.Mockito.`when`
|
|||
| appName = "Aaoeu"
|
||||
""".trimMargin()
|
||||
versionCheckerUtils.compareWithCurrentVersion(versionCheckerUtils.findVersion(buildGradle), currentVersion = "2.2-beta1")
|
||||
verify(uiInteraction, times(1)).addNotification(anyInt(), anyString(), anyInt())
|
||||
verify(uiInteraction, times(1)).addNotification(anyInt(), anyString(), anyInt())
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test
|
||||
fun `warn on rc`() {
|
||||
val buildGradle = """blabla
|
||||
| android {
|
||||
|
@ -368,13 +369,13 @@ import org.mockito.Mockito.`when`
|
|||
| appName = "Aaoeu"
|
||||
""".trimMargin()
|
||||
versionCheckerUtils.compareWithCurrentVersion(versionCheckerUtils.findVersion(buildGradle), currentVersion = "2.2-rc1")
|
||||
verify(uiInteraction, times(1)).addNotification(anyInt(), anyString(), anyInt())
|
||||
verify(uiInteraction, times(1)).addNotification(anyInt(), anyString(), anyInt())
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
fun `set time`() {
|
||||
`when`(dateUtil.now()).thenReturn(10000000000L)
|
||||
assertEquals(10000000000L, dateUtil.now())
|
||||
Assertions.assertEquals(10000000000L, dateUtil.now())
|
||||
|
||||
`when`(rh.gs(anyInt(), anyString())).thenReturn("")
|
||||
}
|
||||
|
|
|
@ -2,12 +2,12 @@ package info.nightscout.plugins.constraints.storage
|
|||
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.TestBase
|
||||
import info.nightscout.interfaces.constraints.Constraint
|
||||
import info.nightscout.interfaces.ui.UiInteraction
|
||||
import info.nightscout.rx.logging.AAPSLogger
|
||||
import info.nightscout.shared.interfaces.ResourceHelper
|
||||
import org.junit.Assert
|
||||
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
|
||||
|
@ -42,9 +42,9 @@ class StorageConstraintPluginTest : TestBase() {
|
|||
val mocked = MockedStorageConstraintPlugin({ AndroidInjector { } }, aapsLogger, rh, uiInteraction)
|
||||
// Set free space under 200(Mb) to disable loop
|
||||
mocked.memSize = 150L
|
||||
Assert.assertEquals(false, mocked.isClosedLoopAllowed(Constraint(true)).value())
|
||||
Assertions.assertEquals(false, mocked.isClosedLoopAllowed(Constraint(true)).value())
|
||||
// Set free space over 200(Mb) to enable loop
|
||||
mocked.memSize = 300L
|
||||
Assert.assertEquals(true, mocked.isClosedLoopAllowed(Constraint(true)).value())
|
||||
Assertions.assertEquals(true, mocked.isClosedLoopAllowed(Constraint(true)).value())
|
||||
}
|
||||
}
|
|
@ -4,10 +4,7 @@ import info.nightscout.interfaces.constraints.versionChecker.AllowedVersions
|
|||
import org.joda.time.LocalDate
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class AllowedVersionsTest {
|
||||
|
@ -48,14 +45,14 @@ class AllowedVersionsTest {
|
|||
@Test
|
||||
fun generateSupportedVersionsTest() {
|
||||
val definition = generateSupportedVersions()
|
||||
assertNull(AllowedVersions().findByApi(definition, 0))
|
||||
assertFalse(AllowedVersions().findByApi(definition, 1)?.has("supported") ?: true)
|
||||
assertFalse(AllowedVersions().findByApi(definition, 23)?.has("supported") ?: true)
|
||||
assertEquals("2.6.2", AllowedVersions().findByApi(definition, 24)?.getString("supported"))
|
||||
assertEquals("2.6.2", AllowedVersions().findByApi(definition, 25)?.getString("supported"))
|
||||
assertEquals("2.8.2", AllowedVersions().findByApi(definition, 26)?.getString("supported"))
|
||||
assertEquals("2.8.2", AllowedVersions().findByApi(definition, 27)?.getString("supported"))
|
||||
assertEquals("2.8.2", AllowedVersions().findByApi(definition, 28)?.getString("supported"))
|
||||
Assertions.assertNull(AllowedVersions().findByApi(definition, 0))
|
||||
Assertions.assertFalse(AllowedVersions().findByApi(definition, 1)?.has("supported") ?: true)
|
||||
Assertions.assertFalse(AllowedVersions().findByApi(definition, 23)?.has("supported") ?: true)
|
||||
Assertions.assertEquals("2.6.2", AllowedVersions().findByApi(definition, 24)?.getString("supported"))
|
||||
Assertions.assertEquals("2.6.2", AllowedVersions().findByApi(definition, 25)?.getString("supported"))
|
||||
Assertions.assertEquals("2.8.2", AllowedVersions().findByApi(definition, 26)?.getString("supported"))
|
||||
Assertions.assertEquals("2.8.2", AllowedVersions().findByApi(definition, 27)?.getString("supported"))
|
||||
Assertions.assertEquals("2.8.2", AllowedVersions().findByApi(definition, 28)?.getString("supported"))
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -65,20 +62,21 @@ class AllowedVersionsTest {
|
|||
"[{\"minAndroid\":1,\"maxAndroid\":23},{\"minAndroid\":24,\"maxAndroid\":25,\"supported\":\"2.6.2\"},{\"minAndroid\":26,\"maxAndroid\":27,\"supported\":\"2.8.2\"},{\"minAndroid\":28,\"maxAndroid\":99,\"supported\":\"2.8.2\"},{\"endDate\":\"2021-11-07\",\"version\":\"2.9.0-beta1\"},{\"endDate\":\"2021-11-02\",\"version\":\"3.0-beta1\"},{\"endDate\":\"2021-11-04\",\"version\":\"3.0-beta2\"},{\"endDate\":\"2021-11-10\",\"version\":\"3.0-beta3\"},{\"endDate\":\"2021-11-14\",\"version\":\"3.0-beta4\"}\n" +
|
||||
" ,{\"endDate\":\"2021-11-16\",\"version\":\"3.0-beta5\"}\n" +
|
||||
"]"
|
||||
assertNull(AllowedVersions().findByVersion(definition, "2.6.0"))
|
||||
assertTrue(AllowedVersions().findByVersion(definition, "2.9.0-beta1")?.has("endDate") ?: false)
|
||||
assertEquals("2021-11-07", AllowedVersions().findByVersion(definition, "2.9.0-beta1")?.getString("endDate"))
|
||||
Assertions.assertNull(AllowedVersions().findByVersion(definition, "2.6.0"))
|
||||
Assertions.assertTrue(AllowedVersions().findByVersion(definition, "2.9.0-beta1")?.has("endDate") ?: false)
|
||||
Assertions.assertEquals("2021-11-07", AllowedVersions().findByVersion(definition, "2.9.0-beta1")?.getString("endDate"))
|
||||
}
|
||||
|
||||
@Suppress("SpellCheckingInspection")
|
||||
@Test
|
||||
fun endDateToMilliseconds() {
|
||||
val definition = generateSupportedVersions()
|
||||
val endDate = AllowedVersions().endDateToMilliseconds(AllowedVersions().findByVersion(definition, "2.9.0-beta1")?.getString("endDate") ?: "1000/01/01")
|
||||
val dateTime = LocalDate(endDate)
|
||||
assertEquals(2021, dateTime.year)
|
||||
assertEquals(11, dateTime.monthOfYear)
|
||||
assertEquals(7, dateTime.dayOfMonth)
|
||||
Assertions.assertEquals(2021, dateTime.year)
|
||||
Assertions.assertEquals(11, dateTime.monthOfYear)
|
||||
Assertions.assertEquals(7, dateTime.dayOfMonth)
|
||||
|
||||
assertNull(AllowedVersions().endDateToMilliseconds("abdef"))
|
||||
Assertions.assertNull(AllowedVersions().endDateToMilliseconds("abdef"))
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue