Open
Description
- Reduce boilerplate mocks
In each OrderDetailViewModelTest
test, we mock many default behaviours not related specifically to the test itself. Most of them are repeatable for each test, like mock repository returning mocked order.
So instead of
@Test
fun `collect button hidden if payment is not collectable`() =
coroutinesTestRule.testDispatcher.runBlockingTest {
// GIVEN
doReturn(false).whenever(paymentCollectibilityChecker).isCollectable(any())
doReturn(order).whenever(repository).getOrder(any())
doReturn(order).whenever(repository).fetchOrder(any(), any())
doReturn(true).whenever(repository).fetchOrderNotes(any(), any())
// WHEN
viewModel.start()
// THEN
assertThat(currentViewStateValue!!.orderInfo!!.isPaymentCollectableWithCardReader).isFalse()
}
we could have just
@Test
fun `collect button hidden if payment is not collectable`() =
coroutinesTestRule.testDispatcher.runBlockingTest {
// GIVEN
doReturn(false).whenever(paymentCollectibilityChecker).isCollectable(any())
// WHEN
viewModel.start()
// THEN
assertThat(currentViewStateValue!!.orderInfo!!.isPaymentCollectableWithCardReader).isFalse()
}
-
OrderDetailViewModel#updateOrderStatus
is public-visible just for testing, we might refactor tests and hide this method