Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9b54f10c authored by Jacky Wang's avatar Jacky Wang
Browse files

[Catalyst] Allow null client for MessengerServiceRule

Bug: 338916345
Flag: TEST_ONLY
Test: atest
Change-Id: Id16cf4d2337e3fbb736c2c813c75deb08a1ade46
parent 8d4fa82b
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -35,13 +35,16 @@ import org.robolectric.android.controller.ServiceController
/** Rule for messenger service testing. */
open class MessengerServiceRule<C : MessengerServiceClient>(
    private val serviceClass: Class<out MessengerService>,
    val client: C,
    private val nullableClient: C? = null,
) : TestWatcher() {
    val application: Application = ApplicationProvider.getApplicationContext()
    val isRobolectric = Build.FINGERPRINT.contains("robolectric")

    private var serviceController: ServiceController<out Service>? = null

    val client: C
        get() = nullableClient!!

    init {
        if (isRobolectric) {
            // `starting` is invoked by `startingQuietly`, which swallows exception. Hence we must
@@ -59,7 +62,7 @@ open class MessengerServiceRule<C : MessengerServiceClient>(
    }

    override fun finished(description: Description) {
        client.close()
        nullableClient?.close()
        if (isRobolectric) {
            runBlocking {
                withContext(Dispatchers.Main) { serviceController?.run { unbind().destroy() } }