Skip to content

Improve OrderDetailViewModelTest #4305

Open
@wzieba

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

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions