Leave a rating/review
In the previous episode you ensured that you could save the correct data. Now you want to make sure that you actualy get the correct data when calling the database. So, our last test is going to do just that.
Let me scroll down a little bit. Call this method:
@Test
fun getWishListReturnsCorretData(){
}
As usual we will create our wishlist:
val wishlist = Wishlist("Victoria",
listOf("RW Android Apprentice Book", "Android phone"), 1)
then:
wishlistDao.save(wishlist)
We’re going to create a mockup server just like the one we created before so im going to copy and paste:
val mockObserver = mock<Observer<Wishlist>>()
viewModel.getWishlist(1).observeForever(mockObserver)
verify(mockObserver).onChanged(wishlist)
Again we’re creating a new wishlist with some test data and an id of . We’re using the save method of the wishlistDao to save the wishlist. Then we create an observer and finally we call the wishlist method and verify that the getWishlist that we return with this method is the correct one.
Execute your test. It fails as expected.
Open your DetailViewmodel class and instead of just passing any id. Pass the id that we received as a parameter.
Execute all of your tests and they all pass. Nice.