Feature/mockito setup (#48)
* mockito set up * added mockito basic setup * handled teminated cases
This commit is contained in:
committed by
GitHub Enterprise
parent
9a88bcabd4
commit
1e816a43d3
@@ -75,4 +75,9 @@ dependencies {
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
|
||||
testImplementation 'org.mockito:mockito-core:2.19.0'
|
||||
androidTestImplementation 'android.arch.core:core-testing:1.1.1'
|
||||
testImplementation 'android.arch.core:core-testing:1.0.0'
|
||||
testImplementation 'org.mockito:mockito-inline:2.13.0'
|
||||
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.navi.medici.androidCustomerApp.models.request.RegisterRequest
|
||||
import com.navi.medici.androidCustomerApp.models.response.RegisterResponse
|
||||
import com.navi.medici.androidCustomerApp.network.RepoResult
|
||||
import com.navi.medici.androidCustomerApp.registration.repositories.RegisterRepository
|
||||
import com.navi.medici.androidCustomerApp.utils.Constants.CHANNEL_ID
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
@@ -24,12 +26,16 @@ class SplashVM : ViewModel() {
|
||||
val isBlacklisted: LiveData<Boolean>
|
||||
get() = _isBlacklisted
|
||||
|
||||
val result = MutableLiveData<RepoResult<RegisterResponse>>()
|
||||
|
||||
fun checkDevice(imei: String) {
|
||||
Timber.i("IMEI $imei")
|
||||
val registerRequest = RegisterRequest(imei, CHANNEL_ID)
|
||||
coroutineScope.launch {
|
||||
val response = registerRepository.checkDevice(registerRequest)
|
||||
Timber.i("Register response $response")
|
||||
|
||||
result.value = response
|
||||
if (response.exception == null) {
|
||||
_isBlacklisted.value = response.response.data?.success?.not()
|
||||
} else {
|
||||
|
||||
@@ -12,6 +12,7 @@ import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.navi.medici.androidCustomerApp.app.NaviApplication
|
||||
import com.navi.medici.androidCustomerApp.common.PreferenceManager
|
||||
import com.navi.medici.androidCustomerApp.models.response.UploadPanResponse
|
||||
import com.navi.medici.androidCustomerApp.repositories.UploadPanRepository
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@@ -29,7 +30,7 @@ class UploadPanVM : ViewModel() {
|
||||
private val coroutineScope = CoroutineScope(Dispatchers.Main)
|
||||
private val uploadPanRepository = UploadPanRepository()
|
||||
|
||||
val imageBitmap = MutableLiveData< Bitmap>()
|
||||
val imageBitmap = MutableLiveData<Bitmap>()
|
||||
|
||||
fun uploadPan(file: File) {
|
||||
val reqFile = RequestBody.create(MediaType.parse("application/x-www-form-urlencoded"), file)
|
||||
@@ -45,8 +46,12 @@ class UploadPanVM : ViewModel() {
|
||||
)
|
||||
Timber.i("Upload PAN response $response")
|
||||
if (response.exception == null) {
|
||||
_panUploaded.value = true
|
||||
setUploadPan(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun setUploadPan(res: Boolean) {
|
||||
_panUploaded.value = res
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* *
|
||||
* * Copyright (c) 2019 . All rights reserved @Navi
|
||||
*
|
||||
*/
|
||||
|
||||
package com.navi.medici.androidCustomerApp.registration.viewmodel
|
||||
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.Mock
|
||||
import org.mockito.junit.MockitoJUnitRunner
|
||||
|
||||
|
||||
@RunWith(MockitoJUnitRunner::class)
|
||||
class LoginPageVMTest {
|
||||
|
||||
@Mock
|
||||
lateinit var loginPageVm: LoginPageVM
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
loginPageVm = LoginPageVM()
|
||||
}
|
||||
|
||||
@After
|
||||
fun tearDown() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun onChangePhoneNumber() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* *
|
||||
* * Copyright (c) 2019 . All rights reserved @Navi
|
||||
*
|
||||
*/
|
||||
|
||||
package com.navi.medici.androidCustomerApp.registration.viewmodel
|
||||
|
||||
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
|
||||
import org.junit.runner.RunWith
|
||||
import org.junit.Rule
|
||||
import org.mockito.junit.MockitoJUnitRunner
|
||||
|
||||
|
||||
@RunWith(MockitoJUnitRunner::class)
|
||||
class SplashVMTest {
|
||||
|
||||
@get: Rule
|
||||
var instantExecutorRule = InstantTaskExecutorRule()
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun checkDevice() = runBlocking {
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
fun tearDown() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* *
|
||||
* * Copyright (c) 2019 . All rights reserved @Navi
|
||||
*
|
||||
*/
|
||||
|
||||
package com.navi.medici.androidCustomerApp.useridentityupload.viewmodel
|
||||
|
||||
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
|
||||
import androidx.lifecycle.Observer
|
||||
import com.navi.medici.androidCustomerApp.utils.log
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Rule
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.ArgumentCaptor
|
||||
import org.mockito.Mockito.*
|
||||
import org.mockito.junit.MockitoJUnitRunner
|
||||
|
||||
|
||||
@RunWith(MockitoJUnitRunner::class)
|
||||
class UploadPanVMTest {
|
||||
|
||||
inline fun <reified T> mock(): T = mock(T::class.java)
|
||||
|
||||
@get:Rule
|
||||
val rule = InstantTaskExecutorRule()
|
||||
|
||||
private lateinit var uploadPanVm: UploadPanVM
|
||||
private val uploadPanObserver: Observer<Boolean> = mock()
|
||||
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
uploadPanVm = UploadPanVM()
|
||||
uploadPanVm.panUploaded.observeForever(uploadPanObserver)
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun setPanUploadRes() {
|
||||
val expectedResponse = true
|
||||
uploadPanVm.setUploadPan(true)
|
||||
|
||||
val captor = ArgumentCaptor.forClass(Boolean::class.java)
|
||||
captor.run {
|
||||
verify(uploadPanObserver, times(1)).onChanged(capture())
|
||||
assertEquals(expectedResponse, value)
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
fun tearDown() {
|
||||
try {
|
||||
uploadPanVm.panUploaded.removeObserver(uploadPanObserver)
|
||||
} catch (e: Exception) {
|
||||
e.log()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user