Merge pull request #1734 from jotomo/zoidberg-physical

Zoidberg physical
This commit is contained in:
AdrianLxM 2019-04-10 16:21:23 +02:00 committed by GitHub
commit 469ea2d1f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 10 deletions

View file

@ -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)

View file

@ -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)
}
}