package Ġcom . example Ċ Ċ /* import Ġcom . co zo . co z om vp . authentication . Auth Activity Ċ import Ġcom . google . firebase . auth . Phone Auth Credential Ċ import Ġorg . junit . Test Ċ import Ġorg . mockito . Mock Ċ import Ġcom . google . firebase . auth . Phone Auth Provider Ċ import Ġorg . junit . Before Ċ import Ġorg . mockito . Matchers Ċ import Ġorg . mockito . Matchers . any Ċ import Ġorg . mockito . Mockito . do Answer Ċ import Ġorg . mockito . Mockito Annotations Ċ import Ġjava . util . concurrent . TimeUnit Ċ import Ġcom . co zo . co z om vp . authentication . Auth Interfaces Ċ import Ġcom . co zo . co z om vp . authentication . Auth Model Ċ import Ġcom . co zo . co z om vp . authentication . validation service . Phone Validation ServiceImpl Ċ import Ġcom . google . android . gms . tasks . On Complete Listener Ċ import Ġcom . google . android . gms . tasks . Task Ċ import Ġcom . google . firebase . auth . Auth Result Ċ import Ġcom . google . firebase . auth . Firebase Auth Ċ import Ġcom . google . i 1 8 n . phon en umbers . PhoneNumber Util Ċ import Ġcom . google . i 1 8 n . phon en umbers . Ph on enumber Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . mockito . Matchers . any String Ċ import Ġorg . mockito . Mockito .` when ` Ċ import Ġorg . ro bo lectric . Ro bo lectric TestRunner Ċ Ċ @ RunWith ( Ro bo lectric TestRunner :: class ) Ċ class ĠAuth Model UnitTest { ĊĊĠĠĠ Ġ/* ĊĠĠĠ ĠIn Ġcase Ġtest Ġfails Ġwith Ġexception ĠNo Class Def Found Error Ġ, Ġdelete Ġ. gradle Ġand Ġ. idle Ġfolders Ġand ĊĠĠĠ Ġrebuild Ġproject . ĊĠĠĠ ĠCheck : Ġhttps :// stackoverflow . com / questions / 4 2 8 0 5 4 9 5 / android - junit - dont - compile - if - objects - are - parcel able ĊĠĠĠĠ Ġ*/ ĊĠĠĠ Ġ@ Mock Ġlateinit Ġvar Ġmocked Phone Auth Provider Ġ: ĠPhone Auth Provider ĊĠĠĠ Ġ@ Mock Ġlateinit Ġvar Ġmocked Firebase Auth Ġ: ĠFirebase Auth ĊĠĠĠ Ġ@ Mock Ġlateinit Ġvar Ġmocked PhoneNumber Util : ĠPhone Number Util ĊĠĠĠ Ġ@ Mock Ġlateinit Ġvar Ġmocked Credential : ĠPhone Auth Credential ĊĠĠĠ Ġ@ Mock Ġlateinit Ġvar Ġmocked Task Ġ: ĠTask < Auth Result > ĊĠĠĠ Ġprivate Ġvar Ġtest PhoneNumber Ġ: ĠString Ġ= Ġ" 1 1 9 4 5 9 0 8 2 7 9 " ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun Ġsetup (){ ĊĠĠĠĠĠĠĠ ĠMockito Annotations . init Mocks ( this ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġauth Model _ authenticate Number _ on Auth And Linked Completed (){ ĊĊĠĠĠĠĠĠĠ Ġ// ĠMock Ġmethods Ġparse Ġand ĠisValid Number Ġfrom ĠPhone Number Util ĊĠĠĠĠĠĠĠ Ġval Ġfake Br Phone Ġ= ĠPh on enumber . PhoneNumber () ĊĠĠĠĠĠĠĠ Ġ` when `( mocked PhoneNumber Util . parse ( any String (), Ġany String ())). thenReturn ( fake Br Phone ) ĊĠĠĠĠĠĠĠ Ġ` when `( mocked PhoneNumber Util . isValid Number ( any ( Ph on enumber . PhoneNumber :: class . java ))). thenReturn ( true ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠStub ĠOn Verification StateChanged Callbacks ĊĠĠĠĠĠĠĠ Ġdo Answer Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġcallback Ġ= Ġit . arguments [ 4 ] Ġas ĠPhone Auth Provider . On Verification StateChanged Callbacks ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġ// Ġtriggers Ġon Verification Completed Ġwith Ġfake Ġresult Ġobject Ġof Ġtype ĠPhone Auth Credential ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcallback . on Verification Completed ( mocked Credential ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn @ do Answer Ġnull ĊĠĠĠĠĠĠĠ Ġ}. ` when `( mocked Phone Auth Provider ). verify PhoneNumber ( Matchers . any String (), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠMatch ers . any Long (), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġany ( TimeUnit :: class . java ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġany ( Auth Activity :: class . java ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġany ( Phone Auth Provider . On Verification StateChanged Callbacks :: class . java )) ĊĊĠĠĠĠĠĠĠ Ġ// ĠMock Ġmethod Ġsign In With Credential Ġfrom ĠFirebase Auth ĊĠĠĠĠĠĠĠ Ġ` when `( mocked Firebase Auth . signIn With Credential ( any ( Phone Auth Credential :: class . java ))). thenReturn ( mocked Task ) ĊĊĠĠĠĠĠĠĠ Ġ// ĊĠĠĠĠĠĠĠ Ġdo Answer Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġcallback Ġ= Ġit . arguments [ 1 ] Ġas ĠOn Complete Listener < Auth Result > ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġcallback . onComplete ( mocked Task ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn @ do Answer Ġnull ĊĠĠĠĠĠĠĠ Ġ}. ` when `( mocked Task ). add On Complete Listener ( any ( Auth Activity :: class . java ), Ġany ()) ĊĊĠĠĠĠĠĠĠ Ġ// ĠInstantiate Ġvalidation Service Ġas ĠPhone Validation ServiceImpl ĊĠĠĠĠĠĠĠ Ġval Ġvalidation Service Ġ= ĠPhone Validation ServiceImpl ( mocked PhoneNumber Util , Ġmocked Phone Auth Provider , Ġmocked Firebase Auth ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠInstantiate Ġauth Listener ĊĠĠĠĠĠĠĠ Ġval Ġauth Listener Ġ= ĠAuth Listener () ĊĊĠĠĠĠĠĠĠ Ġval Ġauth Model Ġ= ĠAuth Model ( validation Service , Ġauth Listener ) ĊĠĠĠĠĠĠĠ Ġauth Model . authenticate Number ( test PhoneNumber ) ĊĊĠĠĠĠĠĠĠ Ġ// read Ġfor ĠMonday Ġhttps :// www . ba eld ung . com / mockito - spy ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġclass ĠAuth Listener Ġ: ĠAuth Interfaces . Presenter . On Request Auth Listener { ĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġon Auth And Linked Completed () Ġ{} ĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġon Request Link With Google Needed () Ġ{} ĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġon Authentication Failed () Ġ{} ĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġon Invalid Number () Ġ{} ĊĠĠĠ Ġ} Ċ } ĊĠĠĠĠĠĠĠ Ġ*/