Merge "Use androidx.arch.core InstantTaskExecutorRule"

This commit is contained in:
TreeHugger Robot
2022-12-01 17:36:30 +00:00
committed by Android (Google) Code Review
4 changed files with 3 additions and 58 deletions

View File

@@ -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

View File

@@ -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",

View File

@@ -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"

View File

@@ -1,55 +0,0 @@
/*
* 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)
}
}