some work fixing tests
This commit is contained in:
parent
ccf93d2191
commit
6326c3f6f9
7 changed files with 90 additions and 91 deletions
|
@ -59,7 +59,7 @@ class VersionCheckerUtils @Inject constructor() {
|
|||
aapsLogger.debug(LTag.CORE, "Github master version no checked. No connectivity")
|
||||
|
||||
@Suppress("SameParameterValue")
|
||||
private fun compareWithCurrentVersion(newVersion: String?, currentVersion: String) {
|
||||
fun compareWithCurrentVersion(newVersion: String?, currentVersion: String) {
|
||||
|
||||
val newVersionElements = newVersion.toNumberList()
|
||||
val currentVersionElements = currentVersion.toNumberList()
|
||||
|
@ -113,6 +113,27 @@ class VersionCheckerUtils @Inject constructor() {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private fun String?.toNumberList() =
|
||||
this?.numericVersionPart().takeIf { !it.isNullOrBlank() }?.split(".")?.map { it.toInt() }
|
||||
|
||||
|
||||
companion object {
|
||||
private val CHECK_EVERY = TimeUnit.DAYS.toMillis(1)
|
||||
private val WARN_EVERY = TimeUnit.DAYS.toMillis(1)
|
||||
}
|
||||
}
|
||||
|
||||
fun String.numericVersionPart(): String =
|
||||
"(((\\d+)\\.)+(\\d+))(\\D(.*))?".toRegex().matchEntire(this)?.groupValues?.getOrNull(1)
|
||||
?: ""
|
||||
|
||||
fun findVersion(file: String?): String? {
|
||||
val regex = "(.*)version(.*)\"(((\\d+)\\.)+(\\d+))\"(.*)".toRegex()
|
||||
return file?.lines()?.filter { regex.matches(it) }?.mapNotNull { regex.matchEntire(it)?.groupValues?.getOrNull(3) }?.firstOrNull()
|
||||
}
|
||||
|
||||
@Deprecated(replaceWith = ReplaceWith("numericVersionPart()"), message = "Will not work if RCs have another index number in it.")
|
||||
fun String.versionStrip() = this.mapNotNull {
|
||||
when (it) {
|
||||
|
@ -121,21 +142,3 @@ class VersionCheckerUtils @Inject constructor() {
|
|||
else -> null
|
||||
}
|
||||
}.joinToString(separator = "")
|
||||
|
||||
private fun String.numericVersionPart(): String =
|
||||
"(((\\d+)\\.)+(\\d+))(\\D(.*))?".toRegex().matchEntire(this)?.groupValues?.getOrNull(1)
|
||||
?: ""
|
||||
|
||||
private fun String?.toNumberList() =
|
||||
this?.numericVersionPart().takeIf { !it.isNullOrBlank() }?.split(".")?.map { it.toInt() }
|
||||
|
||||
private fun findVersion(file: String?): String? {
|
||||
val regex = "(.*)version(.*)\"(((\\d+)\\.)+(\\d+))\"(.*)".toRegex()
|
||||
return file?.lines()?.filter { regex.matches(it) }?.mapNotNull { regex.matchEntire(it)?.groupValues?.getOrNull(3) }?.firstOrNull()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val CHECK_EVERY = TimeUnit.DAYS.toMillis(1)
|
||||
private val WARN_EVERY = TimeUnit.DAYS.toMillis(1)
|
||||
}
|
||||
}
|
|
@ -1,15 +1,15 @@
|
|||
package info.nightscout.androidaps.plugins.constraints.signatureVerifier
|
||||
|
||||
import org.junit.Assert.fail
|
||||
import org.junit.Test
|
||||
|
||||
import org.junit.Assert.*
|
||||
|
||||
class SignatureVerifierPluginTest {
|
||||
|
||||
@Test
|
||||
fun singleCharUnMapTest() {
|
||||
val key = "2ΙšÄΠΒϨÒÇeЄtЄЗž-*Ж*ZcHijЊÄœ<|x\"Ε"
|
||||
val unmapped = SignatureVerifierPlugin.getPlugin().singleCharUnMap(key)
|
||||
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)
|
||||
fail() // TODO fix test
|
||||
//val unmapped = SignatureVerifierPlugin.getPlugin().singleCharUnMap(key)
|
||||
// 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)
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@ import info.nightscout.androidaps.R
|
|||
import info.nightscout.androidaps.logging.L
|
||||
import info.nightscout.androidaps.utils.SP
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.fail
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.ArgumentMatchers
|
||||
|
@ -128,7 +129,7 @@ class VersionCheckerUtilsKtTest {
|
|||
fun `should find update1`() {
|
||||
prepareMainApp()
|
||||
|
||||
compareWithCurrentVersion(newVersion = "2.2.3", currentVersion = "2.2.1")
|
||||
fail()// TODO setup as Object and test: compareWithCurrentVersion(newVersion = "2.2.3", currentVersion = "2.2.1")
|
||||
|
||||
//verify(bus, times(1)).post(any())
|
||||
|
||||
|
@ -145,7 +146,7 @@ class VersionCheckerUtilsKtTest {
|
|||
fun `should find update2`() {
|
||||
prepareMainApp()
|
||||
|
||||
compareWithCurrentVersion(newVersion = "2.2.3", currentVersion = "2.2.1-dev")
|
||||
fail()// TODO setup as Object and test: compareWithCurrentVersion(newVersion = "2.2.3", currentVersion = "2.2.1-dev")
|
||||
|
||||
//verify(bus, times(1)).post(any())
|
||||
|
||||
|
@ -161,7 +162,7 @@ class VersionCheckerUtilsKtTest {
|
|||
fun `should find update3`() {
|
||||
prepareMainApp()
|
||||
|
||||
compareWithCurrentVersion(newVersion = "2.2.3", currentVersion = "2.1")
|
||||
fail()// TODO setup as Object and test: compareWithCurrentVersion(newVersion = "2.2.3", currentVersion = "2.1")
|
||||
|
||||
//verify(bus, times(1)).post(any())
|
||||
|
||||
|
@ -177,7 +178,7 @@ class VersionCheckerUtilsKtTest {
|
|||
fun `should find update4`() {
|
||||
prepareMainApp()
|
||||
|
||||
compareWithCurrentVersion(newVersion = "2.2", currentVersion = "2.1.1")
|
||||
fail()// TODO setup as Object and test: compareWithCurrentVersion(newVersion = "2.2", currentVersion = "2.1.1")
|
||||
|
||||
//verify(bus, times(1)).post(any())
|
||||
|
||||
|
@ -192,7 +193,7 @@ class VersionCheckerUtilsKtTest {
|
|||
@PrepareForTest(MainApp::class, L::class, SP::class)
|
||||
fun `should find update5`() {
|
||||
prepareMainApp()
|
||||
compareWithCurrentVersion(newVersion = "2.2.1", currentVersion = "2.2-dev")
|
||||
fail()// TODO setup as Object and test: compareWithCurrentVersion(newVersion = "2.2.1", currentVersion = "2.2-dev")
|
||||
|
||||
//verify(bus, times(1)).post(any())
|
||||
|
||||
|
@ -207,7 +208,7 @@ class VersionCheckerUtilsKtTest {
|
|||
@PrepareForTest(MainApp::class, L::class, SP::class)
|
||||
fun `should find update6`() {
|
||||
prepareMainApp()
|
||||
compareWithCurrentVersion(newVersion = "2.2.1", currentVersion = "2.2dev")
|
||||
fail()// TODO setup as Object and test: compareWithCurrentVersion(newVersion = "2.2.1", currentVersion = "2.2dev")
|
||||
|
||||
//verify(bus, times(1)).post(any())
|
||||
|
||||
|
@ -222,7 +223,7 @@ class VersionCheckerUtilsKtTest {
|
|||
@PrepareForTest(MainApp::class, L::class, SP::class)
|
||||
fun `should not find update on fourth version digit`() {
|
||||
prepareMainApp()
|
||||
compareWithCurrentVersion(newVersion = "2.5.0", currentVersion = "2.5.0.1")
|
||||
fail()// TODO setup as Object and test: compareWithCurrentVersion(newVersion = "2.5.0", currentVersion = "2.5.0.1")
|
||||
|
||||
//verify(bus, times(0)).post(any())
|
||||
|
||||
|
@ -235,7 +236,7 @@ class VersionCheckerUtilsKtTest {
|
|||
@PrepareForTest(MainApp::class, L::class, SP::class)
|
||||
fun `should not find update on personal version with same number` (){
|
||||
prepareMainApp()
|
||||
compareWithCurrentVersion(newVersion = "2.5.0", currentVersion = "2.5.0-myversion")
|
||||
fail()// TODO setup as Object and test: compareWithCurrentVersion(newVersion = "2.5.0", currentVersion = "2.5.0-myversion")
|
||||
|
||||
//verify(bus, times(0)).post(any())
|
||||
|
||||
|
@ -256,7 +257,7 @@ class VersionCheckerUtilsKtTest {
|
|||
| appName = "Aaoeu"
|
||||
""".trimMargin()
|
||||
prepareMainApp()
|
||||
compareWithCurrentVersion(findVersion(buildGradle), currentVersion = "2.2.2")
|
||||
fail()// TODO setup as Object and test: compareWithCurrentVersion(findVersion(buildGradle), currentVersion = "2.2.2")
|
||||
|
||||
//verify(bus, times(0)).post(any())
|
||||
|
||||
|
@ -276,7 +277,7 @@ class VersionCheckerUtilsKtTest {
|
|||
| appName = "Aaoeu"
|
||||
""".trimMargin()
|
||||
prepareMainApp()
|
||||
compareWithCurrentVersion(findVersion(buildGradle), currentVersion = "2.2.2")
|
||||
fail()// TODO setup as Object and test: compareWithCurrentVersion(findVersion(buildGradle), currentVersion = "2.2.2")
|
||||
|
||||
PowerMockito.verifyStatic(SP::class.java, times(1))
|
||||
SP.getLong(eq(R.string.key_last_versionchecker_warning), ArgumentMatchers.anyLong())
|
||||
|
@ -297,7 +298,7 @@ class VersionCheckerUtilsKtTest {
|
|||
| appName = "Aaoeu"
|
||||
""".trimMargin()
|
||||
prepareMainApp()
|
||||
compareWithCurrentVersion(findVersion(buildGradle), currentVersion = "2.2.2")
|
||||
fail()// TODO setup as Object and test: compareWithCurrentVersion(findVersion(buildGradle), currentVersion = "2.2.2")
|
||||
|
||||
PowerMockito.verifyStatic(SP::class.java, times(1))
|
||||
SP.getLong(eq(R.string.key_last_versionchecker_warning), ArgumentMatchers.anyLong())
|
||||
|
@ -317,7 +318,7 @@ class VersionCheckerUtilsKtTest {
|
|||
| appName = "Aaoeu"
|
||||
""".trimMargin()
|
||||
prepareMainApp()
|
||||
compareWithCurrentVersion(findVersion(buildGradle), currentVersion = "3.0-RC04")
|
||||
fail()// TODO setup as Object and test: compareWithCurrentVersion(findVersion(buildGradle), currentVersion = "3.0-RC04")
|
||||
|
||||
PowerMockito.verifyStatic(SP::class.java, times(1))
|
||||
SP.getLong(eq(R.string.key_last_versionchecker_warning), ArgumentMatchers.anyLong())
|
||||
|
@ -337,7 +338,7 @@ class VersionCheckerUtilsKtTest {
|
|||
| appName = "Aaoeu"
|
||||
""".trimMargin()
|
||||
prepareMainApp()
|
||||
compareWithCurrentVersion(findVersion(buildGradle), currentVersion = "3.0RC04")
|
||||
fail()// TODO setup as Object and test: compareWithCurrentVersion(findVersion(buildGradle), currentVersion = "3.0RC04")
|
||||
|
||||
PowerMockito.verifyStatic(SP::class.java, times(1))
|
||||
SP.getLong(eq(R.string.key_last_versionchecker_warning), ArgumentMatchers.anyLong())
|
||||
|
@ -357,7 +358,7 @@ class VersionCheckerUtilsKtTest {
|
|||
| appName = "Aaoeu"
|
||||
""".trimMargin()
|
||||
prepareMainApp()
|
||||
compareWithCurrentVersion(findVersion(buildGradle), currentVersion = "3.RC04")
|
||||
fail()// TODO setup as Object and test: compareWithCurrentVersion(findVersion(buildGradle), currentVersion = "3.RC04")
|
||||
|
||||
PowerMockito.verifyStatic(SP::class.java, times(1))
|
||||
SP.getLong(eq(R.string.key_last_versionchecker_warning), ArgumentMatchers.anyLong())
|
||||
|
@ -377,7 +378,7 @@ class VersionCheckerUtilsKtTest {
|
|||
| appName = "Aaoeu"
|
||||
""".trimMargin()
|
||||
prepareMainApp()
|
||||
compareWithCurrentVersion(findVersion(buildGradle), currentVersion = "3.0.RC04")
|
||||
fail()// TODO setup as Object and test: compareWithCurrentVersion(findVersion(buildGradle), currentVersion = "3.0.RC04")
|
||||
|
||||
PowerMockito.verifyStatic(SP::class.java, times(1))
|
||||
SP.getLong(eq(R.string.key_last_versionchecker_warning), ArgumentMatchers.anyLong())
|
||||
|
@ -397,7 +398,7 @@ class VersionCheckerUtilsKtTest {
|
|||
| appName = "Aaoeu"
|
||||
""".trimMargin()
|
||||
prepareMainApp()
|
||||
compareWithCurrentVersion(findVersion(buildGradle), currentVersion = "3.7.9")
|
||||
fail()// TODO setup as Object and test: compareWithCurrentVersion(findVersion(buildGradle), currentVersion = "3.7.9")
|
||||
|
||||
PowerMockito.verifyStatic(SP::class.java, times(1))
|
||||
SP.getLong(eq(R.string.key_last_versionchecker_warning), ArgumentMatchers.anyLong())
|
||||
|
@ -417,7 +418,7 @@ class VersionCheckerUtilsKtTest {
|
|||
| appName = "Aaoeu"
|
||||
""".trimMargin()
|
||||
prepareMainApp()
|
||||
compareWithCurrentVersion(findVersion(buildGradle), currentVersion = "2.3")
|
||||
fail()// TODO setup as Object and test: compareWithCurrentVersion(findVersion(buildGradle), currentVersion = "2.3")
|
||||
|
||||
//verify(bus, times(0)).post(any())
|
||||
|
||||
|
@ -437,7 +438,7 @@ class VersionCheckerUtilsKtTest {
|
|||
| appName = "Aaoeu"
|
||||
""".trimMargin()
|
||||
prepareMainApp()
|
||||
compareWithCurrentVersion(findVersion(buildGradle), currentVersion = "2.3-RC")
|
||||
fail()// TODO setup as Object and test: compareWithCurrentVersion(findVersion(buildGradle), currentVersion = "2.3-RC")
|
||||
|
||||
//verify(bus, times(0)).post(any())
|
||||
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.general.automation.triggers;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
|
||||
public class DummyTrigger extends Trigger {
|
||||
private boolean result;
|
||||
|
||||
public DummyTrigger() {
|
||||
this.result = false;
|
||||
}
|
||||
|
||||
public DummyTrigger(boolean result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRun() {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toJSON() { return null; }
|
||||
|
||||
@Override
|
||||
Trigger fromJSON(String data) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int friendlyName() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String friendlyDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Integer> icon() {
|
||||
return Optional.absent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executed(long time) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Trigger duplicate() { return new DummyTrigger(result); }
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package info.nightscout.androidaps.plugins.general.automation.triggers
|
||||
|
||||
import com.google.common.base.Optional
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.HasAndroidInjector
|
||||
|
||||
class DummyTrigger(var result: Boolean) : Trigger(HasAndroidInjector { AndroidInjector { } }) {
|
||||
|
||||
override fun shouldRun(): Boolean {
|
||||
return result
|
||||
}
|
||||
|
||||
override fun toJSON(): String {
|
||||
return ""
|
||||
}
|
||||
|
||||
override fun fromJSON(data: String): Trigger {
|
||||
return DummyTrigger(result)
|
||||
}
|
||||
|
||||
override fun friendlyName(): Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
override fun friendlyDescription(): String {
|
||||
return " "
|
||||
}
|
||||
|
||||
override fun icon(): Optional<Int?> {
|
||||
return Optional.absent()
|
||||
}
|
||||
|
||||
override fun duplicate(): Trigger {
|
||||
return DummyTrigger(result)
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package info.nightscout.androidaps.plugins.insulin
|
||||
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
|
@ -36,10 +37,15 @@ class InsulinOrefFreePeakPluginTest {
|
|||
@Mock lateinit var resourceHelper: ResourceHelper
|
||||
@Mock lateinit var rxBus: RxBusWrapper
|
||||
@Mock lateinit var profileFunction: ProfileFunction
|
||||
@Mock lateinit var aapsLogger: AAPSLogger
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
sut = InsulinOrefFreePeakPlugin(sp, resourceHelper, rxBus, profileFunction)
|
||||
sut = InsulinOrefFreePeakPlugin(sp = sp,
|
||||
resourceHelper = resourceHelper,
|
||||
rxBus = rxBus,
|
||||
profileFunction = profileFunction,
|
||||
aapsLogger = aapsLogger)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package info.nightscout.androidaps.plugins.source
|
||||
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
|
@ -17,9 +18,11 @@ class GlimpPluginTest {
|
|||
|
||||
@Mock lateinit var aapsLogger: AAPSLogger
|
||||
|
||||
@Mock lateinit var resourceHelper: ResourceHelper
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
glimpPlugin = GlimpPlugin(aapsLogger)
|
||||
glimpPlugin = GlimpPlugin(resourceHelper, aapsLogger)
|
||||
}
|
||||
|
||||
@Test fun advancedFilteringSupported() {
|
||||
|
|
Loading…
Reference in a new issue