Skip to content

Commit

Permalink
Add test for UserSettingsUseCaseImplTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Geanik committed Oct 12, 2023
1 parent 130c13b commit 11d373d
Showing 1 changed file with 49 additions and 0 deletions.
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,
)
}
}
}

0 comments on commit 11d373d

Please sign in to comment.