From 110a17749da65a817833c2d8994e84adb9f0bd2d Mon Sep 17 00:00:00 2001 From: David Allison <62114487+david-allison@users.noreply.github.com> Date: Tue, 17 Dec 2024 08:38:14 +0000 Subject: [PATCH] refactor(AndroidTest): remove `col` dependency --- .../test/java/com/ichi2/anki/RobolectricTest.kt | 5 ++++- .../test/java/com/ichi2/testutils/AndroidTest.kt | 15 +++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/RobolectricTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/RobolectricTest.kt index 81345a7b2f98..b6dabb0b61ec 100644 --- a/AnkiDroid/src/test/java/com/ichi2/anki/RobolectricTest.kt +++ b/AnkiDroid/src/test/java/com/ichi2/anki/RobolectricTest.kt @@ -45,6 +45,7 @@ import com.ichi2.libanki.utils.TimeManager import com.ichi2.testutils.AndroidTest import com.ichi2.testutils.MockTime import com.ichi2.testutils.TaskSchedulerRule +import com.ichi2.testutils.TestClass import com.ichi2.testutils.common.FailOnUnhandledExceptionRule import com.ichi2.testutils.common.IgnoreFlakyTestsInCIRule import com.ichi2.testutils.filter @@ -75,7 +76,9 @@ import org.robolectric.shadows.ShadowMediaPlayer import timber.log.Timber import kotlin.test.assertNotNull -open class RobolectricTest : AndroidTest { +open class RobolectricTest : + TestClass, + AndroidTest { @Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN") private fun Any.wait(timeMs: Long) = (this as Object).wait(timeMs) diff --git a/AnkiDroid/src/test/java/com/ichi2/testutils/AndroidTest.kt b/AnkiDroid/src/test/java/com/ichi2/testutils/AndroidTest.kt index 1e66ca3d0764..4ed8b7c00395 100644 --- a/AnkiDroid/src/test/java/com/ichi2/testutils/AndroidTest.kt +++ b/AnkiDroid/src/test/java/com/ichi2/testutils/AndroidTest.kt @@ -20,10 +20,21 @@ import android.content.Context import android.content.SharedPreferences import androidx.core.content.edit import androidx.test.core.app.ApplicationProvider +import com.ichi2.anki.RobolectricTest import com.ichi2.anki.preferences.sharedPrefs -/** Marker interface for classes annotated with `@RunWith(AndroidJUnit4.class)` */ -interface AndroidTest : TestClass +/** + * Marker interface for classes annotated with `@RunWith(AndroidJUnit4.class)` which do + * not need access to the collection + * + * Classes should also be marked with `@Config(application = EmptyApplication::class)` for + * performance improvements + * + * Use [JvmTest] if a reference to Android is not necessary but the collection is required + * + * Use [RobolectricTest] if access the collection is necessary + */ +interface AndroidTest val AndroidTest.targetContext: Context get() {