Skip to content
This repository has been archived by the owner on Aug 4, 2019. It is now read-only.

Commit

Permalink
Use Any string for tests,closed #51
Browse files Browse the repository at this point in the history
  • Loading branch information
TinaT2 committed Aug 3, 2019
1 parent 9be955b commit e26ba7a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class UserRepositoryTest : BaseTest() {

companion object {

val sUser = UserModel("", "", "989359323175", "123456", "")
val sUser = UserModel("", "", "981234567", "123456", "")
}

private lateinit var mUserRepository: UserRepository
Expand All @@ -38,7 +38,7 @@ class UserRepositoryTest : BaseTest() {
@Test
fun claimUser_claimToApi() {
mUserRepository.claim(sUser.mPhone, sUser.mUdid)
Mockito.verify(apiInterface).claim(sUser.mPhone, sUser.mUdid)
Mockito.verify(apiInterface).claim(Mockito.anyString(),Mockito.anyString())
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import retrofit2.Response
class EmailVerificationViewModelTest : BaseTest() {

companion object {
private val sEmail = EmailVerificationModel("tina.t2aq@gmail.com")
private val sEmail = EmailVerificationModel("ab@bc.com")
private const val TOKEN =
"eyJhbGciOiJIUzI1NiIsImlhdCI6MTU2Mzk2Njk0OCwiZXhwIjoxNTcyNTY2OTQ4fQ.eyJpZCI6NCwiZGV2aWNlX2lkIjoxLCJwaG9uZSI6Iis5ODkzNTkzMjMxNzUiLCJyb2xlcyI6WyJjbGllbnQiXSwic2Vzc2lvbklkIjoiMTk5YmM4ZWItN2ExNC00YjBjLWI2YWMtNzQyZWQ1YTViNTk3IiwiZW1haWwiOiIiLCJpc0FjdGl2ZSI6ZmFsc2V9.sa0z7_2R-u94DlUQ0JEoaCHXi-ULaU5mJFy2KDjm_oM"
private val sWrongEmail = EmailVerificationModel("tinat2aq")
private val sWrongEmail = EmailVerificationModel("abc")
}

@get:Rule
Expand Down Expand Up @@ -58,11 +58,11 @@ class EmailVerificationViewModelTest : BaseTest() {
Response.success(200, sEmail)
).delaySubscription(delayer)
Mockito.`when`(
mEmailRepository.setEmail(TOKEN, sEmail.mEmail)
mEmailRepository.setEmail(Mockito.anyString(), Mockito.anyString())
).thenReturn(singleResponse)
Mockito.`when`(mValidatorUtils.emailValidator(sEmail.mEmail)).thenReturn(true)
Mockito.`when`(mValidatorUtils.emailValidator(Mockito.anyString())).thenReturn(true)
mEmailVerificationViewModel.setEmail(TOKEN, sEmail.mEmail)
Mockito.verify(mEmailRepository).setEmail(TOKEN, sEmail.mEmail)
Mockito.verify(mEmailRepository).setEmail(Mockito.anyString(), Mockito.anyString())
Assert.assertEquals(
LiveDataTestUtil.getValue(mEmailVerificationViewModel.getSetEmailLiveData()).status,
Status.LOADING
Expand All @@ -88,10 +88,10 @@ class EmailVerificationViewModelTest : BaseTest() {
Response.error<EmailVerificationModel>(
400,
ResponseBody.create(MediaType.parse("text/plain"), ""))).delaySubscription(delayer)
Mockito.`when`(mEmailRepository.setEmail(TOKEN, sEmail.mEmail)).thenReturn(singleResponse)
Mockito.`when`(mValidatorUtils.emailValidator(sEmail.mEmail)).thenReturn(true)
Mockito.`when`(mEmailRepository.setEmail(Mockito.anyString(), Mockito.anyString())).thenReturn(singleResponse)
Mockito.`when`(mValidatorUtils.emailValidator(Mockito.anyString())).thenReturn(true)
mEmailVerificationViewModel.setEmail(TOKEN, sEmail.mEmail)
Mockito.verify(mEmailRepository).setEmail(TOKEN, sEmail.mEmail)
Mockito.verify(mEmailRepository).setEmail(Mockito.anyString(), Mockito.anyString())
Assert.assertEquals(
LiveDataTestUtil.getValue(mEmailVerificationViewModel.getSetEmailLiveData()).status,
Status.LOADING
Expand Down Expand Up @@ -119,13 +119,13 @@ class EmailVerificationViewModelTest : BaseTest() {
)
).delaySubscription(delayer)
Mockito.`when`(
mEmailRepository.setEmail(TOKEN, sEmail.mEmail)
mEmailRepository.setEmail(Mockito.anyString(), Mockito.anyString())
).thenReturn(singleResponse)
Mockito.`when`(mValidatorUtils.emailValidator(sEmail.mEmail)).thenReturn(true)
Mockito.`when`(mValidatorUtils.emailValidator(Mockito.anyString())).thenReturn(true)
mEmailVerificationViewModel.setEmail(
TOKEN, sEmail.mEmail
)
Mockito.verify(mEmailRepository).setEmail(TOKEN, sEmail.mEmail)
Mockito.verify(mEmailRepository).setEmail(Mockito.anyString(), Mockito.anyString())
Assert.assertEquals(
LiveDataTestUtil.getValue(mEmailVerificationViewModel.getSetEmailLiveData()).status,
Status.LOADING
Expand All @@ -151,12 +151,12 @@ class EmailVerificationViewModelTest : BaseTest() {
ResponseBody.create(MediaType.parse("text/plain"), "")
)
).delaySubscription(delayer)
Mockito.`when`(mEmailRepository.setEmail(TOKEN, sEmail.mEmail)).thenReturn(singleResponse)
Mockito.`when`(mValidatorUtils.emailValidator(sEmail.mEmail)).thenReturn(true)
Mockito.`when`(mEmailRepository.setEmail(Mockito.anyString(), Mockito.anyString())).thenReturn(singleResponse)
Mockito.`when`(mValidatorUtils.emailValidator(Mockito.anyString())).thenReturn(true)
mEmailVerificationViewModel.setEmail(
TOKEN, sEmail.mEmail
)
Mockito.verify(mEmailRepository).setEmail(TOKEN, sEmail.mEmail)
Mockito.verify(mEmailRepository).setEmail(Mockito.anyString(), Mockito.anyString())
Assert.assertEquals(
LiveDataTestUtil.getValue(mEmailVerificationViewModel.getSetEmailLiveData()).status,
Status.LOADING
Expand All @@ -182,10 +182,10 @@ class EmailVerificationViewModelTest : BaseTest() {
ResponseBody.create(MediaType.parse("text/plain"), "")
)
).delaySubscription(delayer)
Mockito.`when`(mEmailRepository.setEmail(TOKEN, sEmail.mEmail)).thenReturn(singleResponse)
Mockito.`when`(mValidatorUtils.emailValidator(sEmail.mEmail)).thenReturn(true)
Mockito.`when`(mEmailRepository.setEmail(Mockito.anyString(), Mockito.anyString())).thenReturn(singleResponse)
Mockito.`when`(mValidatorUtils.emailValidator(Mockito.anyString())).thenReturn(true)
mEmailVerificationViewModel.setEmail(TOKEN, sEmail.mEmail)
Mockito.verify(mEmailRepository).setEmail(TOKEN, sEmail.mEmail)
Mockito.verify(mEmailRepository).setEmail(Mockito.anyString(), Mockito.anyString())
Assert.assertEquals(
LiveDataTestUtil.getValue(mEmailVerificationViewModel.getSetEmailLiveData()).status,
Status.LOADING
Expand All @@ -211,10 +211,10 @@ class EmailVerificationViewModelTest : BaseTest() {
ResponseBody.create(MediaType.parse("text/plain"), "")
)
).delaySubscription(delayer)
Mockito.`when`(mEmailRepository.setEmail(TOKEN, sEmail.mEmail)).thenReturn(singleResponse)
Mockito.`when`(mValidatorUtils.emailValidator(sEmail.mEmail)).thenReturn(true)
Mockito.`when`(mEmailRepository.setEmail(Mockito.anyString(), Mockito.anyString())).thenReturn(singleResponse)
Mockito.`when`(mValidatorUtils.emailValidator(Mockito.anyString())).thenReturn(true)
mEmailVerificationViewModel.setEmail(TOKEN, sEmail.mEmail)
Mockito.verify(mEmailRepository).setEmail(TOKEN, sEmail.mEmail)
Mockito.verify(mEmailRepository).setEmail(Mockito.anyString(), Mockito.anyString())
Assert.assertEquals(
LiveDataTestUtil.getValue(mEmailVerificationViewModel.getSetEmailLiveData()).status,
Status.LOADING
Expand All @@ -238,10 +238,10 @@ class EmailVerificationViewModelTest : BaseTest() {
val singleResponse = Single
.error<Response<EmailVerificationModel>>(Exception())
.delaySubscription(delayer)
Mockito.`when`(mEmailRepository.setEmail(TOKEN, sEmail.mEmail)).thenReturn(singleResponse)
Mockito.`when`(mValidatorUtils.emailValidator(sEmail.mEmail)).thenReturn(true)
Mockito.`when`(mEmailRepository.setEmail(Mockito.anyString(), Mockito.anyString())).thenReturn(singleResponse)
Mockito.`when`(mValidatorUtils.emailValidator(Mockito.anyString())).thenReturn(true)
mEmailVerificationViewModel.setEmail(TOKEN, sEmail.mEmail)
Mockito.verify(mEmailRepository).setEmail(TOKEN, sEmail.mEmail)
Mockito.verify(mEmailRepository).setEmail(Mockito.anyString(), Mockito.anyString())
Assert.assertEquals(
LiveDataTestUtil.getValue(mEmailVerificationViewModel.getSetEmailLiveData()).status,
Status.LOADING
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class PhoneInputViewModelTest : BaseTest() {


companion object {
private val sUser = UserModel(mPhone = "989359323175", mUdid = "123456")
private val wrongUserPhone = UserModel(mPhone = "a359323175", mUdid = "123456")
private val sUser = UserModel(mPhone = "9812345678", mUdid = "123456")
private val sWrongUserPhone = UserModel(mPhone = "a12345", mUdid = "123456")
}

@get:Rule
Expand Down Expand Up @@ -59,10 +59,10 @@ class PhoneInputViewModelTest : BaseTest() {
val singleResponse = Single.just(
Response.success(200, sUser)
).delaySubscription(delayer)
Mockito.`when`(mUserRepository.claim(sUser.mPhone, sUser.mUdid)).thenReturn(singleResponse)
Mockito.`when`(mValidatorUtils.phoneValidator(sUser.mPhone)).thenReturn(true)
Mockito.`when`(mUserRepository.claim(Mockito.anyString(),Mockito.anyString())).thenReturn(singleResponse)
Mockito.`when`(mValidatorUtils.phoneValidator(Mockito.anyString())).thenReturn(true)
mRegistrationViewModel.claim(sUser.mPhone, sUser.mUdid)
Mockito.verify(mUserRepository).claim(sUser.mPhone, sUser.mUdid)
Mockito.verify(mUserRepository).claim(Mockito.anyString(),Mockito.anyString())
Assert.assertEquals(
LiveDataTestUtil.getValue(mRegistrationViewModel.getClaimLiveData()).status,
Status.LOADING
Expand All @@ -85,10 +85,10 @@ class PhoneInputViewModelTest : BaseTest() {
)
)
.delaySubscription(delayer)
Mockito.`when`(mUserRepository.claim(sUser.mPhone, sUser.mUdid)).thenReturn(singleResponse)
Mockito.`when`(mValidatorUtils.phoneValidator(sUser.mPhone)).thenReturn(true)
Mockito.`when`(mUserRepository.claim(Mockito.anyString(),Mockito.anyString())).thenReturn(singleResponse)
Mockito.`when`(mValidatorUtils.phoneValidator(Mockito.anyString())).thenReturn(true)
mRegistrationViewModel.claim(sUser.mPhone, sUser.mUdid)
Mockito.verify(mUserRepository).claim(sUser.mPhone, sUser.mUdid)
Mockito.verify(mUserRepository).claim(Mockito.anyString(),Mockito.anyString())
Assert.assertEquals(
LiveDataTestUtil.getValue(mRegistrationViewModel.getClaimLiveData()).status,
Status.LOADING
Expand All @@ -113,10 +113,10 @@ class PhoneInputViewModelTest : BaseTest() {
)
)
.delaySubscription(delayer)
Mockito.`when`(mUserRepository.claim(sUser.mPhone, sUser.mUdid)).thenReturn(singleResponse)
Mockito.`when`(mValidatorUtils.phoneValidator(sUser.mPhone)).thenReturn(true)
Mockito.`when`(mUserRepository.claim(Mockito.anyString(),Mockito.anyString())).thenReturn(singleResponse)
Mockito.`when`(mValidatorUtils.phoneValidator(Mockito.anyString())).thenReturn(true)
mRegistrationViewModel.claim(sUser.mPhone, sUser.mUdid)
Mockito.verify(mUserRepository).claim(sUser.mPhone, sUser.mUdid)
Mockito.verify(mUserRepository).claim(Mockito.anyString(),Mockito.anyString())
Assert.assertEquals(
LiveDataTestUtil.getValue(mRegistrationViewModel.getClaimLiveData()).status,
Status.LOADING
Expand All @@ -142,10 +142,10 @@ class PhoneInputViewModelTest : BaseTest() {
)
)
.delaySubscription(delayer)
Mockito.`when`(mUserRepository.claim(sUser.mPhone, sUser.mUdid)).thenReturn(singleResponse)
Mockito.`when`(mValidatorUtils.phoneValidator(sUser.mPhone)).thenReturn(true)
Mockito.`when`(mUserRepository.claim(Mockito.anyString(),Mockito.anyString())).thenReturn(singleResponse)
Mockito.`when`(mValidatorUtils.phoneValidator(Mockito.anyString())).thenReturn(true)
mRegistrationViewModel.claim(sUser.mPhone, sUser.mUdid)
Mockito.verify(mUserRepository).claim(sUser.mPhone, sUser.mUdid)
Mockito.verify(mUserRepository).claim(Mockito.anyString(),Mockito.anyString())
Assert.assertEquals(
LiveDataTestUtil.getValue(mRegistrationViewModel.getClaimLiveData()).status,
Status.LOADING
Expand All @@ -166,10 +166,10 @@ class PhoneInputViewModelTest : BaseTest() {
val singleResponse = Single.error<Response<UserModel>>(Exception())
.delaySubscription(delayer)

Mockito.`when`(mUserRepository.claim(sUser.mPhone, sUser.mUdid)).thenReturn(singleResponse)
Mockito.`when`(mValidatorUtils.phoneValidator(sUser.mPhone)).thenReturn(true)
Mockito.`when`(mUserRepository.claim(Mockito.anyString(),Mockito.anyString())).thenReturn(singleResponse)
Mockito.`when`(mValidatorUtils.phoneValidator(Mockito.anyString())).thenReturn(true)
mRegistrationViewModel.claim(sUser.mPhone, sUser.mUdid)
Mockito.verify(mUserRepository).claim(sUser.mPhone, sUser.mUdid)
Mockito.verify(mUserRepository).claim(Mockito.anyString(),Mockito.anyString())
Assert.assertEquals(
LiveDataTestUtil.getValue(mRegistrationViewModel.getClaimLiveData()).status,
Status.LOADING
Expand All @@ -187,8 +187,8 @@ class PhoneInputViewModelTest : BaseTest() {
@Test
fun phoneValidator_invalidPhoneNumber() {

Mockito.`when`(mValidatorUtils.phoneValidator(wrongUserPhone.mPhone)).thenReturn(false)
mRegistrationViewModel.claim(wrongUserPhone.mPhone, wrongUserPhone.mUdid)
Mockito.`when`(mValidatorUtils.phoneValidator(Mockito.anyString())).thenReturn(false)
mRegistrationViewModel.claim(sWrongUserPhone.mPhone, sWrongUserPhone.mUdid)
Assert.assertEquals(LiveDataTestUtil.getValue(mRegistrationViewModel.getClaimLiveData()).status, Status.FAILED)
Assert.assertEquals(
LiveDataTestUtil.getValue(mRegistrationViewModel.getClaimLiveData()).throwable!!::class.java,
Expand Down

0 comments on commit e26ba7a

Please sign in to comment.