Closed johncheung233 closed 1 year ago
Most Context
-based things aren't going to work in a unit test, unless you're using something like Robolectric. That isn't really anything to do with this library.
You can substitute MapSettings
in your tests instead of SharedPreferencesSettings
to get a Settings
instance that's in-memory only and doesn't depend on Context
.
Could not create instance for '[Singleton:'com.russhwolf.settings.Settings',qualifier:normal]
actual val settingsModule: Module = module { single(named("encrypted")) {
val context = get()
val masterKey = MasterKey.Builder(context)
.setKeyScheme(MasterKey.KeyScheme.AES256_GCM)
.build()
val delegate = EncryptedSharedPreferences.create(
context,
"encrypted",
masterKey,
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
)
SharedPreferencesSettings(delegate)
}
single(named("normal")) {
val context = get()
val delegate : SharedPreferences = context.getSharedPreferences("normal", Context.MODE_PRIVATE)
SharedPreferencesSettings(delegate)
}
single{
val context = get()
KMMPreference(context)
}
}