Skip to content
Permalink
Browse files

Issue #557: Fretboard: ExperimentEvaluator: Add tests for empty value…

…s and release channel

Closes #557: Fretboard: ExperimentEvaluator: Add tests for empty values and release channel
  • Loading branch information...
fercarcedo authored and pocmo committed Aug 3, 2018
1 parent 80d1bbf commit 7c7bfe00b3bd9192c3b74c53506fa96ff1534dd7
@@ -23,6 +23,37 @@ import org.robolectric.RobolectricTestRunner

@RunWith(RobolectricTestRunner::class)
class ExperimentEvaluatorTest {
@Test
fun testEvaluateEmtpyMatchers() {
val experiment = Experiment(
"testid",
"testexperiment",
"testdesc",
Experiment.Matcher(
appId = "",
regions = listOf()
),
Experiment.Bucket(
70,
20
),
1528916183)

val context = mock(Context::class.java)
`when`(context.packageName).thenReturn("other.appId")
val sharedPreferences = mock(SharedPreferences::class.java)
`when`(sharedPreferences.getBoolean(eq("testexperiment"), anyBoolean())).thenAnswer { invocation -> invocation.arguments[1] as Boolean }
`when`(context.getSharedPreferences(anyString(), eq(Context.MODE_PRIVATE))).thenReturn(sharedPreferences)
val packageManager = mock(PackageManager::class.java)
val packageInfo = PackageInfo()
packageInfo.versionName = "test.version"
`when`(packageManager.getPackageInfo(anyString(), anyInt())).thenReturn(packageInfo)
`when`(context.packageManager).thenReturn(packageManager)

val evaluator = ExperimentEvaluator()
assertNotNull(evaluator.evaluate(context, ExperimentDescriptor("testexperiment"), listOf(experiment), 20))
}

@Test
fun testEvaluateBuckets() {
val experiment = Experiment(
@@ -310,6 +341,56 @@ class ExperimentEvaluatorTest {
assertNull(evaluator.evaluate(context, ExperimentDescriptor("testexperiment"), listOf(experiment), 20))
}

@Test
fun testEvaluateReleaseChannel() {
val experiment = Experiment(
"testid",
"testexperiment",
"testdesc",
Experiment.Matcher(
"eng",
"test.appId",
listOf("USA", "GBR"),
"test.version",
"unknown",
"robolectric",
"USA",
"alpha"
),
Experiment.Bucket(
70,
20
),
1528916183)

val context = mock(Context::class.java)
`when`(context.packageName).thenReturn("test.appId")
val sharedPreferences = mock(SharedPreferences::class.java)
`when`(sharedPreferences.getBoolean(eq("testexperiment"), anyBoolean())).thenAnswer { invocation -> invocation.arguments[1] as Boolean }
`when`(context.getSharedPreferences(anyString(), eq(Context.MODE_PRIVATE))).thenReturn(sharedPreferences)
val packageManager = mock(PackageManager::class.java)
val packageInfo = PackageInfo()
packageInfo.versionName = "test.version"
`when`(packageManager.getPackageInfo(anyString(), anyInt())).thenReturn(packageInfo)
`when`(context.packageManager).thenReturn(packageManager)

var evaluator = ExperimentEvaluator(object : ValuesProvider() {
override fun getReleaseChannel(context: Context): String? {
return "alpha"
}
})

assertNotNull(evaluator.evaluate(context, ExperimentDescriptor("testexperiment"), listOf(experiment), 20))

evaluator = ExperimentEvaluator(object : ValuesProvider() {
override fun getRegion(context: Context): String? {
return "production"
}
})

assertNull(evaluator.evaluate(context, ExperimentDescriptor("testexperiment"), listOf(experiment), 20))
}

@Test
fun testEvaluateManufacturer() {
var experiment = Experiment(

0 comments on commit 7c7bfe0

Please sign in to comment.
You can’t perform that action at this time.