mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-29 22:03:55 +01:00
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:
parent
fe347c21fd
commit
e070c5dbe8
14 changed files with 56 additions and 52 deletions
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue