Skip to content

Instantly share code, notes, and snippets.

@DenisBronx
DenisBronx / FakePreferences.kt
Last active Sep 19, 2022
Fake Shared Preferences class that uses an in-memory implementation
View FakePreferences.kt
class FakePreferences : SharedPreferences {
private val map: MutableMap<String, Any?> = mutableMapOf()
private val listeners: MutableList<SharedPreferences.OnSharedPreferenceChangeListener> = mutableListOf()
override fun getAll(): MutableMap<String, *> = map
override fun getString(key: String, default: String?): String? = map[key] as String? ?: default
@Suppress("UNCHECKED_CAST")
override fun getStringSet(key: String, default: MutableSet<String>?): MutableSet<String>? =