From d4a44105b3c9a8b24b5617a3f9036ada1d53b1e6 Mon Sep 17 00:00:00 2001 From: Geanik Date: Thu, 12 Oct 2023 18:02:07 +0200 Subject: [PATCH] Add test for UserSettingsUseCaseImpl --- .../impl/UserSettingsUseCaseImplTest.kt | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/UserSettingsUseCaseImplTest.kt diff --git a/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/UserSettingsUseCaseImplTest.kt b/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/UserSettingsUseCaseImplTest.kt new file mode 100644 index 00000000..e9a14006 --- /dev/null +++ b/app/src/test/java/com/hieuwu/groceriesstore/domain/usecases/impl/UserSettingsUseCaseImplTest.kt @@ -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, + ) + } + } +}