-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Provide TestScope as ApplicationScope in tests (#364)
Previously some tests had to manually create dependencies (instead of injecting them) because the dependency required the `TestScope` `CoroutineScope` as one of its dependencies. Resolve this with a `FakeCoroutineScopeModule` that provides `TestScope` as `@ApplicationScope`. The tests can now inject their dependencies, which will use `TestScope`. To inject `AccountPreferenceDataStore` it has been updated to use the current active account when reading or writing preferences.
- Loading branch information
1 parent
993b746
commit aaf8cf5
Showing
6 changed files
with
56 additions
and
105 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
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
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
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
38 changes: 38 additions & 0 deletions
38
app/src/test/java/app/pachli/di/FakeCoroutineScopeModule.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,38 @@ | ||
/* | ||
* Copyright 2024 Pachli Association | ||
* | ||
* This file is a part of Pachli. | ||
* | ||
* This program is free software; you can redistribute it and/or modify it under the terms of the | ||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* Pachli is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even | ||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | ||
* Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with Pachli; if not, | ||
* see <http://www.gnu.org/licenses>. | ||
*/ | ||
|
||
package app.pachli.di | ||
|
||
import app.pachli.core.common.di.ApplicationScope | ||
import app.pachli.core.common.di.CoroutineScopeModule | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.components.SingletonComponent | ||
import dagger.hilt.testing.TestInstallIn | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.test.TestScope | ||
|
||
@TestInstallIn( | ||
components = [SingletonComponent::class], | ||
replaces = [CoroutineScopeModule::class], | ||
) | ||
@Module | ||
object FakeCoroutineScopeModule { | ||
@ApplicationScope | ||
@Provides | ||
fun providesApplicationScope(): CoroutineScope = TestScope() | ||
} |
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