-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: [#274] fixing locale on android 14 and setup test using junit & …
…mockk (#282) * chore: [#274] initial setup test using JUnit & MockK * chore: [#274] add more test case at LocaleHelperTest * fix: [#274] fix default language from shared preferences * fix: [#274] disable language split on AAB * chore: [#274] rename method
- Loading branch information
1 parent
342ae91
commit cfc463b
Showing
5 changed files
with
80 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
app/src/test/java/com/breadwallet/tools/util/LocaleHelperTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.breadwallet.tools.util | ||
|
||
import android.content.Context | ||
import com.breadwallet.entities.Language | ||
import io.mockk.mockk | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Assert.assertFalse | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Test | ||
|
||
class LocaleHelperTest { | ||
|
||
@Test | ||
fun `given LocaleHelper instance, then should validate default value`() { | ||
val context: Context = mockk(relaxed = true) | ||
|
||
LocaleHelper.init(context) | ||
|
||
val currentLocale = LocaleHelper.instance.currentLocale | ||
|
||
assertTrue(currentLocale == Language.ENGLISH) | ||
assertEquals("en", currentLocale.code) | ||
assertEquals("English", currentLocale.title) | ||
assertEquals("Select language", currentLocale.desc) | ||
} | ||
|
||
@Test | ||
fun `getLocale invoked, should return Locale object`() { | ||
val localeIndonesian = LocaleHelper.getLocale(Language.INDONESIAN) | ||
|
||
assertEquals("id", localeIndonesian.language) | ||
|
||
val localeChineseSimplified = LocaleHelper.getLocale(Language.CHINESE_SIMPLIFIED) | ||
|
||
assertEquals("zh", localeChineseSimplified.language) | ||
assertEquals("CN", localeChineseSimplified.country) | ||
} | ||
|
||
@Test | ||
fun `setLocaleIfNeeded invoked, should update current locale`() { | ||
val context: Context = mockk(relaxed = true) | ||
LocaleHelper.init(context) | ||
|
||
val currentLocale = LocaleHelper.instance.currentLocale | ||
assertTrue(currentLocale == Language.ENGLISH) | ||
|
||
var changed = LocaleHelper.instance.setLocaleIfNeeded(Language.INDONESIAN) | ||
assertTrue(changed) | ||
|
||
changed = LocaleHelper.instance.setLocaleIfNeeded(Language.INDONESIAN) | ||
assertFalse(changed) | ||
} | ||
} |