Skip to content
This repository was archived by the owner on Dec 10, 2024. It is now read-only.

Commit 4f33a7e

Browse files
filogranoGiuseppe Filograno
authored andcommitted
Add unit tests on SplashViewModel
1 parent c73fcc0 commit 4f33a7e

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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

Comments
 (0)