package Ġy ode put . android . sample . app . feature Ċ Ċ import Ġandroid . content . Context Ċ import Ġandroidx . arch . core . executor . testing . Instant Task Executor Rule Ċ import Ġandroidx . compose . runtime . collect As State Ċ import Ġcom . sky do ves . sand wich . ApiResponse Ċ import Ġkotlinx . coroutines . Dispatch ers Ċ import Ġkotlinx . coroutines . Experimental Cor outines Api Ċ import Ġorg . hamcrest . Core Matchers .` is ` Ċ import Ġorg . hamcrest . Matcher Assert . assertThat Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . rules . Test Rule Ċ import Ġorg . mockito . Argument Matchers . any Int Ċ import Ġorg . mockito . Mock Ċ import Ġorg . mockito . Mockito .* Ċ import Ġorg . mockito . Mockito Annotations Ċ import Ġy ode put . mobile . bank ing . common . util . ViewState Ċ import Ġy ode put . mobile . bank ing . core . dao . Pay ee Dao Ċ import Ġy ode put . mobile . bank ing . core . dao . Transaction Dao Ċ import Ġy ode put . mobile . bank ing . core . dao . User Dao Ċ import Ġy ode put . mobile . bank ing . core . database . Preference Storage Ċ import Ġy ode put . mobile . bank ing . core . network . Auth Service Ċ import Ġy ode put . mobile . bank ing . core . repository . UserRepository Ċ import Ġy ode put . mobile . bank ing . core . request . Login Request Ċ import Ġy ode put . mobile . bank ing . core . response . Login Response Ċ import Ġy ode put . mobile . bank ing . feature . ui . auth . Auth ViewModel Ċ Ċ @ Experimental Cor outines Api Ċ class ĠAuth ViewModel Test Ġ{ ĊĊĠĠĠ Ġ@ get : Rule ĊĠĠĠ Ġval Ġrule : ĠTest Rule Ġ= ĠInstant Task Executor Rule () ĊĊĠĠĠ Ġ@ get : Rule ĊĠĠĠ Ġval Ġtest Coroutine Rule Ġ= ĠTest Coroutine Rule () ĊĊĠĠĠ Ġ@ Mock ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġapi : ĠAuth Service ĊĊĠĠĠ Ġ@ Mock ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġuser Dao : ĠUser Dao ĊĊĠĠĠ Ġ@ Mock ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġtransaction Dao : ĠTransaction Dao ĊĊĠĠĠ Ġ@ Mock ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġpay ee Dao : ĠPay ee Dao ĊĊĠĠĠ Ġ@ Mock ĊĠĠĠ Ġprivate Ġlateinit Ġvar ĠviewModel : ĠAuth ViewModel ĊĊĠĠĠ Ġ@ Mock ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġcontext : ĠContext ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun ĠsetUp () Ġ{ ĊĠĠĠĠĠĠĠ ĠMockito Annotations . init Mocks ( this ) ĊĠĠĠĠĠĠĠ Ġval Ġpref Ġ= ĠPreference Storage . getInstance ( context ) ĊĠĠĠĠĠĠĠ Ġval Ġrepository Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠ ĠUser Repository ( pref , Ġuser Dao , Ġtransaction Dao , Ġpay ee Dao , Ġapi , ĠDispatch ers . Main ) ĊĠĠĠĠĠĠĠ ĠviewModel Ġ= ĠAuth ViewModel ( repository ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġlogin _ should Return Success () Ġ{ ĊĠĠĠĠĠĠĠ Ġtest Coroutine Rule . run Blocking Test Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdo Return ( ApiResponse ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. ` when `( viewModel ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. perform Login (" test ", Ġ" as das d ") ĊĠĠĠĠĠĠĠ Ġ} ĊĊĊĠĠĠĠĠĠĠ Ġtest Coroutine Rule . pause Dispatcher () ĊĠĠĠĠĠĠĠ ĠassertThat ( viewModel . login State . value , Ġ` is `( ViewState . Loading )) ĊĊĠĠĠĠĠĠĠ Ġtest Coroutine Rule . resume Dispatcher () ĊĠĠĠĠĠĠĠ ĠassertThat ( viewModel . login State . value , Ġ` is `( ViewState . Success ( Login Response ()))) ĊĠĠĠ Ġ} Ċ } Ċ