core description
This commit is contained in:
parent
392ebc5115
commit
ad2a8fee80
8 changed files with 318 additions and 19 deletions
|
|
@ -14,6 +14,7 @@ class TestMainDispatcher : BeforeEachCallback, AfterEachCallback {
|
|||
override fun beforeEach(context: ExtensionContext?) {
|
||||
val testDispatcher = TestCoroutineDispatcher()
|
||||
privateTestDispatcher = testDispatcher
|
||||
testDispatcher.pauseDispatcher()
|
||||
DatabaseInitialization.dispatcher = testDispatcher
|
||||
Dispatchers.setMain(testDispatcher)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import org.fnives.test.showcase.testutils.InstantExecutorExtension
|
|||
import org.fnives.test.showcase.testutils.TestMainDispatcher
|
||||
import org.fnives.test.showcase.ui.shared.Event
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.extension.ExtendWith
|
||||
import org.junit.jupiter.params.ParameterizedTest
|
||||
|
|
@ -35,13 +36,14 @@ internal class AuthViewModelTest {
|
|||
@BeforeEach
|
||||
fun setUp() {
|
||||
mockLoginUseCase = mock()
|
||||
testDispatcher.pauseDispatcher()
|
||||
sut = AuthViewModel(mockLoginUseCase)
|
||||
}
|
||||
|
||||
@DisplayName("GIVEN_initialized_viewModel_WHEN_observed_THEN_loading_false_other_fields_are_empty")
|
||||
@Test
|
||||
fun GIVEN_initialized_viewModel_WHEN_observed_THEN_loading_false_other_fields_are_empty() {
|
||||
fun initialSetup() {
|
||||
testDispatcher.resumeDispatcher()
|
||||
|
||||
sut.username.test().assertNoValue()
|
||||
sut.password.test().assertNoValue()
|
||||
sut.loading.test().assertValue(false)
|
||||
|
|
@ -49,8 +51,9 @@ internal class AuthViewModelTest {
|
|||
sut.navigateToHome.test().assertNoValue()
|
||||
}
|
||||
|
||||
@DisplayName("GIVEN_password_text_WHEN_onPasswordChanged_is_called_THEN_password_livedata_is_updated")
|
||||
@Test
|
||||
fun GIVEN_password_text_WHEN_onPasswordChanged_is_called_THEN_password_livedata_is_updated() {
|
||||
fun whenPasswordChangedLiveDataIsUpdated() {
|
||||
testDispatcher.resumeDispatcher()
|
||||
val passwordTestObserver = sut.password.test()
|
||||
|
||||
|
|
@ -64,8 +67,9 @@ internal class AuthViewModelTest {
|
|||
sut.navigateToHome.test().assertNoValue()
|
||||
}
|
||||
|
||||
@DisplayName("GIVEN_username_text_WHEN_onUsernameChanged_is_called_THEN_username_livedata_is_updated")
|
||||
@Test
|
||||
fun GIVEN_username_text_WHEN_onUsernameChanged_is_called_THEN_username_livedata_is_updated() {
|
||||
fun whenUsernameChangedLiveDataIsUpdated() {
|
||||
testDispatcher.resumeDispatcher()
|
||||
val usernameTestObserver = sut.username.test()
|
||||
|
||||
|
|
@ -79,8 +83,9 @@ internal class AuthViewModelTest {
|
|||
sut.navigateToHome.test().assertNoValue()
|
||||
}
|
||||
|
||||
@DisplayName("GIVEN_no_password_or_username_WHEN_login_is_Called_THEN_empty_credentials_are_used_in_usecase")
|
||||
@Test
|
||||
fun GIVEN_no_password_or_username_WHEN_login_is_Called_THEN_empty_credentials_are_used_in_usecase() {
|
||||
fun noPasswordUsesEmptyStringInLoginUseCase() {
|
||||
val loadingTestObserver = sut.loading.test()
|
||||
runBlocking {
|
||||
whenever(mockLoginUseCase.invoke(anyOrNull())).doReturn(Answer.Error(Throwable()))
|
||||
|
|
@ -95,7 +100,7 @@ internal class AuthViewModelTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun WHEN_login_is_Called_twise_THEN_use_case_is_only_called_once() {
|
||||
fun WHEN_login_is_Called_twice_THEN_use_case_is_only_called_once() {
|
||||
runBlocking { whenever(mockLoginUseCase.invoke(anyOrNull())).doReturn(Answer.Error(Throwable())) }
|
||||
|
||||
sut.onLogin()
|
||||
|
|
@ -107,7 +112,7 @@ internal class AuthViewModelTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun GIVEN_password_and_username_WHEN_login_is_Called_THEN_empty_credentials_are_used_in_usecase() {
|
||||
fun GIVEN_password_and_username_WHEN_login_is_Called_THEN_not_empty_credentials_are_used_in_usecase() {
|
||||
runBlocking {
|
||||
whenever(mockLoginUseCase.invoke(anyOrNull())).doReturn(Answer.Error(Throwable()))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,48 @@
|
|||
package org.fnives.test.showcase.ui.auth
|
||||
|
||||
import org.fnives.test.showcase.core.login.LoginUseCase
|
||||
import org.fnives.test.showcase.testutils.InstantExecutorExtension
|
||||
import org.fnives.test.showcase.testutils.TestMainDispatcher
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.extension.ExtendWith
|
||||
import org.mockito.kotlin.mock
|
||||
|
||||
@ExtendWith(InstantExecutorExtension::class, TestMainDispatcher::class)
|
||||
class CodeKataAuthViewModel {
|
||||
|
||||
private lateinit var sut: AuthViewModel
|
||||
private lateinit var mockLoginUseCase: LoginUseCase
|
||||
private val testDispatcher get() = TestMainDispatcher.testDispatcher
|
||||
|
||||
@BeforeEach
|
||||
fun setUp() {
|
||||
mockLoginUseCase = mock()
|
||||
sut = AuthViewModel(mockLoginUseCase)
|
||||
}
|
||||
|
||||
@DisplayName("GIVEN_initialized_viewModel_WHEN_observed_THEN_loading_false_other_fields_are_empty")
|
||||
@Test
|
||||
fun initialSetup() {
|
||||
|
||||
}
|
||||
|
||||
@DisplayName("GIVEN_password_text_WHEN_onPasswordChanged_is_called_THEN_password_livedata_is_updated")
|
||||
@Test
|
||||
fun whenPasswordChangedLiveDataIsUpdated() {
|
||||
|
||||
}
|
||||
|
||||
@DisplayName("GIVEN_username_text_WHEN_onUsernameChanged_is_called_THEN_username_livedata_is_updated")
|
||||
@Test
|
||||
fun whenUsernameChangedLiveDataIsUpdated() {
|
||||
|
||||
}
|
||||
|
||||
@DisplayName("GIVEN_no_password_or_username_WHEN_login_is_Called_THEN_empty_credentials_are_used_in_usecase")
|
||||
@Test
|
||||
fun noPasswordUsesEmptyStringInLoginUseCase() {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
package org.fnives.test.showcase.ui.splash
|
||||
|
||||
import org.fnives.test.showcase.core.login.IsUserLoggedInUseCase
|
||||
import org.fnives.test.showcase.testutils.InstantExecutorExtension
|
||||
import org.fnives.test.showcase.testutils.TestMainDispatcher
|
||||
import org.fnives.test.showcase.ui.shared.Event
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.extension.ExtendWith
|
||||
import org.mockito.kotlin.doReturn
|
||||
import org.mockito.kotlin.mock
|
||||
import org.mockito.kotlin.whenever
|
||||
|
||||
internal class CodeKataSplashViewModelTest {
|
||||
|
||||
@BeforeEach
|
||||
fun setUp() {
|
||||
|
||||
}
|
||||
|
||||
@DisplayName("GIVEN not logged in user WHEN splash started THEN after half a second navigated to authentication")
|
||||
@Test
|
||||
fun loggedOutUserGoesToAuthentication() {
|
||||
|
||||
}
|
||||
|
||||
@DisplayName("GIVEN logged in user WHEN splash started THEN after half a second navigated to home")
|
||||
@Test
|
||||
fun loggedInUserGoestoHome() {
|
||||
|
||||
}
|
||||
|
||||
@DisplayName("GIVEN not logged in user WHEN splash started THEN before half a second no event is sent")
|
||||
@Test
|
||||
fun withoutEnoughTimeNoNavigationHappens() {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -6,13 +6,13 @@ import org.fnives.test.showcase.testutils.InstantExecutorExtension
|
|||
import org.fnives.test.showcase.testutils.TestMainDispatcher
|
||||
import org.fnives.test.showcase.ui.shared.Event
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.extension.ExtendWith
|
||||
import org.mockito.kotlin.doReturn
|
||||
import org.mockito.kotlin.mock
|
||||
import org.mockito.kotlin.whenever
|
||||
|
||||
@Suppress("TestFunctionName")
|
||||
@ExtendWith(InstantExecutorExtension::class, TestMainDispatcher::class)
|
||||
internal class SplashViewModelTest {
|
||||
|
||||
|
|
@ -26,8 +26,9 @@ internal class SplashViewModelTest {
|
|||
sut = SplashViewModel(mockIsUserLoggedInUseCase)
|
||||
}
|
||||
|
||||
@DisplayName("GIVEN not logged in user WHEN splash started THEN after half a second navigated to authentication")
|
||||
@Test
|
||||
fun GIVEN_not_logged_in_user_WHEN_splash_started_THEN_after_half_a_second_navigated_to_authentication() {
|
||||
fun loggedOutUserGoesToAuthentication() {
|
||||
whenever(mockIsUserLoggedInUseCase.invoke()).doReturn(false)
|
||||
|
||||
testCoroutineDispatcher.advanceTimeBy(500)
|
||||
|
|
@ -35,8 +36,9 @@ internal class SplashViewModelTest {
|
|||
sut.navigateTo.test().assertValue(Event(SplashViewModel.NavigateTo.AUTHENTICATION))
|
||||
}
|
||||
|
||||
@DisplayName("GIVEN logged in user WHEN splash started THEN after half a second navigated to home")
|
||||
@Test
|
||||
fun GIVEN_logged_in_user_WHEN_splash_started_THEN_after_half_a_second_navigated_to_home() {
|
||||
fun loggedInUserGoestoHome() {
|
||||
whenever(mockIsUserLoggedInUseCase.invoke()).doReturn(true)
|
||||
|
||||
testCoroutineDispatcher.advanceTimeBy(500)
|
||||
|
|
@ -44,8 +46,9 @@ internal class SplashViewModelTest {
|
|||
sut.navigateTo.test().assertValue(Event(SplashViewModel.NavigateTo.HOME))
|
||||
}
|
||||
|
||||
@DisplayName("GIVEN not logged in user WHEN splash started THEN before half a second no event is sent")
|
||||
@Test
|
||||
fun GIVEN_not_logged_in_user_WHEN_splash_started_THEN_before_half_a_second_no_event_is_sent() {
|
||||
fun withoutEnoughTimeNoNavigationHappens() {
|
||||
whenever(mockIsUserLoggedInUseCase.invoke()).doReturn(false)
|
||||
|
||||
testCoroutineDispatcher.advanceTimeBy(100)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue