-
Notifications
You must be signed in to change notification settings - Fork 263
Add unit test for HomeViewModel #154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
neelanshsahai
wants to merge
2
commits into
credman-compose
Choose a base branch
from
shrineTests
base: credman-compose
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
135 changes: 135 additions & 0 deletions
135
Shrine/app/src/main/java/com/authentication/shrine/di/AppModule.kt
This file contains hidden or 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,135 @@ | ||
/* | ||
* Copyright 2025 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.authentication.shrine.di | ||
|
||
import android.app.Application | ||
import android.content.Context | ||
import android.os.Build | ||
import androidx.credentials.CredentialManager | ||
import androidx.datastore.core.DataStore | ||
import androidx.datastore.dataStore | ||
import androidx.datastore.preferences.core.PreferenceDataStoreFactory | ||
import androidx.datastore.preferences.core.Preferences | ||
import androidx.datastore.preferences.preferencesDataStoreFile | ||
import com.authentication.shrine.BuildConfig | ||
import com.authentication.shrine.CredentialManagerUtils | ||
import com.authentication.shrine.api.AddHeaderInterceptor | ||
import com.authentication.shrine.api.AuthApiService | ||
import com.authentication.shrine.repository.AuthRepository | ||
import com.authentication.shrine.repository.AuthenticationRepository | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import dagger.hilt.components.SingletonComponent | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.SupervisorJob | ||
import okhttp3.OkHttpClient | ||
import okhttp3.logging.HttpLoggingInterceptor | ||
import retrofit2.Retrofit | ||
import retrofit2.converter.gson.GsonConverterFactory | ||
import java.util.concurrent.TimeUnit | ||
import javax.inject.Singleton | ||
|
||
/** | ||
* A Dagger Hilt module that provides dependencies for the application. | ||
*/ | ||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object AppModule { | ||
|
||
/** | ||
* Creates and provides an OkHttpClient instance with interceptors and timeouts. | ||
* | ||
* @return The OkHttpClient instance. | ||
*/ | ||
@Singleton | ||
@Provides | ||
fun provideOkHttpClient(): OkHttpClient { | ||
val userAgent = "${BuildConfig.APPLICATION_ID}/${BuildConfig.VERSION_NAME} " + | ||
"(Android ${Build.VERSION.RELEASE}; ${Build.MODEL}; ${Build.BRAND})" | ||
return OkHttpClient.Builder() | ||
.addInterceptor(AddHeaderInterceptor(userAgent)) | ||
.addInterceptor( | ||
HttpLoggingInterceptor().apply { | ||
level = HttpLoggingInterceptor.Level.BODY | ||
}, | ||
) | ||
.readTimeout(30, TimeUnit.SECONDS) | ||
.writeTimeout(40, TimeUnit.SECONDS) | ||
.connectTimeout(40, TimeUnit.SECONDS) | ||
.build() | ||
} | ||
|
||
/** | ||
* Provides a singleton instance of the CoroutineScope. | ||
* | ||
* @return The CoroutineScope instance. | ||
*/ | ||
@Singleton | ||
@Provides | ||
fun provideAppCoroutineScope(): CoroutineScope = CoroutineScope(SupervisorJob()) | ||
|
||
/** | ||
* Provides a DataStore instance with the file name "auth". | ||
* | ||
* @param application The application context. | ||
* @return The DataStore instance. | ||
*/ | ||
@Singleton | ||
@Provides | ||
fun provideDataStore(application: Application): DataStore<Preferences> { | ||
return PreferenceDataStoreFactory.create { | ||
application.preferencesDataStoreFile("auth") | ||
} | ||
} | ||
|
||
@Singleton | ||
@Provides | ||
fun providesCredentialManager(@ApplicationContext context: Context): CredentialManager { | ||
return CredentialManager.create(context) | ||
} | ||
|
||
@Singleton | ||
@Provides | ||
fun providesCredentialManagerUtils( | ||
credentialManager: CredentialManager, | ||
): CredentialManagerUtils { | ||
return CredentialManagerUtils( | ||
credentialManager = credentialManager, | ||
) | ||
} | ||
|
||
@Singleton | ||
@Provides | ||
fun provideAuthApiService(okHttpClient: OkHttpClient): AuthApiService { | ||
return Retrofit.Builder() | ||
.baseUrl(BuildConfig.API_BASE_URL) | ||
.client(okHttpClient) | ||
.addConverterFactory(GsonConverterFactory.create()) | ||
.build() | ||
.create(AuthApiService::class.java) | ||
} | ||
|
||
@Singleton | ||
@Provides | ||
fun provideAuthRepository( | ||
dataStore: DataStore<Preferences>, | ||
authApiService: AuthApiService, | ||
): AuthenticationRepository { | ||
return AuthRepository(dataStore, authApiService) | ||
} | ||
} |
19 changes: 17 additions & 2 deletions
19
Shrine/app/src/main/java/com/authentication/shrine/model/FederationOptionsRequest.kt
This file contains hidden or 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,9 +1,24 @@ | ||
/* | ||
* Copyright 2025 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.authentication.shrine.model | ||
|
||
/** | ||
* Represents the request body for getting federation options from the server. | ||
* @param urls a list of urls to send for federated requests. | ||
*/ | ||
data class FederationOptionsRequest( | ||
val urls: List<String> = listOf("https://accounts.google.com") | ||
) | ||
val urls: List<String> = listOf("https://accounts.google.com"), | ||
) |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This import is unused and can be removed.