music: add the FakeMediaProvider.enabled switch main's tests use
- Commit
63c0038e18e2274bfe47d83012f97da2ff63f910- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-07 15:23 UTC (29 days ago)
- Parents
8025837
Integrated the pass-3 music tests onto main (ee9abbaeb, picked from d367e0b49) but left FakeMediaProvider without the companion enabled switch. PopulatedLibraryTest already sets FakeMediaProvider.enabled to false/true around its Robolectric sandbox, so :music unit tests did not compile on main. The later cov/c35 commit f7f860bfd carried the switch but no longer cherry-picked (the rest of its tree was already on main; this file was the only remaining difference). Ports exactly those 11 lines from f7f860bfd: a @Volatile enabled flag checked at the top of query() so a shared-sandbox test class can switch the fixture off and later classes see an authoritative empty library instead of the populated one. Verified in a throwaway worktree via gslot: :music:testDevUnitTest green, 121 tests, 0 failures (includes PopulatedLibraryTest). (cherry picked from commit 70f0b113964e76a3353c134ed9ac51851f339677)
Diff
music/src/test/java/com/vayunmathur/music/FakeMediaProvider.kt
diff --git a/music/src/test/java/com/vayunmathur/music/FakeMediaProvider.kt b/music/src/test/java/com/vayunmathur/music/FakeMediaProvider.ktindex 5bb7d6d3e4..a4a0401782 100644--- a/music/src/test/java/com/vayunmathur/music/FakeMediaProvider.kt+++ b/music/src/test/java/com/vayunmathur/music/FakeMediaProvider.kt@@ -16,6 +16,16 @@ import android.net.Uri */ class FakeMediaProvider : ContentProvider() { + companion object {+ /**+ * Robolectric's provider registry and the repository singleton both+ * outlive a test class in a shared sandbox, so the populated tests+ * switch this off (and refresh) on the way out: later classes then+ * query an authoritative empty library instead of this fixture.+ */+ @Volatile var enabled: Boolean = true+ }+ override fun onCreate(): Boolean = true override fun query(@@ -27,6 +37,7 @@ class FakeMediaProvider : ContentProvider() { ): Cursor { val columns = projection ?: emptyArray() val cursor = MatrixCursor(columns)+ if (!enabled) return cursor fun row(values: Map<String, Any?>) { cursor.addRow(columns.map { values[it] }) }