Merge branch 'dagger3' into dagger3-0111a
This commit is contained in:
commit
1c2036d1a3
3 changed files with 113 additions and 89 deletions
|
@ -118,6 +118,10 @@ class VersionCheckerUtils @Inject constructor() {
|
|||
private fun String?.toNumberList() =
|
||||
this?.numericVersionPart().takeIf { !it.isNullOrBlank() }?.split(".")?.map { it.toInt() }
|
||||
|
||||
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)
|
||||
|
|
|
@ -1,86 +1,110 @@
|
|||
package info.nightscout.androidaps.plugins.constraints.versionChecker
|
||||
|
||||
import android.content.Context
|
||||
import info.nightscout.androidaps.MainApp
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.logging.L
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||
import info.nightscout.androidaps.utils.SP
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.fail
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.ArgumentMatchers
|
||||
import org.mockito.Mockito.*
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito.`when`
|
||||
import org.mockito.Mockito.any
|
||||
import org.mockito.Mockito.eq
|
||||
import org.mockito.Mockito.mock
|
||||
import org.mockito.Mockito.times
|
||||
import org.mockito.junit.MockitoJUnit
|
||||
import org.mockito.junit.MockitoRule
|
||||
import org.powermock.api.mockito.PowerMockito
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest
|
||||
import org.powermock.modules.junit4.PowerMockRunner
|
||||
|
||||
|
||||
@RunWith(PowerMockRunner::class)
|
||||
class VersionCheckerUtilsKtTest {
|
||||
|
||||
|
||||
@get:Rule
|
||||
val mockitoRule: MockitoRule = MockitoJUnit.rule()
|
||||
|
||||
@Test
|
||||
fun `should keep 2 digit version`() {
|
||||
assertEquals("1.2", "1.2".numericVersionPart())
|
||||
lateinit var versionCheckerUtils: VersionCheckerUtils
|
||||
|
||||
@Mock lateinit var aapsLogger: AAPSLogger
|
||||
@Mock lateinit var sp: info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||
@Mock lateinit var resourceHelper: ResourceHelper
|
||||
@Mock lateinit var rxBusWrapper: RxBusWrapper
|
||||
@Mock lateinit var context: Context
|
||||
|
||||
@Before fun setup() {
|
||||
versionCheckerUtils = VersionCheckerUtils()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should keep 3 digit version`() {
|
||||
assertEquals("1.2.3", "1.2.3".numericVersionPart())
|
||||
}
|
||||
/*
|
||||
@Test
|
||||
fun `should keep 2 digit version`() {
|
||||
assertEquals("1.2", "1.2".numericVersionPart())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should keep 4 digit version`() {
|
||||
assertEquals("1.2.3.4", "1.2.3.4".numericVersionPart())
|
||||
}
|
||||
@Test
|
||||
fun `should keep 3 digit version`() {
|
||||
assertEquals("1.2.3", "1.2.3".numericVersionPart())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should strip 2 digit version RC`() {
|
||||
assertEquals("1.2", "1.2-RC1".numericVersionPart())
|
||||
}
|
||||
@Test
|
||||
fun `should keep 4 digit version`() {
|
||||
assertEquals("1.2.3.4", "1.2.3.4".numericVersionPart())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should strip 2 digit version RC old format`() {
|
||||
assertEquals("1.2", "1.2RC1".numericVersionPart())
|
||||
}
|
||||
@Test
|
||||
fun `should strip 2 digit version RC`() {
|
||||
assertEquals("1.2", "1.2-RC1".numericVersionPart())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should strip 2 digit version RC without digit`() {
|
||||
assertEquals("1.2", "1.2-RC".numericVersionPart())
|
||||
}
|
||||
@Test
|
||||
fun `should strip 2 digit version RC old format`() {
|
||||
assertEquals("1.2", "1.2RC1".numericVersionPart())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should strip 2 digit version dev`() {
|
||||
assertEquals("1.2", "1.2-dev".numericVersionPart())
|
||||
}
|
||||
@Test
|
||||
fun `should strip 2 digit version RC without digit`() {
|
||||
assertEquals("1.2", "1.2-RC".numericVersionPart())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should strip 2 digit version dev old format 1`() {
|
||||
assertEquals("1.2", "1.2dev".numericVersionPart())
|
||||
}
|
||||
@Test
|
||||
fun `should strip 2 digit version dev`() {
|
||||
assertEquals("1.2", "1.2-dev".numericVersionPart())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should strip 2 digit version dev old format 2`() {
|
||||
assertEquals("1.2", "1.2dev-a3".numericVersionPart())
|
||||
}
|
||||
@Test
|
||||
fun `should strip 2 digit version dev old format 1`() {
|
||||
assertEquals("1.2", "1.2dev".numericVersionPart())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should strip 3 digit version RC`() {
|
||||
assertEquals("1.2.3", "1.2.3-RC1".numericVersionPart())
|
||||
}
|
||||
@Test
|
||||
fun `should strip 2 digit version dev old format 2`() {
|
||||
assertEquals("1.2", "1.2dev-a3".numericVersionPart())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should strip 4 digit version RC`() {
|
||||
assertEquals("1.2.3.4", "1.2.3.4-RC5".numericVersionPart())
|
||||
}
|
||||
@Test
|
||||
fun `should strip 3 digit version RC`() {
|
||||
assertEquals("1.2.3", "1.2.3-RC1".numericVersionPart())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should strip even with dot`() {
|
||||
assertEquals("1.2", "1.2.RC5".numericVersionPart())
|
||||
}
|
||||
@Test
|
||||
fun `should strip 4 digit version RC`() {
|
||||
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())
|
||||
}
|
||||
|
||||
*/
|
||||
@Test
|
||||
fun findVersionMatchesRegularVersion() {
|
||||
val buildGradle = """blabla
|
||||
|
@ -90,11 +114,10 @@ class VersionCheckerUtilsKtTest {
|
|||
| version = "2.2.2"
|
||||
| appName = "Aaoeu"
|
||||
""".trimMargin()
|
||||
val detectedVersion: String? = findVersion(buildGradle)
|
||||
val detectedVersion: String? = versionCheckerUtils.findVersion(buildGradle)
|
||||
assertEquals("2.2.2", detectedVersion)
|
||||
}
|
||||
|
||||
|
||||
// In case we merge a "x.x.x-dev" into master, don't see it as update.
|
||||
@Test
|
||||
fun `should return null on non-digit versions on master`() {
|
||||
|
@ -105,31 +128,32 @@ class VersionCheckerUtilsKtTest {
|
|||
| version = "2.2.2-nefarious-underground-mod"
|
||||
| appName = "Aaoeu"
|
||||
""".trimMargin()
|
||||
val detectedVersion: String? = findVersion(buildGradle)
|
||||
val detectedVersion: String? = versionCheckerUtils.findVersion(buildGradle)
|
||||
assertEquals(null, detectedVersion)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun findVersionMatchesDoesNotMatchErrorResponse() {
|
||||
val buildGradle = """<html><body>Balls! No build.gradle here. Move along</body><html>"""
|
||||
val detectedVersion: String? = findVersion(buildGradle)
|
||||
val detectedVersion: String? = versionCheckerUtils.findVersion(buildGradle)
|
||||
assertEquals(null, detectedVersion)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testVersionStrip() {
|
||||
assertEquals("2.2.2", "2.2.2".versionStrip())
|
||||
assertEquals("2.2.2", "2.2.2-dev".versionStrip())
|
||||
assertEquals("2.2.2", "2.2.2dev".versionStrip())
|
||||
assertEquals("2.2.2", """"2.2.2"""".versionStrip())
|
||||
}
|
||||
|
||||
/*
|
||||
@Test
|
||||
fun testVersionStrip() {
|
||||
assertEquals("2.2.2", "2.2.2".versionStrip())
|
||||
assertEquals("2.2.2", "2.2.2-dev".versionStrip())
|
||||
assertEquals("2.2.2", "2.2.2dev".versionStrip())
|
||||
assertEquals("2.2.2", """"2.2.2"""".versionStrip())
|
||||
}
|
||||
*/
|
||||
@Test
|
||||
@PrepareForTest(MainApp::class, L::class, SP::class)
|
||||
fun `should find update1`() {
|
||||
prepareMainApp()
|
||||
|
||||
fail()// TODO setup as Object and test: compareWithCurrentVersion(newVersion = "2.2.3", currentVersion = "2.2.1")
|
||||
versionCheckerUtils.compareWithCurrentVersion(newVersion = "2.2.3", currentVersion = "2.2.1")
|
||||
|
||||
//verify(bus, times(1)).post(any())
|
||||
|
||||
|
@ -146,7 +170,7 @@ class VersionCheckerUtilsKtTest {
|
|||
fun `should find update2`() {
|
||||
prepareMainApp()
|
||||
|
||||
fail()// TODO setup as Object and test: compareWithCurrentVersion(newVersion = "2.2.3", currentVersion = "2.2.1-dev")
|
||||
versionCheckerUtils.compareWithCurrentVersion(newVersion = "2.2.3", currentVersion = "2.2.1-dev")
|
||||
|
||||
//verify(bus, times(1)).post(any())
|
||||
|
||||
|
@ -162,7 +186,7 @@ class VersionCheckerUtilsKtTest {
|
|||
fun `should find update3`() {
|
||||
prepareMainApp()
|
||||
|
||||
fail()// TODO setup as Object and test: compareWithCurrentVersion(newVersion = "2.2.3", currentVersion = "2.1")
|
||||
versionCheckerUtils.compareWithCurrentVersion(newVersion = "2.2.3", currentVersion = "2.1")
|
||||
|
||||
//verify(bus, times(1)).post(any())
|
||||
|
||||
|
@ -178,7 +202,7 @@ class VersionCheckerUtilsKtTest {
|
|||
fun `should find update4`() {
|
||||
prepareMainApp()
|
||||
|
||||
fail()// TODO setup as Object and test: compareWithCurrentVersion(newVersion = "2.2", currentVersion = "2.1.1")
|
||||
versionCheckerUtils.compareWithCurrentVersion(newVersion = "2.2", currentVersion = "2.1.1")
|
||||
|
||||
//verify(bus, times(1)).post(any())
|
||||
|
||||
|
@ -193,7 +217,7 @@ class VersionCheckerUtilsKtTest {
|
|||
@PrepareForTest(MainApp::class, L::class, SP::class)
|
||||
fun `should find update5`() {
|
||||
prepareMainApp()
|
||||
fail()// TODO setup as Object and test: compareWithCurrentVersion(newVersion = "2.2.1", currentVersion = "2.2-dev")
|
||||
versionCheckerUtils.compareWithCurrentVersion(newVersion = "2.2.1", currentVersion = "2.2-dev")
|
||||
|
||||
//verify(bus, times(1)).post(any())
|
||||
|
||||
|
@ -208,7 +232,7 @@ class VersionCheckerUtilsKtTest {
|
|||
@PrepareForTest(MainApp::class, L::class, SP::class)
|
||||
fun `should find update6`() {
|
||||
prepareMainApp()
|
||||
fail()// TODO setup as Object and test: compareWithCurrentVersion(newVersion = "2.2.1", currentVersion = "2.2dev")
|
||||
versionCheckerUtils.compareWithCurrentVersion(newVersion = "2.2.1", currentVersion = "2.2dev")
|
||||
|
||||
//verify(bus, times(1)).post(any())
|
||||
|
||||
|
@ -223,7 +247,7 @@ class VersionCheckerUtilsKtTest {
|
|||
@PrepareForTest(MainApp::class, L::class, SP::class)
|
||||
fun `should not find update on fourth version digit`() {
|
||||
prepareMainApp()
|
||||
fail()// TODO setup as Object and test: compareWithCurrentVersion(newVersion = "2.5.0", currentVersion = "2.5.0.1")
|
||||
versionCheckerUtils.compareWithCurrentVersion(newVersion = "2.5.0", currentVersion = "2.5.0.1")
|
||||
|
||||
//verify(bus, times(0)).post(any())
|
||||
|
||||
|
@ -234,9 +258,9 @@ class VersionCheckerUtilsKtTest {
|
|||
|
||||
@Test
|
||||
@PrepareForTest(MainApp::class, L::class, SP::class)
|
||||
fun `should not find update on personal version with same number` (){
|
||||
fun `should not find update on personal version with same number`() {
|
||||
prepareMainApp()
|
||||
fail()// TODO setup as Object and test: compareWithCurrentVersion(newVersion = "2.5.0", currentVersion = "2.5.0-myversion")
|
||||
versionCheckerUtils.compareWithCurrentVersion(newVersion = "2.5.0", currentVersion = "2.5.0-myversion")
|
||||
|
||||
//verify(bus, times(0)).post(any())
|
||||
|
||||
|
@ -245,7 +269,6 @@ class VersionCheckerUtilsKtTest {
|
|||
PowerMockito.verifyNoMoreInteractions(SP::class.java)
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@PrepareForTest(MainApp::class, L::class, SP::class)
|
||||
fun `find same version`() {
|
||||
|
@ -257,7 +280,7 @@ class VersionCheckerUtilsKtTest {
|
|||
| appName = "Aaoeu"
|
||||
""".trimMargin()
|
||||
prepareMainApp()
|
||||
fail()// TODO setup as Object and test: compareWithCurrentVersion(findVersion(buildGradle), currentVersion = "2.2.2")
|
||||
versionCheckerUtils.compareWithCurrentVersion(versionCheckerUtils.findVersion(buildGradle), currentVersion = "2.2.2")
|
||||
|
||||
//verify(bus, times(0)).post(any())
|
||||
|
||||
|
@ -277,7 +300,7 @@ class VersionCheckerUtilsKtTest {
|
|||
| appName = "Aaoeu"
|
||||
""".trimMargin()
|
||||
prepareMainApp()
|
||||
fail()// TODO setup as Object and test: compareWithCurrentVersion(findVersion(buildGradle), currentVersion = "2.2.2")
|
||||
versionCheckerUtils.compareWithCurrentVersion(versionCheckerUtils.findVersion(buildGradle), currentVersion = "2.2.2")
|
||||
|
||||
PowerMockito.verifyStatic(SP::class.java, times(1))
|
||||
SP.getLong(eq(R.string.key_last_versionchecker_warning), ArgumentMatchers.anyLong())
|
||||
|
@ -286,7 +309,6 @@ class VersionCheckerUtilsKtTest {
|
|||
PowerMockito.verifyNoMoreInteractions(SP::class.java)
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@PrepareForTest(MainApp::class, L::class, SP::class)
|
||||
fun `find higher version with longer number`() {
|
||||
|
@ -298,7 +320,7 @@ class VersionCheckerUtilsKtTest {
|
|||
| appName = "Aaoeu"
|
||||
""".trimMargin()
|
||||
prepareMainApp()
|
||||
fail()// TODO setup as Object and test: compareWithCurrentVersion(findVersion(buildGradle), currentVersion = "2.2.2")
|
||||
versionCheckerUtils.compareWithCurrentVersion(versionCheckerUtils.findVersion(buildGradle), currentVersion = "2.2.2")
|
||||
|
||||
PowerMockito.verifyStatic(SP::class.java, times(1))
|
||||
SP.getLong(eq(R.string.key_last_versionchecker_warning), ArgumentMatchers.anyLong())
|
||||
|
@ -318,7 +340,7 @@ class VersionCheckerUtilsKtTest {
|
|||
| appName = "Aaoeu"
|
||||
""".trimMargin()
|
||||
prepareMainApp()
|
||||
fail()// TODO setup as Object and test: compareWithCurrentVersion(findVersion(buildGradle), currentVersion = "3.0-RC04")
|
||||
versionCheckerUtils.compareWithCurrentVersion(versionCheckerUtils.findVersion(buildGradle), currentVersion = "3.0-RC04")
|
||||
|
||||
PowerMockito.verifyStatic(SP::class.java, times(1))
|
||||
SP.getLong(eq(R.string.key_last_versionchecker_warning), ArgumentMatchers.anyLong())
|
||||
|
@ -338,7 +360,7 @@ class VersionCheckerUtilsKtTest {
|
|||
| appName = "Aaoeu"
|
||||
""".trimMargin()
|
||||
prepareMainApp()
|
||||
fail()// TODO setup as Object and test: compareWithCurrentVersion(findVersion(buildGradle), currentVersion = "3.0RC04")
|
||||
versionCheckerUtils.compareWithCurrentVersion(versionCheckerUtils.findVersion(buildGradle), currentVersion = "3.0RC04")
|
||||
|
||||
PowerMockito.verifyStatic(SP::class.java, times(1))
|
||||
SP.getLong(eq(R.string.key_last_versionchecker_warning), ArgumentMatchers.anyLong())
|
||||
|
@ -358,7 +380,7 @@ class VersionCheckerUtilsKtTest {
|
|||
| appName = "Aaoeu"
|
||||
""".trimMargin()
|
||||
prepareMainApp()
|
||||
fail()// TODO setup as Object and test: compareWithCurrentVersion(findVersion(buildGradle), currentVersion = "3.RC04")
|
||||
versionCheckerUtils.compareWithCurrentVersion(versionCheckerUtils.findVersion(buildGradle), currentVersion = "3.RC04")
|
||||
|
||||
PowerMockito.verifyStatic(SP::class.java, times(1))
|
||||
SP.getLong(eq(R.string.key_last_versionchecker_warning), ArgumentMatchers.anyLong())
|
||||
|
@ -378,7 +400,7 @@ class VersionCheckerUtilsKtTest {
|
|||
| appName = "Aaoeu"
|
||||
""".trimMargin()
|
||||
prepareMainApp()
|
||||
fail()// TODO setup as Object and test: compareWithCurrentVersion(findVersion(buildGradle), currentVersion = "3.0.RC04")
|
||||
versionCheckerUtils.compareWithCurrentVersion(versionCheckerUtils.findVersion(buildGradle), currentVersion = "3.0.RC04")
|
||||
|
||||
PowerMockito.verifyStatic(SP::class.java, times(1))
|
||||
SP.getLong(eq(R.string.key_last_versionchecker_warning), ArgumentMatchers.anyLong())
|
||||
|
@ -398,7 +420,7 @@ class VersionCheckerUtilsKtTest {
|
|||
| appName = "Aaoeu"
|
||||
""".trimMargin()
|
||||
prepareMainApp()
|
||||
fail()// TODO setup as Object and test: compareWithCurrentVersion(findVersion(buildGradle), currentVersion = "3.7.9")
|
||||
versionCheckerUtils.compareWithCurrentVersion(versionCheckerUtils.findVersion(buildGradle), currentVersion = "3.7.9")
|
||||
|
||||
PowerMockito.verifyStatic(SP::class.java, times(1))
|
||||
SP.getLong(eq(R.string.key_last_versionchecker_warning), ArgumentMatchers.anyLong())
|
||||
|
@ -418,7 +440,7 @@ class VersionCheckerUtilsKtTest {
|
|||
| appName = "Aaoeu"
|
||||
""".trimMargin()
|
||||
prepareMainApp()
|
||||
fail()// TODO setup as Object and test: compareWithCurrentVersion(findVersion(buildGradle), currentVersion = "2.3")
|
||||
versionCheckerUtils.compareWithCurrentVersion(versionCheckerUtils.findVersion(buildGradle), currentVersion = "2.3")
|
||||
|
||||
//verify(bus, times(0)).post(any())
|
||||
|
||||
|
@ -438,7 +460,7 @@ class VersionCheckerUtilsKtTest {
|
|||
| appName = "Aaoeu"
|
||||
""".trimMargin()
|
||||
prepareMainApp()
|
||||
fail()// TODO setup as Object and test: compareWithCurrentVersion(findVersion(buildGradle), currentVersion = "2.3-RC")
|
||||
versionCheckerUtils.compareWithCurrentVersion(versionCheckerUtils.findVersion(buildGradle), currentVersion = "2.3-RC")
|
||||
|
||||
//verify(bus, times(0)).post(any())
|
||||
|
||||
|
@ -447,9 +469,6 @@ class VersionCheckerUtilsKtTest {
|
|||
PowerMockito.verifyNoMoreInteractions(SP::class.java)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
@PrepareForTest(System::class)
|
||||
fun `set time`() {
|
||||
|
|
|
@ -6,7 +6,7 @@ import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
|||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||
import junit.framework.Assert.assertEquals
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
|
@ -62,6 +62,7 @@ class InsulinOrefFreePeakPluginTest {
|
|||
return uninitialized()
|
||||
}
|
||||
|
||||
@Suppress("Unchecked_Cast")
|
||||
private fun <T> uninitialized(): T = null as T
|
||||
|
||||
}
|
Loading…
Reference in a new issue