-
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.
Reorganize use case - repository structure
- Loading branch information
1 parent
7db29bb
commit b1d1696
Showing
11 changed files
with
146 additions
and
74 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
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
3 changes: 1 addition & 2 deletions
3
app/src/main/java/org/digitalcampus/oppiamobile/domain/useCases/TestApiClientUseCase.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
27 changes: 0 additions & 27 deletions
27
app/src/main/java/org/digitalcampus/oppiamobile/domain/useCases/UserLoginLocalUseCase.kt
This file was deleted.
Oops, something went wrong.
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
56 changes: 56 additions & 0 deletions
56
app/src/test/java/org/digitalcampus/oppiamobile/ui/auth/login/LoginViewModelTest.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,56 @@ | ||
package org.digitalcampus.oppiamobile.ui.auth.login | ||
|
||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.test.advanceUntilIdle | ||
import kotlinx.coroutines.test.runTest | ||
import org.digitalcampus.oppiamobile.domain.model.User | ||
import org.digitalcampus.oppiamobile.domain.useCases.TestApiClientUseCase | ||
import org.digitalcampus.oppiamobile.domain.useCases.UserLoginUseCase | ||
import org.junit.Assert | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.mockito.ArgumentMatchers | ||
import org.mockito.kotlin.mock | ||
import org.mockito.kotlin.whenever | ||
import utils.MainCoroutineRule | ||
|
||
internal class LoginViewModelTest { | ||
|
||
private val userLoginUseCase = mock<UserLoginUseCase>() | ||
private val testApiClientUseCase = mock<TestApiClientUseCase>() | ||
|
||
val viewmodel by lazy { LoginViewModel(userLoginUseCase, testApiClientUseCase) } | ||
|
||
@ExperimentalCoroutinesApi | ||
@get:Rule | ||
var mainCoroutineRule = MainCoroutineRule() | ||
|
||
@Test | ||
fun `test login successful`() = runTest { | ||
val expectedUser = User( | ||
email = "testEmail@test.com", | ||
username = "testUsername", | ||
firstName = "Test", | ||
lastName = "User", | ||
apiKey = "testApiKey" | ||
) | ||
whenever(userLoginUseCase.invoke(ArgumentMatchers.anyString(), ArgumentMatchers.anyString())) | ||
.thenReturn(expectedUser) | ||
|
||
viewmodel.onLoginClick("testUsername", "Some Password") | ||
advanceUntilIdle() | ||
Assert.assertEquals(expectedUser, viewmodel.uiState.value.user) | ||
} | ||
|
||
@Test | ||
fun `test user is empty`() = runTest { | ||
viewmodel.onLoginClick("", "") | ||
Assert.assertEquals("Username is empty", viewmodel.uiState.value.error) | ||
} | ||
|
||
@Test | ||
fun `test password is empty`() = runTest { | ||
viewmodel.onLoginClick("someUsername", "") | ||
Assert.assertEquals("Password is empty", viewmodel.uiState.value.error) | ||
} | ||
} |
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,25 @@ | ||
package utils | ||
|
||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.test.StandardTestDispatcher | ||
import kotlinx.coroutines.test.TestDispatcher | ||
import kotlinx.coroutines.test.resetMain | ||
import kotlinx.coroutines.test.setMain | ||
import org.junit.rules.TestWatcher | ||
import org.junit.runner.Description | ||
|
||
@ExperimentalCoroutinesApi | ||
class MainCoroutineRule(private val testDispatcher: TestDispatcher = StandardTestDispatcher()) : | ||
TestWatcher() { | ||
|
||
override fun starting(description: Description) { | ||
super.starting(description) | ||
Dispatchers.setMain(testDispatcher) | ||
} | ||
|
||
override fun finished(description: Description) { | ||
super.finished(description) | ||
Dispatchers.resetMain() | ||
} | ||
} |