Skip to content

Commit 8592d19

Browse files
committedJul 28, 2024·
use default dispatcher to load suggestions
1 parent 4423db8 commit 8592d19

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed
 

‎features/finances/impl/src/main/kotlin/br/com/mob1st/features/finances/impl/infra/data/repositories/suggestions/CategorySuggestionsRepositoryImpl.kt

+8-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package br.com.mob1st.features.finances.impl.infra.data.repositories.suggestions
22

33
import br.com.mob1st.core.androidx.assets.AssetsGetter
44
import br.com.mob1st.core.androidx.resources.StringIdGetter
5-
import br.com.mob1st.core.kotlinx.coroutines.IoCoroutineDispatcher
5+
import br.com.mob1st.core.kotlinx.coroutines.DefaultCoroutineDispatcher
66
import br.com.mob1st.core.kotlinx.structures.Uri
77
import br.com.mob1st.features.finances.impl.domain.entities.BuilderNextAction
88
import br.com.mob1st.features.finances.impl.domain.entities.CategorySuggestion
@@ -15,10 +15,14 @@ import java.nio.file.Files
1515

1616
/**
1717
* Concrete implementation of the [CategorySuggestionRepository] interface.
18-
* @property io The IO dispatcher.
18+
* @param default The default coroutine dispatcher.
19+
* @param stringIdGetter Provide the suggestions names based on its string identifier.
20+
* @param assetsGetter Provide the file links for the suggestions images. It doesn't need to create/load the file on
21+
* disk.
22+
* @param suggestionListPerStep Does the map of step to suggestions identifiers list
1923
*/
2024
internal class CategorySuggestionsRepositoryImpl(
21-
private val io: IoCoroutineDispatcher,
25+
private val default: DefaultCoroutineDispatcher,
2226
private val stringIdGetter: StringIdGetter,
2327
private val assetsGetter: AssetsGetter,
2428
private val suggestionListPerStep: SuggestionListPerStep,
@@ -29,7 +33,7 @@ internal class CategorySuggestionsRepositoryImpl(
2933
val list = suggestionListPerStep[step]
3034
val suggestions = list.mapNotNull(::map)
3135
emit(suggestions)
32-
}.flowOn(io)
36+
}.flowOn(default)
3337

3438
private fun map(suggestion: String): CategorySuggestion? {
3539
val name = stringIdGetter.getString(suggestion)

‎features/finances/impl/src/test/kotlin/br/com/mob1st/features/finances/impl/infra/data/repositories/suggestions/CategorySuggestionRepositoryImplTest.kt

+2-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package br.com.mob1st.features.finances.impl.infra.data.repositories.suggestions
22

33
import br.com.mob1st.core.androidx.assets.AssetsGetter
44
import br.com.mob1st.core.androidx.resources.StringIdGetter
5-
import br.com.mob1st.core.kotlinx.coroutines.IoCoroutineDispatcher
5+
import br.com.mob1st.core.kotlinx.coroutines.DefaultCoroutineDispatcher
66
import br.com.mob1st.core.kotlinx.structures.Uri
77
import br.com.mob1st.features.finances.impl.domain.entities.BuilderNextAction
88
import br.com.mob1st.features.finances.impl.domain.entities.CategorySuggestion
@@ -32,9 +32,6 @@ class CategorySuggestionRepositoryImplTest {
3232
private lateinit var assetsGetter: AssetsGetter
3333
private lateinit var suggestionListPerStep: SuggestionListPerStep
3434
private lateinit var timberTree: TestTimberTree
35-
private val io = IoCoroutineDispatcher(
36-
UnconfinedTestDispatcher(),
37-
)
3835

3936
@BeforeEach
4037
fun setUp() {
@@ -44,7 +41,7 @@ class CategorySuggestionRepositoryImplTest {
4441
stringIdGetter = mockk()
4542
assetsGetter = mockk()
4643
repository = CategorySuggestionsRepositoryImpl(
47-
io = io,
44+
default = DefaultCoroutineDispatcher(UnconfinedTestDispatcher()),
4845
stringIdGetter = stringIdGetter,
4946
assetsGetter = assetsGetter,
5047
suggestionListPerStep = suggestionListPerStep,

0 commit comments

Comments
 (0)
Please sign in to comment.