@Test
fun sendResultToUI() {
val foo = MutableLiveData<Resource<User>>()
val bar = MutableLiveData<Resource<User>>()
`when`(userRepository.loadUser("foo")).thenReturn(foo)
`when`(userRepository.loadUser("bar")).thenReturn(bar)
val observer = mock<Observer<Resource<User>>>()
userViewModel.user.observeForever(observer) //Create foo and bar, observe user live data
userViewModel.setLogin("foo")
verify(observer, never()).onChanged(any()) //Make sure that setting login to foo did not touch vm.user?
/*val fooUser = TestUtil.createUser("foo")
val fooValue = Resource.success(fooUser)
foo.value = fooValue
verify(observer).onChanged(fooValue)
reset(observer)
val barUser = TestUtil.createUser("bar")
val barValue = Resource.success(barUser)
bar.value = barValue
userViewModel.setLogin("bar")
verify(observer).onChanged(barValue)*/
}
谁能解释一下这句话:
verify(observer, never()).onChanged(any())
GithubBrowser
样品?我只是不明白,打电话来
setLogin()
观察家那我们他妈的怎么能证实呢
onChanged()
当我们在前一行特别触发它的时候从来没有被调用过!?