Skip to content
Permalink
Browse files

Issue #464: Let app access a list of experiments

Closes #464: Let app access a list of experiments
  • Loading branch information...
fercarcedo authored and pocmo committed Jul 20, 2018
1 parent f788b9c commit 5a999c4a482c7b6f6bb7641da9da6031ba4f4568
@@ -21,6 +21,12 @@ class Fretboard(
private var experimentsLoaded: Boolean = false
private val evaluator = ExperimentEvaluator(valuesProvider)

/**
* Provides the list of experiments (active or not)
*/
val experiments: List<Experiment>
get() = experimentsResult.experiments.toList()

/**
* Loads experiments from local storage
*/
@@ -4,6 +4,8 @@

package mozilla.components.service.fretboard

import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mockito.`when`
@@ -58,4 +60,34 @@ class FretboardTest {
verify(experimentSource).getExperiments(ExperimentsSnapshot(listOf(Experiment("id0")), null))
verify(experimentStorage).save(ExperimentsSnapshot(listOf(Experiment("id")), null))
}

@Test
fun testExperiments() {
val experimentSource = mock(ExperimentSource::class.java)
val experimentStorage = mock(ExperimentStorage::class.java)
val experiments = listOf(
Experiment("first-id"),
Experiment("second-id")
)
`when`(experimentStorage.retrieve()).thenReturn(ExperimentsSnapshot(experiments, null))
val fretboard = Fretboard(experimentSource, experimentStorage)
var returnedExperiments = fretboard.experiments
assertEquals(0, returnedExperiments.size)
fretboard.loadExperiments()
returnedExperiments = fretboard.experiments
assertEquals(2, returnedExperiments.size)
assertTrue(returnedExperiments.contains(experiments[0]))
assertTrue(returnedExperiments.contains(experiments[1]))
}

@Test
fun testExperimentsNoExperiments() {
val experimentSource = mock(ExperimentSource::class.java)
val experimentStorage = mock(ExperimentStorage::class.java)
val experiments = listOf<Experiment>()
`when`(experimentStorage.retrieve()).thenReturn(ExperimentsSnapshot(experiments, null))
val fretboard = Fretboard(experimentSource, experimentStorage)
val returnedExperiments = fretboard.experiments
assertEquals(0, returnedExperiments.size)
}
}

0 comments on commit 5a999c4

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