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

Commit b95a080d authored by Chaohui Wang's avatar Chaohui Wang
Browse files

Use androidx.arch.core InstantTaskExecutorRule

Bug: 260660819
Test: Unit test
Change-Id: Ia57018037244130f0d88eb4f6c0d4a86aae9353c
parent 493d0f3d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -18,12 +18,12 @@ package com.android.settingslib.spa.slice

import android.content.Context
import android.net.Uri
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import androidx.lifecycle.Observer
import androidx.slice.Slice
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.android.settingslib.spa.framework.common.createSettingsPage
import com.android.settingslib.spa.testutils.InstantTaskExecutorRule
import com.android.settingslib.spa.tests.testutils.SpaEnvironmentForTest
import com.android.settingslib.spa.tests.testutils.SppHome
import com.android.settingslib.spa.tests.testutils.SppLayer2
+1 −1
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ android_library {
    srcs: ["src/**/*.kt"],

    static_libs: [
        "androidx.arch.core_core-runtime",
        "androidx.arch.core_core-testing",
        "androidx.compose.ui_ui-test-junit4",
        "androidx.compose.ui_ui-test-manifest",
        "mockito",
+1 −1
Original line number Diff line number Diff line
@@ -47,7 +47,7 @@ android {
}

dependencies {
    api "androidx.arch.core:core-runtime:2.1.0"
    api "androidx.arch.core:core-testing:2.1.0"
    api "androidx.compose.ui:ui-test-junit4:$jetpack_compose_version"
    api "com.google.truth:truth:1.1.3"
    api "org.mockito:mockito-core:2.21.0"
+0 −55
Original line number Diff line number Diff line
/*
 *  Copyright (C) 2022 The Android Open Source Project
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package com.android.settingslib.spa.testutils

import androidx.arch.core.executor.ArchTaskExecutor
import androidx.arch.core.executor.TaskExecutor
import org.junit.rules.TestWatcher
import org.junit.runner.Description

/**
 * Test rule that makes ArchTaskExecutor main thread assertions pass. There is one such assert
 * in LifecycleRegistry.

 * This is a copy of androidx/arch/core/executor/testing/InstantTaskExecutorRule which should be
 * replaced once the dependency issue is solved.
 */
class InstantTaskExecutorRule : TestWatcher() {
    override fun starting(description: Description) {
        super.starting(description)
        ArchTaskExecutor.getInstance().setDelegate(
            object : TaskExecutor() {
                override fun executeOnDiskIO(runnable: Runnable) {
                    runnable.run()
                }

                override fun postToMainThread(runnable: Runnable) {
                    runnable.run()
                }

                override fun isMainThread(): Boolean {
                    return true
                }
            }
        )
    }

    override fun finished(description: Description) {
        super.finished(description)
        ArchTaskExecutor.getInstance().setDelegate(null)
    }
}