Skip to content

Instantly share code, notes, and snippets.

View cengiztoru's full-sized avatar

Cengiz TORU cengiztoru

View GitHub Profile
DenisBronx / FakePreferences.kt
Last active September 19, 2022 20:45
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
override fun getStringSet(key: String, default: MutableSet<String>?): MutableSet<String>? =