Fix unit tests (#5947)

* move createLocale() method to companion object and add test dependency

* use mockk() from Mockk library for mocking sealed classes

* change method parameter to null-able String type

* add null check for accessing property from unit tests

* change method signature to match old method's signature

It fixes the NullPointerException when running ImageProcessingUnitTest

* Fix unresolved references and make properties public for unit tests

* fix tests in UploadRepositoryUnitTest by making return type null-able
This commit is contained in:
Rohit Verma 2024-11-23 05:05:34 +05:30 committed by GitHub
parent fe347c21fd
commit e070c5dbe8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 56 additions and 52 deletions

View file

@ -471,18 +471,20 @@ class SettingsFragment : PreferenceFragmentCompat() {
editor.apply()
}
/**
* Create Locale based on different types of language codes
* @param languageCode
* @return Locale and throws error for invalid language codes
*/
fun createLocale(languageCode: String): Locale {
val parts = languageCode.split("-")
return when (parts.size) {
1 -> Locale(parts[0])
2 -> Locale(parts[0], parts[1])
3 -> Locale(parts[0], parts[1], parts[2])
else -> throw IllegalArgumentException("Invalid language code: $languageCode")
companion object {
/**
* Create Locale based on different types of language codes
* @param languageCode
* @return Locale and throws error for invalid language codes
*/
fun createLocale(languageCode: String): Locale {
val parts = languageCode.split("-")
return when (parts.size) {
1 -> Locale(parts[0])
2 -> Locale(parts[0], parts[1])
3 -> Locale(parts[0], parts[1], parts[2])
else -> throw IllegalArgumentException("Invalid language code: $languageCode")
}
}
}