Update Tests for new versioning

This commit is contained in:
AdrianLxM 2019-10-31 08:20:00 +01:00 committed by GitHub
parent 1ab004a39e
commit d2b059fd6b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -16,6 +16,70 @@ import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class)
class VersionCheckerUtilsKtTest {
@Test
fun `should keep 2 digit version`() {
assertEquals("1.2", "1.2".numericVersionPart())
}
@Test
fun `should keep 3 digit version`() {
assertEquals("1.2.3", "1.2.3".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`() {
assertEquals("1.2", "1.2-RC1".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 without digit`() {
assertEquals("1.2", "1.2-RC".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 1`() {
assertEquals("1.2", "1.2dev".numericVersionPart())
}
@Test
fun `should strip 2 digit version dev old format 2`() {
assertEquals("1.2", "1.2dev-a3".numericVersionPart())
}
@Test
fun `should strip 3 digit version RC`() {
assertEquals("1.2.3", "1.2.3-RC1".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
@ -154,6 +218,33 @@ class VersionCheckerUtilsKtTest {
PowerMockito.verifyNoMoreInteractions(SP::class.java)
}
@Test
@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")
//verify(bus, times(0)).post(any())
PowerMockito.verifyStatic(SP::class.java, times(1))
SP.putLong(eq(R.string.key_last_time_this_version_detected), ArgumentMatchers.anyLong())
PowerMockito.verifyNoMoreInteractions(SP::class.java)
}
@Test
@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")
//verify(bus, times(0)).post(any())
PowerMockito.verifyStatic(SP::class.java, times(1))
SP.putLong(eq(R.string.key_last_time_this_version_detected), ArgumentMatchers.anyLong())
PowerMockito.verifyNoMoreInteractions(SP::class.java)
}
@Test
@PrepareForTest(MainApp::class, L::class, SP::class)
fun `find same version`() {
@ -177,6 +268,27 @@ class VersionCheckerUtilsKtTest {
@Test
@PrepareForTest(MainApp::class, L::class, SP::class)
fun `find higher version`() {
val buildGradle = """blabla
| android {
| aosenuthoae
| }
| version = "3.0.0"
| appName = "Aaoeu"
""".trimMargin()
prepareMainApp()
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())
PowerMockito.verifyStatic(SP::class.java, times(1))
SP.putLong(eq(R.string.key_last_versionchecker_warning), ArgumentMatchers.anyLong())
PowerMockito.verifyNoMoreInteractions(SP::class.java)
}
@Test
@PrepareForTest(MainApp::class, L::class, SP::class)
fun `find higher version with longer number`() {
val buildGradle = """blabla
| android {
| aosenuthoae
@ -194,6 +306,148 @@ class VersionCheckerUtilsKtTest {
PowerMockito.verifyNoMoreInteractions(SP::class.java)
}
@Test
@PrepareForTest(MainApp::class, L::class, SP::class)
fun `find higher version after RC`() {
val buildGradle = """blabla
| android {
| aosenuthoae
| }
| version = "3.0.0"
| appName = "Aaoeu"
""".trimMargin()
prepareMainApp()
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())
PowerMockito.verifyStatic(SP::class.java, times(1))
SP.putLong(eq(R.string.key_last_versionchecker_warning), ArgumentMatchers.anyLong())
PowerMockito.verifyNoMoreInteractions(SP::class.java)
}
@Test
@PrepareForTest(MainApp::class, L::class, SP::class)
fun `find higher version after RC 2 - typo`() {
val buildGradle = """blabla
| android {
| aosenuthoae
| }
| version = "3.0.0"
| appName = "Aaoeu"
""".trimMargin()
prepareMainApp()
compareWithCurrentVersion(findVersion(buildGradle), currentVersion = "3.0RC04")
PowerMockito.verifyStatic(SP::class.java, times(1))
SP.getLong(eq(R.string.key_last_versionchecker_warning), ArgumentMatchers.anyLong())
PowerMockito.verifyStatic(SP::class.java, times(1))
SP.putLong(eq(R.string.key_last_versionchecker_warning), ArgumentMatchers.anyLong())
PowerMockito.verifyNoMoreInteractions(SP::class.java)
}
@Test
@PrepareForTest(MainApp::class, L::class, SP::class)
fun `find higher version after RC 3 - typo`() {
val buildGradle = """blabla
| android {
| aosenuthoae
| }
| version = "3.0.0"
| appName = "Aaoeu"
""".trimMargin()
prepareMainApp()
compareWithCurrentVersion(findVersion(buildGradle), currentVersion = "3.RC04")
PowerMockito.verifyStatic(SP::class.java, times(1))
SP.getLong(eq(R.string.key_last_versionchecker_warning), ArgumentMatchers.anyLong())
PowerMockito.verifyStatic(SP::class.java, times(1))
SP.putLong(eq(R.string.key_last_versionchecker_warning), ArgumentMatchers.anyLong())
PowerMockito.verifyNoMoreInteractions(SP::class.java)
}
@Test
@PrepareForTest(MainApp::class, L::class, SP::class)
fun `find higher version after RC 4 - typo`() {
val buildGradle = """blabla
| android {
| aosenuthoae
| }
| version = "3.0.0"
| appName = "Aaoeu"
""".trimMargin()
prepareMainApp()
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())
PowerMockito.verifyStatic(SP::class.java, times(1))
SP.putLong(eq(R.string.key_last_versionchecker_warning), ArgumentMatchers.anyLong())
PowerMockito.verifyNoMoreInteractions(SP::class.java)
}
@Test
@PrepareForTest(MainApp::class, L::class, SP::class)
fun `find higher version on multi digit numbers`() {
val buildGradle = """blabla
| android {
| aosenuthoae
| }
| version = "3.7.12"
| appName = "Aaoeu"
""".trimMargin()
prepareMainApp()
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())
PowerMockito.verifyStatic(SP::class.java, times(1))
SP.putLong(eq(R.string.key_last_versionchecker_warning), ArgumentMatchers.anyLong())
PowerMockito.verifyNoMoreInteractions(SP::class.java)
}
@Test
@PrepareForTest(MainApp::class, L::class, SP::class)
fun `don't find higher version on higher but shorter version`() {
val buildGradle = """blabla
| android {
| aosenuthoae
| }
| version = "2.2.2"
| appName = "Aaoeu"
""".trimMargin()
prepareMainApp()
compareWithCurrentVersion(findVersion(buildGradle), currentVersion = "2.3")
//verify(bus, times(0)).post(any())
PowerMockito.verifyStatic(SP::class.java, times(1))
SP.putLong(eq(R.string.key_last_time_this_version_detected), ArgumentMatchers.anyLong())
PowerMockito.verifyNoMoreInteractions(SP::class.java)
}
@Test
@PrepareForTest(MainApp::class, L::class, SP::class)
fun `don't find higher version if on next RC`() {
val buildGradle = """blabla
| android {
| aosenuthoae
| }
| version = "2.2.2"
| appName = "Aaoeu"
""".trimMargin()
prepareMainApp()
compareWithCurrentVersion(findVersion(buildGradle), currentVersion = "2.3-RC")
//verify(bus, times(0)).post(any())
PowerMockito.verifyStatic(SP::class.java, times(1))
SP.putLong(eq(R.string.key_last_time_this_version_detected), ArgumentMatchers.anyLong())
PowerMockito.verifyNoMoreInteractions(SP::class.java)
}
@Test
@PrepareForTest(System::class)
@ -221,4 +475,4 @@ class VersionCheckerUtilsKtTest {
`when`(L.isEnabled(any())).thenReturn(true)
}
}
}