Skip to content
This repository has been archived by the owner on Apr 17, 2021. It is now read-only.

Commit

Permalink
Issue #2543: wrote tests for languageAndMaybeCountryMatch
Browse files Browse the repository at this point in the history
  • Loading branch information
Michelle Wong authored and liuche committed Jul 13, 2019
1 parent 21bf217 commit 3d4819a
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions app/src/test/java/org/mozilla/tv/firefox/ext/LocaleKtTest.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package org.mozilla.tv.firefox.ext

import io.mockk.every
import io.mockk.mockk
import io.mockk.mockkStatic
import io.mockk.verify
import org.junit.Assert.*
import org.junit.Test
import org.mozilla.tv.firefox.architecture.KillswitchLocales
import java.util.*

class LocaleKtTest {
Expand Down Expand Up @@ -62,4 +67,45 @@ class LocaleKtTest {

assertTrue(Locale.US.languageAndMaybeCountryMatch(arrayOf(Locale.CANADA, allowed)))
}

@Test
fun `GIVEN all killswitch locale is allowed WHEN any locale is passed THEN should return true`() {
val allowed = KillswitchLocales.All

assertTrue(Locale.US.languageAndMaybeCountryMatch(allowed))
assertTrue(Locale.CANADA.languageAndMaybeCountryMatch(allowed))
assertTrue(Locale.UK.languageAndMaybeCountryMatch(allowed))
assertTrue(Locale.GERMANY.languageAndMaybeCountryMatch(allowed))
assertTrue(Locale.CHINA.languageAndMaybeCountryMatch(allowed))

assertTrue(Locale.ENGLISH.languageAndMaybeCountryMatch(allowed))
assertTrue(Locale.GERMAN.languageAndMaybeCountryMatch(allowed))
assertTrue(Locale.CHINESE.languageAndMaybeCountryMatch(allowed))
}

@Test
fun `WHEN KillswitchLocale ActiveIn is passed THEN overload should be called`() {
// Mock extension functions in this class
// If this test fails, check if this class has been moved, causing this string to be incorrect
mockkStatic("org.mozilla.tv.firefox.ext.LocaleKt")

val allowed = KillswitchLocales.ActiveIn(Locale.US)

val locales = listOf(
Locale.US,
Locale.CANADA,
Locale.UK,
Locale.GERMANY,
Locale.CHINA,
Locale.ENGLISH,
Locale.GERMAN,
Locale.CHINESE
)

locales.forEach { it.languageAndMaybeCountryMatch(allowed) }

// Verify that languageAndMaybeCountryMatch is called with an array of locales (i.e., the overload)
locales.forEach { verify(exactly = 1) { it.languageAndMaybeCountryMatch(any<Array<Locale>>()) } }
}

}

0 comments on commit 3d4819a

Please sign in to comment.