1+ package com.example.android.dagger.splash
2+
3+ import com.example.android.dagger.login.LoginActivity
4+ import com.example.android.dagger.main.MainActivity
5+ import com.example.android.dagger.registration.RegistrationActivity
6+ import com.example.android.dagger.user.UserManager
7+ import org.junit.Assert.assertEquals
8+ import org.junit.Before
9+ import org.junit.Test
10+ import org.mockito.Mockito.mock
11+ import org.mockito.Mockito.`when` as whenever
12+
13+ class SplashViewModelTest {
14+
15+ private lateinit var userManager: UserManager
16+ private lateinit var viewModel: SplashViewModel
17+
18+ @Before
19+ fun setup () {
20+ userManager = mock(UserManager ::class .java)
21+ viewModel = SplashViewModel (userManager)
22+ }
23+
24+ @Test
25+ fun `If the user is not registered then getActivityClass returns RegistrationActivity` () {
26+ whenever(userManager.isUserRegistered()).thenReturn(false )
27+
28+ assertEquals(RegistrationActivity ::class .java, viewModel.getActivityClass())
29+ }
30+
31+ @Test
32+ fun `If the user is registered but not logged in then getActivityClass returns LoginActivity` () {
33+ whenever(userManager.isUserRegistered()).thenReturn(true )
34+ whenever(userManager.isUserLoggedIn()).thenReturn(false )
35+
36+ assertEquals(LoginActivity ::class .java, viewModel.getActivityClass())
37+ }
38+
39+ @Test
40+ fun `If the user is logged in then getActivityClass returns MainActivity` () {
41+ whenever(userManager.isUserLoggedIn()).thenReturn(true )
42+
43+ assertEquals(MainActivity ::class .java, viewModel.getActivityClass())
44+ }
45+ }
0 commit comments