From 9be0ffffa9f37274c22833f1c112fb1ffd260277 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Wed, 17 Apr 2019 21:28:32 +0200 Subject: [PATCH] verify static calls on mocked classes --- .../VersionCheckerUtilsKtTest.kt | 45 ++++++++++++++++++- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/versionChecker/VersionCheckerUtilsKtTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/versionChecker/VersionCheckerUtilsKtTest.kt index b1b62b589d..d711c4f958 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/versionChecker/VersionCheckerUtilsKtTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/versionChecker/VersionCheckerUtilsKtTest.kt @@ -63,24 +63,43 @@ class VersionCheckerUtilsKtTest { @PrepareForTest(MainApp::class, L::class, SP::class) fun `should find update1`() { val bus = prepareBus() + compareWithCurrentVersion(newVersion = "2.2.3", currentVersion = "2.2.1") + verify(bus, times(1)).post(any()) + + PowerMockito.verifyStatic(SP::class.java, times(1)) + SP.putLong(eq(R.string.key_new_version_available_since), ArgumentMatchers.anyLong()) + PowerMockito.verifyNoMoreInteractions(SP::class.java) + } @Test @PrepareForTest(MainApp::class, L::class, SP::class) fun `should find update2`() { val bus = prepareBus() + compareWithCurrentVersion(newVersion = "2.2.3", currentVersion = "2.2.1-dev") + verify(bus, times(1)).post(any()) + + PowerMockito.verifyStatic(SP::class.java, times(1)) + SP.putLong(eq(R.string.key_new_version_available_since), ArgumentMatchers.anyLong()) + PowerMockito.verifyNoMoreInteractions(SP::class.java) } @Test @PrepareForTest(MainApp::class, L::class, SP::class) fun `should find update3`() { val bus = prepareBus() + compareWithCurrentVersion(newVersion = "2.2.3", currentVersion = "2.1") + verify(bus, times(1)).post(any()) + + PowerMockito.verifyStatic(SP::class.java, times(1)) + SP.putLong(eq(R.string.key_new_version_available_since), ArgumentMatchers.anyLong()) + PowerMockito.verifyNoMoreInteractions(SP::class.java) } @Test @@ -91,6 +110,10 @@ class VersionCheckerUtilsKtTest { compareWithCurrentVersion(newVersion = "2.2", currentVersion = "2.1.1") verify(bus, times(1)).post(any()) + + PowerMockito.verifyStatic(SP::class.java, times(1)) + SP.putLong(eq(R.string.key_new_version_available_since), ArgumentMatchers.anyLong()) + PowerMockito.verifyNoMoreInteractions(SP::class.java) } @Test @@ -98,16 +121,25 @@ class VersionCheckerUtilsKtTest { fun `should find update5`() { val bus = prepareBus() compareWithCurrentVersion(newVersion = "2.2.1", currentVersion = "2.2-dev") + verify(bus, times(1)).post(any()) + + PowerMockito.verifyStatic(SP::class.java, times(1)) + SP.putLong(eq(R.string.key_new_version_available_since), ArgumentMatchers.anyLong()) + PowerMockito.verifyNoMoreInteractions(SP::class.java) } @Test @PrepareForTest(MainApp::class, L::class, SP::class) fun `should find update6`() { val bus = prepareBus() - val sp = prepareSP() compareWithCurrentVersion(newVersion = "2.2.1", currentVersion = "2.2dev") + verify(bus, times(1)).post(any()) + + PowerMockito.verifyStatic(SP::class.java, times(1)) + SP.putLong(eq(R.string.key_new_version_available_since), ArgumentMatchers.anyLong()) + PowerMockito.verifyNoMoreInteractions(SP::class.java) } @Test @@ -122,8 +154,12 @@ class VersionCheckerUtilsKtTest { """.trimMargin() val bus = prepareBus() compareWithCurrentVersion(buildGradle.byteInputStream().findVersion(), currentVersion = "2.2.2") + verify(bus, times(0)).post(any()) - verify(SP, times(1)).remove(R.string.key_new_version_available_since) + + PowerMockito.verifyStatic(SP::class.java, times(1)) + SP.remove(eq(R.string.key_new_version_available_since)) + PowerMockito.verifyNoMoreInteractions(SP::class.java) } @Test @@ -138,7 +174,12 @@ class VersionCheckerUtilsKtTest { """.trimMargin() val bus = prepareBus() compareWithCurrentVersion(buildGradle.byteInputStream().findVersion(), currentVersion = "2.2.2") + verify(bus, times(1)).post(any()) + + PowerMockito.verifyStatic(SP::class.java, times(1)) + SP.putLong(eq(R.string.key_new_version_available_since), ArgumentMatchers.anyLong()) + PowerMockito.verifyNoMoreInteractions(SP::class.java) }