package Ġcom . v ish al ga ur . shopping app . view Models Ċ Ċ import Ġandroidx . arch . core . executor . testing . Instant Task Executor Rule Ċ import Ġandroidx . test . core . app . Application Provider Ċ import Ġandroidx . test . espress o . matcher . View Matchers . assertThat Ċ import Ġandroidx . test . ext . junit . runners . Android JUnit 4 Ċ import Ġcom . v ish al ga ur . shopping app . Service Locator Ċ import Ġcom . v ish al ga ur . shopping app . data . Shopping App Session Manager Ċ import Ġcom . v ish al ga ur . shopping app . data . UserData Ċ import Ġcom . v ish al ga ur . shopping app . data . source . Fake Auth Repository Ċ import Ġcom . v ish al ga ur . shopping app . data . source . Fake Products Repository Ċ import Ġcom . v ish al ga ur . shopping app . data . source . repository . Auth Repo Interface Ċ import Ġcom . v ish al ga ur . shopping app . data . source . repository . Products Repo Interface Ċ import Ġcom . v ish al ga ur . shopping app . get Or Await Value Ċ import Ġkotlinx . coroutines . Experimental Cor outines Api Ċ import Ġkotlinx . coroutines . delay Ċ import Ġkotlinx . coroutines . run Blocking Ċ import Ġkotlinx . coroutines . test . run Blocking Test Ċ import Ġorg . hamcrest . Matchers .` is ` Ċ import Ġorg . hamcrest . Matchers . not Ċ import Ġorg . junit . After Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ Ċ @ RunWith ( Android JUnit 4 :: class ) Ċ @ Experimental Cor outines Api Ċ class ĠProduct ViewModel Test Ġ{ Ċ ĉ private Ġlateinit Ġvar Ġproduct ViewModel : ĠProduct ViewModel Ċ ĉ private Ġlateinit Ġvar ĠproductId : ĠString Ċ ĉ private Ġlateinit Ġvar Ġproducts Repository : ĠProducts Repo Interface Ċ ĉ private Ġlateinit Ġvar Ġauth Repository : ĠAuth Repo Interface ĊĊ ĉ val Ġuser Ġ= ĠUser Data ( Ċĉ ĉ " sd jm 4 3 8 9 2 y fh 9 4 8 eh od ", Ċĉ ĉ " V ish al ", Ċĉ ĉ "+ 9 1 9 9 9 9 9 8 8 8 8 8 ", Ċĉ ĉ " v ish al @ so mem ail . com ", Ċĉ ĉ " dh 9 4 3 2 8 hd ", Ċĉ ĉ ArrayList (), Ċĉ ĉ ArrayList (), Ċĉ ĉ ArrayList () Ċ ĉ ) ĊĊ ĉ @ get : Rule Ċ ĉ var Ġinstant Task Executor Rule Ġ= ĠInstant Task Executor Rule () ĊĊ ĉ @ Before Ċ ĉ fun ĠsetUp () Ġ{ Ċĉ ĉ products Repository Ġ= ĠFake Products Repository () Ċĉ ĉ val Ġsession Manager Ġ= ĠShop ping App Session Manager ( Application Provider . getApplicationContext ()) Ċĉ ĉ auth Repository Ġ= ĠFake Auth Repository ( session Manager ) Ċĉ ĉ auth Repository . login ( user , Ġtrue ) Ċĉ ĉ Service Locator . products Repository Ġ= Ġproducts Repository Ċĉ ĉ Service Locator . auth Repository Ġ= Ġauth Repository Ċĉ ĉ productId Ġ= Ġ" pro - sh oes - w of w op jf - 1 " Ċĉ ĉ product ViewModel Ġ= ĠProduct ViewModel ( productId , ĠApplication Provider . getApplicationContext ()) Ċ ĉ } ĊĊ ĉ @ After Ċ ĉ fun Ġclean Up () Ġ= Ġrun Blocking Test Ġ{ Ċĉ ĉ Service Locator . reset Repository () Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtoggle Like Product _ false _ true () Ġ{ Ċĉ ĉ val Ġresult 1 Ġ= Ġproduct ViewModel . is Lik ed . value Ċĉ ĉ run Blocking Ġ{ Ċĉĉ ĉ product ViewModel . toggle Like Product () Ċĉĉ ĉ delay ( 1 0 0 0 ) Ċĉĉ ĉ val Ġresult 2 Ġ= Ġproduct ViewModel . is Lik ed . get Or Await Value () Ċĉĉ ĉ assertThat ( result 1 , Ġnot ( result 2 )) Ċĉ ĉ } ĊĊ ĉ } Ċ }