Loading app/src/main/java/foundation/e/apps/domain/common/repository/CacheRepositoryImpl.kt +1 −1 Original line number Diff line number Diff line Loading @@ -51,7 +51,7 @@ class CacheRepositoryImpl @Inject constructor( override fun cacheAuthData(): AuthData = applicationContext.configurations.authData.let { data -> if (data.isEmpty()) throw Exception("Auth Data not available") if (data.isEmpty()) throw RuntimeException("Auth Data not available") return data.toAuthData() } Loading app/src/test/java/foundation/e/apps/presentation/login/LoginViewModelTest.ktdeleted 100644 → 0 +0 −88 Original line number Diff line number Diff line /* * Copyright MURENA SAS 2023 * Apps Quickly and easily install Android apps onto your device! * * 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. * * This program 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 this program. If not, see <https://www.gnu.org/licenses/>. */ package foundation.e.apps.presentation.login import androidx.arch.core.executor.testing.InstantTaskExecutorRule import foundation.e.apps.data.login.LoginSourceRepository import foundation.e.apps.domain.login.usecase.NoGoogleModeUseCase import foundation.e.apps.domain.login.usecase.UserLoginUseCase import foundation.e.apps.loginFailureMessage import foundation.e.apps.testAnonymousResponseData import foundation.e.apps.utils.Resource import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.test.StandardTestDispatcher import kotlinx.coroutines.test.resetMain import kotlinx.coroutines.test.runTest import kotlinx.coroutines.test.setMain import org.junit.After import org.junit.Before import org.junit.Rule import org.junit.Test import org.mockito.Mock import org.mockito.Mockito import org.mockito.MockitoAnnotations @OptIn(ExperimentalCoroutinesApi::class) class LoginViewModelTest { private val testDispatcher = StandardTestDispatcher() @get:Rule val rule = InstantTaskExecutorRule() @Mock lateinit var mockUserLoginUseCase: UserLoginUseCase @Mock lateinit var mockNoGoogleModeUseCase: NoGoogleModeUseCase @Mock lateinit var loginRepository: LoginSourceRepository @Before fun setUp() { MockitoAnnotations.openMocks(this) Dispatchers.setMain(testDispatcher) } @Test fun testOnSuccessReturnLogInStateTrue() = runTest { Mockito.`when`(mockUserLoginUseCase.anonymousUser()) .thenReturn(flowOf(Resource.Success(testAnonymousResponseData))) } @Test fun testOnFailureReturnLogInStateFalseWithError() = runTest { Mockito.`when`(mockUserLoginUseCase.anonymousUser()) .thenReturn(flowOf(Resource.Error(loginFailureMessage, null))) } @Test fun testOnLoadingReturnLogInStateFalse() = runTest { Mockito.`when`(mockUserLoginUseCase.anonymousUser()) .thenReturn(flowOf(Resource.Loading(null))) } @After fun tearDown() { Dispatchers.resetMain() } } Loading
app/src/main/java/foundation/e/apps/domain/common/repository/CacheRepositoryImpl.kt +1 −1 Original line number Diff line number Diff line Loading @@ -51,7 +51,7 @@ class CacheRepositoryImpl @Inject constructor( override fun cacheAuthData(): AuthData = applicationContext.configurations.authData.let { data -> if (data.isEmpty()) throw Exception("Auth Data not available") if (data.isEmpty()) throw RuntimeException("Auth Data not available") return data.toAuthData() } Loading
app/src/test/java/foundation/e/apps/presentation/login/LoginViewModelTest.ktdeleted 100644 → 0 +0 −88 Original line number Diff line number Diff line /* * Copyright MURENA SAS 2023 * Apps Quickly and easily install Android apps onto your device! * * 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. * * This program 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 this program. If not, see <https://www.gnu.org/licenses/>. */ package foundation.e.apps.presentation.login import androidx.arch.core.executor.testing.InstantTaskExecutorRule import foundation.e.apps.data.login.LoginSourceRepository import foundation.e.apps.domain.login.usecase.NoGoogleModeUseCase import foundation.e.apps.domain.login.usecase.UserLoginUseCase import foundation.e.apps.loginFailureMessage import foundation.e.apps.testAnonymousResponseData import foundation.e.apps.utils.Resource import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.test.StandardTestDispatcher import kotlinx.coroutines.test.resetMain import kotlinx.coroutines.test.runTest import kotlinx.coroutines.test.setMain import org.junit.After import org.junit.Before import org.junit.Rule import org.junit.Test import org.mockito.Mock import org.mockito.Mockito import org.mockito.MockitoAnnotations @OptIn(ExperimentalCoroutinesApi::class) class LoginViewModelTest { private val testDispatcher = StandardTestDispatcher() @get:Rule val rule = InstantTaskExecutorRule() @Mock lateinit var mockUserLoginUseCase: UserLoginUseCase @Mock lateinit var mockNoGoogleModeUseCase: NoGoogleModeUseCase @Mock lateinit var loginRepository: LoginSourceRepository @Before fun setUp() { MockitoAnnotations.openMocks(this) Dispatchers.setMain(testDispatcher) } @Test fun testOnSuccessReturnLogInStateTrue() = runTest { Mockito.`when`(mockUserLoginUseCase.anonymousUser()) .thenReturn(flowOf(Resource.Success(testAnonymousResponseData))) } @Test fun testOnFailureReturnLogInStateFalseWithError() = runTest { Mockito.`when`(mockUserLoginUseCase.anonymousUser()) .thenReturn(flowOf(Resource.Error(loginFailureMessage, null))) } @Test fun testOnLoadingReturnLogInStateFalse() = runTest { Mockito.`when`(mockUserLoginUseCase.anonymousUser()) .thenReturn(flowOf(Resource.Loading(null))) } @After fun tearDown() { Dispatchers.resetMain() } }