Create the fake MediaStore directory without java.nio.file

Files.createTempDirectory needs API 26 and the fake lives in the main source
set of tests:testutils, so lint failed it against the minimum of 24.
File.createTempFile has been available since API 1 and still gives each
provider instance its own directory.
This commit is contained in:
hayaksi1
2026-08-13 17:36:51 +03:00
parent 4558590492
commit 59b26173a7
@@ -17,7 +17,6 @@ import android.provider.MediaStore
import androidx.test.core.app.ApplicationProvider
import org.robolectric.shadows.ShadowContentResolver
import java.io.File
import java.nio.file.Files
/**
* Stands in for the MediaStore provider: it records the display names an insert is attempted with,
@@ -25,7 +24,10 @@ import java.nio.file.Files
* way MediaStore does once a directory already holds 32 files with the same name.
*/
class FakeMediaStoreContentProvider : ContentProvider() {
private val directory: File = Files.createTempDirectory("fake-media-store").toFile()
private val directory: File = File.createTempFile("fake-media-store", null).apply {
delete()
mkdir()
}
val insertedDisplayNames = mutableListOf<String>()