build: update to robolectric 4.6.1
authorDa Risk <da_risk@geekorum.com>
Wed, 06 Oct 2021 16:05:47 -0400
changeset 18 3ccb29f83309
parent 17 e395df7aa39f
child 19 91a3ad3b1b9c
child 29 d9ad9e5c05fd
build: update to robolectric 4.6.1
buildSrc/src/main/kotlin/AndroidTests.kt
geekdroid/src/test/java/com/geekorum/geekdroid/battery/LiveDataTest.kt
--- a/buildSrc/src/main/kotlin/AndroidTests.kt	Wed Oct 06 15:22:05 2021 -0400
+++ b/buildSrc/src/main/kotlin/AndroidTests.kt	Wed Oct 06 16:05:47 2021 -0400
@@ -37,7 +37,7 @@
 const val espressoVersion = "3.2.0"
 const val androidxTestRunnerVersion = "1.3.0-alpha05"
 const val androidxTestCoreVersion = "1.3.0-alpha05"
-const val robolectricVersion = "4.3.1"
+const val robolectricVersion = "4.6.1"
 
 
 /*
@@ -47,8 +47,10 @@
     extensions.configure<BaseExtension> {
         defaultConfig {
             testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
-            testInstrumentationRunnerArgument("clearPackageData", "true")
-            testInstrumentationRunnerArgument("disableAnalytics", "true")
+            testInstrumentationRunnerArguments += mapOf(
+                "clearPackageData" to "true",
+                "disableAnalytics" to "true"
+            )
         }
 
         testOptions {
@@ -86,8 +88,8 @@
         dualTestImplementation("androidx.test.ext:truth:1.3.0-alpha01")
 
         // mock
-        testImplementation("io.mockk:mockk:1.9.3")
-        androidTestImplementation("io.mockk:mockk-android:1.9.3")
+        testImplementation("io.mockk:mockk:1.12.0")
+        androidTestImplementation("io.mockk:mockk-android:1.12.0")
         testImplementation("org.robolectric:robolectric:$robolectricVersion")
 
         constraints {
--- a/geekdroid/src/test/java/com/geekorum/geekdroid/battery/LiveDataTest.kt	Wed Oct 06 15:22:05 2021 -0400
+++ b/geekdroid/src/test/java/com/geekorum/geekdroid/battery/LiveDataTest.kt	Wed Oct 06 16:05:47 2021 -0400
@@ -25,6 +25,7 @@
 import android.content.Intent
 import android.os.BatteryManager
 import android.os.Build
+import android.os.Looper.getMainLooper
 import android.os.PowerManager
 import androidx.arch.core.executor.testing.InstantTaskExecutorRule
 import androidx.core.content.getSystemService
@@ -37,6 +38,7 @@
 import org.junit.Test
 import org.junit.runner.RunWith
 import org.robolectric.Shadows
+import org.robolectric.Shadows.shadowOf
 import org.robolectric.annotation.Config
 import org.robolectric.shadows.ShadowPowerManager
 import kotlin.test.BeforeTest
@@ -65,8 +67,10 @@
         liveData.observeForever(mockObserver)
         shadowPowerManager.setIsPowerSaveMode(true)
         application.sendBroadcast(Intent(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED))
+        shadowOf(getMainLooper()).idle()
         shadowPowerManager.setIsPowerSaveMode(false)
         application.sendBroadcast(Intent(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED))
+        shadowOf(getMainLooper()).idle()
         verifySequence {
             mockObserver.onChanged(false)
             mockObserver.onChanged(true)
@@ -96,6 +100,7 @@
         val mockObserver = mockk<Observer<Boolean>>(relaxed = true)
         liveData.observeForever(mockObserver)
         application.sendBroadcast(Intent(Intent.ACTION_BATTERY_LOW))
+        shadowOf(getMainLooper()).idle()
         verifySequence {
             // first battery is okay
             mockObserver.onChanged(false)
@@ -108,6 +113,7 @@
         val mockObserver = mockk<Observer<Boolean>>(relaxed = true)
         liveData.observeForever(mockObserver)
         application.sendBroadcast(Intent(Intent.ACTION_BATTERY_OKAY))
+        shadowOf(getMainLooper()).idle()
         verifySequence {
             // first battery is okay
             mockObserver.onChanged(false)