Your phone, on your command. Gotcha is world's first fully on-device AI copilot for Android that turns natural language into real device actions — safely.
fix: clear FileProvider static cache between Robolectric tests
Rishabh Bajpai4f5cae5f3f33
diff --git a/app/src/test/java/com/gotcha/testsupport/FileProviderCache.kt b/app/src/test/java/com/gotcha/testsupport/FileProviderCache.ktnew file mode 100644index 0000000..c54c631--- /dev/null+++ b/app/src/test/java/com/gotcha/testsupport/FileProviderCache.kt@@ -0,0 +1,25 @@+package com.gotcha.testsupport++import androidx.core.content.FileProvider++/**+ * AndroidX `FileProvider` caches its parsed `file_paths.xml` strategy in a+ * static map keyed by authority. Every Robolectric test gets a fresh+ * application sandbox, but the JVM (and the cache) is shared across the+ * whole Gradle test task — so whichever test calls `getUriForFile` first+ * pins every later test's lookups to ITS sandbox, and files from other+ * sandboxes wrongly resolve as "outside the mapped roots".+ *+ * Call [clear] from `@Before` (and `@After`, for the next class) in every+ * test that touches `FileProvider`, same discipline as+ * [ShadowExternalStorageManager.resetGranted].+ */+object FileProviderCache {+ fun clear() {+ val field = FileProvider::class.java.getDeclaredField("sCache").apply {+ isAccessible = true+ }+ @Suppress("UNCHECKED_CAST")+ (field.get(null) as MutableMap<*, *>).clear()+ }+}diff --git a/app/src/test/java/com/gotcha/tools/PodcastToolTest.kt b/app/src/test/java/com/gotcha/tools/PodcastToolTest.ktindex adfc86d..a9c22a0 100644--- a/app/src/test/java/com/gotcha/tools/PodcastToolTest.kt+++ b/app/src/test/java/com/gotcha/tools/PodcastToolTest.kt@@ -8,6 +8,7 @@ import com.gotcha.audio.ModelCategoryimport com.gotcha.audio.VoiceInfoimport com.gotcha.data.GotchaStorageimport com.gotcha.data.Settings+import com.gotcha.testsupport.FileProviderCacheimport com.gotcha.testsupport.ShadowExternalStorageManagerimport kotlinx.coroutines.runBlockingimport org.junit.After@@ -61,6 +62,10 @@ class PodcastToolTest {@Beforefun setUp() {ShadowExternalStorageManager.granted = true+ // FileProvider caches its path strategy statically per authority+ // across the whole test task while each test gets a fresh sandbox+ // (see FileProviderCache) — clear it so this test resolves ITS roots.+ FileProviderCache.clear()context = ApplicationProvider.getApplicationContext()GotchaStorage.podcastsRoot().deleteRecursively()}@@ -68,6 +73,7 @@ class PodcastToolTest {@Afterfun tearDown() {ShadowExternalStorageManager.resetGranted()+ FileProviderCache.clear()}private fun tool(diff --git a/app/src/test/java/com/gotcha/updater/AppUpdateManagerRobolectricTest.kt b/app/src/test/java/com/gotcha/updater/AppUpdateManagerRobolectricTest.ktindex 005a507..373043d 100644--- a/app/src/test/java/com/gotcha/updater/AppUpdateManagerRobolectricTest.kt+++ b/app/src/test/java/com/gotcha/updater/AppUpdateManagerRobolectricTest.kt@@ -5,10 +5,13 @@ import android.content.Intentimport android.net.Uriimport android.provider.Settingsimport androidx.test.core.app.ApplicationProvider+import com.gotcha.testsupport.FileProviderCacheimport kotlinx.coroutines.test.runTest+import org.junit.Afterimport org.junit.Assert.assertEqualsimport org.junit.Assert.assertFalseimport org.junit.Assert.assertTrue+import org.junit.Beforeimport org.junit.Testimport org.junit.runner.RunWithimport org.robolectric.RobolectricTestRunner@@ -28,6 +31,17 @@ class AppUpdateManagerRobolectricTest {private val updateManager = AppUpdateManager()private val context: Context = ApplicationProvider.getApplicationContext()+ @Before+ fun clearFileProviderCache() {+ // Same static-cache poisoning as PodcastToolTest (see FileProviderCache):+ // each test gets a fresh sandbox but FileProvider remembers the first+ // caller's roots for the whole test task.+ FileProviderCache.clear()+ }++ @After+ fun clearFileProviderCacheAfter() = FileProviderCache.clear()+@Testfun downloadUpdate_untrustedUrl_returnsFailureBeforeAnyNetworkUse() = runTest {val info = AppUpdateInfo(