# HG changeset patch # User Da Risk # Date 1633550747 14400 # Node ID 3ccb29f8330965c13809c77587671ff0e0acdc36 # Parent e395df7aa39f6490718e1a2836526e809c4cfc82 build: update to robolectric 4.6.1 diff -r e395df7aa39f -r 3ccb29f83309 buildSrc/src/main/kotlin/AndroidTests.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 { 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 { diff -r e395df7aa39f -r 3ccb29f83309 geekdroid/src/test/java/com/geekorum/geekdroid/battery/LiveDataTest.kt --- 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>(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>(relaxed = true) liveData.observeForever(mockObserver) application.sendBroadcast(Intent(Intent.ACTION_BATTERY_OKAY)) + shadowOf(getMainLooper()).idle() verifySequence { // first battery is okay mockObserver.onChanged(false)