-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mohammad Sianaki
committed
Jul 7, 2023
1 parent
1a097cd
commit fc83da7
Showing
2 changed files
with
13 additions
and
16 deletions.
There are no files selected for viewing
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
28 changes: 12 additions & 16 deletions
28
domain/market/src/test/java/ir/kaaveh/domain/use_case/GetFavoriteMarketListUseCaseTest.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 |
---|---|---|
@@ -1,38 +1,34 @@ | ||
package ir.kaaveh.domain.use_case | ||
|
||
import io.mockk.every | ||
import io.mockk.mockk | ||
import io.mockk.verify | ||
import ir.kaaveh.domain.repository.MarketRepository | ||
import ir.kaaveh.domain.test.favoriteMarket | ||
import ir.kaaveh.domain.test.notFavoriteMarket | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.flow.first | ||
import kotlinx.coroutines.flow.flow | ||
import kotlinx.coroutines.flow.flowOf | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.Assert.* | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.mockito.kotlin.doReturn | ||
import org.mockito.kotlin.mock | ||
|
||
@OptIn(ExperimentalCoroutinesApi::class) | ||
class GetFavoriteMarketListUseCaseTest { | ||
|
||
private lateinit var mockRepository: MarketRepository | ||
private val marketRepository: MarketRepository = mockk(relaxed = true) | ||
private lateinit var getFavoriteMarketListUseCase: GetFavoriteMarketListUseCase | ||
|
||
@Before | ||
fun provideRepository(){ | ||
mockRepository = mock { | ||
on { getMarketList() } doReturn flow { | ||
emit(listOf(favoriteMarket, notFavoriteMarket)) | ||
} | ||
} | ||
getFavoriteMarketListUseCase = GetFavoriteMarketListUseCase(repository = mockRepository) | ||
fun provideRepository() { | ||
getFavoriteMarketListUseCase = GetFavoriteMarketListUseCase(repository = marketRepository) | ||
} | ||
|
||
@Test | ||
fun checkGetOnlyFavoriteNews() = runTest { | ||
val news = getFavoriteMarketListUseCase().first() | ||
assertTrue(news.size == 1) | ||
every { marketRepository.getFavoriteMarketList() } returns flowOf(emptyList()) | ||
getFavoriteMarketListUseCase.invoke() | ||
verify(exactly = 1) { | ||
marketRepository.getFavoriteMarketList() | ||
} | ||
} | ||
|
||
} |