Skip to content

Instantly share code, notes, and snippets.

@holysheep
Created June 2, 2018 04:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save holysheep/7bca6c7a34f4c45a9baaa33f40b6901e to your computer and use it in GitHub Desktop.
Save holysheep/7bca6c7a34f4c45a9baaa33f40b6901e to your computer and use it in GitHub Desktop.
package im.dlg.push
import Update
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import java.io.File
import java.io.FileOutputStream
class UpdateNotificationTest {
private lateinit var tempFile: File
@get:Rule
private val temporaryFolder = TemporaryFolder()
@Before
fun setUp() {
val update = Update.VersionUpdate.newBuilder()
.apply {
version = "1.13.22"
storelink = "https://play.google.com/store/apps/details?id=im.dlg.app"
}
.build()
temporaryFolder.create()
tempFile = temporaryFolder.newFile("proto.txt")
FileOutputStream(tempFile).apply {
update.writeTo(this)
close()
}
}
@Test
fun deserializeUpdateNotificationProto() {
Update.VersionUpdate.parseFrom(tempFile.inputStream())
}
@Test
fun compareAppVersions() {
val versionUpdate = Update.VersionUpdate.parseFrom(tempFile.inputStream())
assert(!versionUpdate.version.isNullOrEmpty())
val userAppVersion = "1.13.21"
assert(versionUpdate.version > userAppVersion)
}
@After
fun tearDown() {
tempFile.delete()
assert(!tempFile.exists())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment