Created
May 29, 2019 13:19
-
-
Save AdamMc331/4fc8323e404e91531b1c30fc1bde403c to your computer and use it in GitHub Desktop.
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
class QuestionViewModel { | |
private val state = MutableLiveData<QuestionState>() | |
private val currentQuestion: LiveData<Question> = Transformations.map(state) { | |
(it as? QuestionState.Loaded)?.data | |
} | |
val questionTitle: String | |
get() = currentQuestion.value?.title.orEmpty | |
} | |
class QuestionViewModelTest { | |
@JvmField | |
@Rule | |
val instantExecutor = InstantTaskExecutorRule() | |
@Test | |
fun assertTitle() { | |
// Mock data load | |
assertEquals("TestTitle", viewModel.questionTitle) | |
// The above is false, saying viewModel.questionTitle is empty, because `currentQuestion` value is null. | |
// This is as if the Transformations.map() never ran | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment