-
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #229 from hieuwu/feature/test-submit-order-usecase
Cover unit test for submit order
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
...rc/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/SubmitOrderUseCaseImplTest.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.hieuwu.groceriesstore.domain.usecases.impl | ||
|
||
import com.hieuwu.groceriesstore.data.repository.OrderRepository | ||
import com.hieuwu.groceriesstore.domain.models.OrderModel | ||
import com.hieuwu.groceriesstore.domain.usecases.SubmitOrderUseCase | ||
import kotlinx.coroutines.runBlocking | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.mockito.Mock | ||
import org.mockito.junit.MockitoJUnitRunner | ||
import org.mockito.kotlin.any | ||
import org.mockito.kotlin.verify | ||
import org.mockito.kotlin.whenever | ||
|
||
@RunWith(MockitoJUnitRunner::class) | ||
class SubmitOrderUseCaseImplTest { | ||
|
||
@Mock | ||
lateinit var mockedOrderRepository: OrderRepository | ||
|
||
private lateinit var testee: SubmitOrderUseCase | ||
|
||
@Before | ||
fun setUp() { | ||
testee = SubmitOrderUseCaseImpl( | ||
orderRepository = mockedOrderRepository | ||
) | ||
} | ||
|
||
@Test | ||
fun whenExecute_thenSubmitOrderSuccessfully() { | ||
runBlocking { | ||
whenever(mockedOrderRepository.sendOrderToServer(any())).thenReturn(true) | ||
testee.execute( | ||
SubmitOrderUseCase.Input( | ||
order = OrderModel( | ||
lineItemList = mutableListOf() | ||
) | ||
) | ||
) | ||
|
||
verify(mockedOrderRepository).sendOrderToServer( | ||
OrderModel( | ||
lineItemList = mutableListOf() | ||
) | ||
) | ||
} | ||
} | ||
|
||
} |