-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from azrael8576/chore/datastore-test
- Loading branch information
Showing
7 changed files
with
75 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
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,22 @@ | ||
plugins { | ||
alias(libs.plugins.pq.android.library) | ||
alias(libs.plugins.pq.android.hilt) | ||
alias(libs.plugins.protobuf) | ||
} | ||
|
||
android { | ||
namespace = "com.wei.picquest.core.datastore.test" | ||
} | ||
|
||
dependencies { | ||
api(project(":core:datastore")) | ||
implementation(project(":core:testing")) | ||
implementation(project(":core:common")) | ||
implementation(project(":core:model")) | ||
|
||
// DataStore | ||
implementation(libs.androidx.datastore) | ||
|
||
// Protobuf | ||
implementation(libs.protobuf.kotlin.lite) | ||
} |
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,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
</manifest> |
45 changes: 45 additions & 0 deletions
45
.../datastore-test/src/main/java/com/wei/picquest/core/datastore/test/TestDataStoreModule.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,45 @@ | ||
package com.wei.picquest.core.datastore.test | ||
|
||
import androidx.datastore.core.DataStore | ||
import androidx.datastore.core.DataStoreFactory | ||
import com.wei.picquest.core.datastore.UserPreferences | ||
import com.wei.picquest.core.datastore.UserPreferencesSerializer | ||
import com.wei.picquest.core.datastore.di.DataStoreModule | ||
import com.wei.picquest.core.network.di.ApplicationScope | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.components.SingletonComponent | ||
import dagger.hilt.testing.TestInstallIn | ||
import kotlinx.coroutines.CoroutineScope | ||
import org.junit.rules.TemporaryFolder | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@TestInstallIn( | ||
components = [SingletonComponent::class], | ||
replaces = [DataStoreModule::class], | ||
) | ||
object TestDataStoreModule { | ||
|
||
@Provides | ||
@Singleton | ||
fun providesUserPreferencesDataStore( | ||
@ApplicationScope scope: CoroutineScope, | ||
userPreferencesSerializer: UserPreferencesSerializer, | ||
tmpFolder: TemporaryFolder, | ||
): DataStore<UserPreferences> = | ||
tmpFolder.testUserPreferencesDataStore( | ||
coroutineScope = scope, | ||
userPreferencesSerializer = userPreferencesSerializer, | ||
) | ||
} | ||
|
||
fun TemporaryFolder.testUserPreferencesDataStore( | ||
coroutineScope: CoroutineScope, | ||
userPreferencesSerializer: UserPreferencesSerializer = UserPreferencesSerializer(), | ||
) = DataStoreFactory.create( | ||
serializer = userPreferencesSerializer, | ||
scope = coroutineScope, | ||
) { | ||
newFile("user_preferences_test.pb") | ||
} |
File renamed without changes.
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