Merge pull request #1734 from jotomo/zoidberg-physical
Zoidberg physical
This commit is contained in:
commit
469ea2d1f4
2 changed files with 46 additions and 10 deletions
|
@ -24,16 +24,12 @@ fun isConnected(): Boolean {
|
|||
// convert inputstream to String
|
||||
@Throws(IOException::class)
|
||||
fun InputStream.findVersion(): String? {
|
||||
var version: String? = null
|
||||
val regex = "(.*)version(.*)\"(((\\d+)\\.)+(\\d+))\"(.*)"
|
||||
|
||||
this.bufferedReader().forEachLine {
|
||||
if (regex.toRegex().matches(it)) {
|
||||
version = regex.toRegex().matchEntire(it)?.groupValues?.getOrNull(3)
|
||||
return@forEachLine
|
||||
}
|
||||
}
|
||||
return version
|
||||
val regex = "(.*)version(.*)\"(((\\d+)\\.)+(\\d+))\"(.*)".toRegex()
|
||||
return bufferedReader()
|
||||
.readLines()
|
||||
.filter { regex.matches(it) }
|
||||
.mapNotNull { regex.matchEntire(it)?.groupValues?.getOrNull(3) }
|
||||
.firstOrNull()
|
||||
}
|
||||
|
||||
private val log = LoggerFactory.getLogger(L.CORE)
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
package info.nightscout.androidaps.plugins.general.versionChecker
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
class VersionCheckerUtilsKtTest {
|
||||
@Test
|
||||
fun findVersionMatchesRegularVersion() {
|
||||
val buildGradle = """blabla
|
||||
| android {
|
||||
| aosenuthoae
|
||||
| }
|
||||
| version = "2.2.2"
|
||||
| appName = "Aaoeu"
|
||||
""".trimMargin()
|
||||
val detectedVersion: String? = buildGradle.byteInputStream().findVersion()
|
||||
assertEquals("2.2.2", detectedVersion)
|
||||
}
|
||||
|
||||
// 04. Break stuff.mp3 like it's 1999. Again. Pizza delivery! For i c wiener ...
|
||||
//@Test
|
||||
fun findVersionMatchesCustomVersion() {
|
||||
val buildGradle = """blabla
|
||||
| android {
|
||||
| aosenuthoae
|
||||
| }
|
||||
| version = "2.2.2-nefarious-underground-mod"
|
||||
| appName = "Aaoeu"
|
||||
""".trimMargin()
|
||||
val detectedVersion: String? = buildGradle.byteInputStream().findVersion()
|
||||
assertEquals("2.2.2", detectedVersion)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun findVersionMatchesDoesNotMatchErrorResponse() {
|
||||
val buildGradle = """<html><body>Balls! No build.gradle here. Move along</body><html>"""
|
||||
val detectedVersion: String? = buildGradle.byteInputStream().findVersion()
|
||||
assertEquals(null, detectedVersion)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue