-
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for UserSettingsUseCaseImplTest
- Loading branch information
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
...c/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/UserSettingsUseCaseImplTest.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,49 @@ | ||
package com.hieuwu.groceriesstore.domain.usecases.impl | ||
|
||
import com.hieuwu.groceriesstore.data.repository.UserRepository | ||
import com.hieuwu.groceriesstore.domain.usecases.UserSettingsUseCase | ||
import java.util.* | ||
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.verify | ||
import kotlin.random.Random | ||
|
||
@RunWith(MockitoJUnitRunner::class) | ||
class UserSettingsUseCaseImplTest { | ||
|
||
@Mock | ||
lateinit var mockedUserRepository: UserRepository | ||
private lateinit var testee: UserSettingsUseCase | ||
|
||
@Before | ||
fun setUp() { | ||
testee = UserSettingsUseCaseImpl(userRepository = mockedUserRepository) | ||
} | ||
|
||
@Test | ||
fun whenExecute_thenCallUserRepository() { | ||
val input = | ||
UserSettingsUseCase.Input( | ||
id = UUID.randomUUID().toString(), | ||
isOrderCreatedEnabled = Random.nextBoolean(), | ||
isDatabaseRefreshedEnabled = Random.nextBoolean(), | ||
isPromotionEnabled = Random.nextBoolean(), | ||
) | ||
|
||
runBlocking { | ||
testee.execute(input) | ||
|
||
verify(mockedUserRepository) | ||
.updateUserSettings( | ||
id = input.id, | ||
isOrderCreatedEnabled = input.isOrderCreatedEnabled, | ||
isDatabaseRefreshedEnabled = input.isDatabaseRefreshedEnabled, | ||
isPromotionEnabled = input.isPromotionEnabled, | ||
) | ||
} | ||
} | ||
} |