package Ġcom . dims . ly ric ally . view models Ċ Ċ import Ġandroidx . arch . core . executor . testing . Instant Task Executor Rule Ċ import Ġandroidx . lifecycle . Mutable LiveData Ċ import Ġandroidx . lifecycle . Observer Ċ import Ġcom . dims . ly ric ally . models . F avour ites Ċ import Ġcom . dims . ly ric ally . repository . Repository Ċ import Ġcom . dims . ly ric ally . screens . fav our ites . Fav ViewModel Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . check Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . do Answer Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . mock Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . verify Ċ import Ġkotlinx . coroutines . Dispatch ers Ċ import Ġkotlinx . coroutines . Experimental Cor outines Api Ċ import Ġkotlinx . coroutines . run Blocking Ċ import Ġkotlinx . coroutines . test . Test Coroutine Dispatcher Ċ import Ġkotlinx . coroutines . test . reset Main Ċ import Ġkotlinx . coroutines . test . set Main Ċ import Ġorg . junit . After Ċ import Ġorg . junit . Assert . assertEquals Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ Ċ @ Experimental Cor outines Api Ċ class ĠF av ViewModel Test Ġ{ ĊĊĠĠĠ Ġ@ get : Rule ĊĠĠĠ Ġval Ġinstant Execution Rule Ġ= ĠInstant Task Executor Rule () ĊĊĠĠĠ Ġprivate Ġval Ġmain Thread Sur rogate Ġ= ĠTest Coroutine Dispatcher () ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġrepository Ġ: ĠRepository ĊĊĠĠĠ Ġprivate Ġval Ġfav s Ġ= ĠlistOf ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠF avour ites ( 1 , Ġ".. ", Ġ".. ", Ġ".. ", Ġ".. ", Ġ".. ", Ġ".. "), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠF avour ites ( 2 , Ġ".. ", Ġ".. ", Ġ".. ", Ġ".. ", Ġ".. ", Ġ".. ") ĊĠĠĠ Ġ) ĊĠĠĠ Ġprivate Ġval Ġ_ fav LiveData Ġ= ĠMutable LiveData < List < F avour ites >>() ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun ĠsetUp () Ġ{ ĊĠĠĠĠĠĠĠ ĠDispatch ers . set Main ( main Thread Sur rogate ) ĊĠĠĠĠĠĠĠ Ġrepository Ġ= Ġmock { repository Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġon ( repository . fav our ites ). do Answer { ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ_ fav LiveData ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ After ĊĠĠĠ Ġfun ĠtearDown () Ġ{ ĊĠĠĠĠĠĠĠ ĠDispatch ers . reset Main () Ġ// Ġreset Ġmain Ġdispatcher Ġto Ġthe Ġoriginal ĠMain Ġdispatcher ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest _ fav our ites LiveData _ on Changed () Ġ= Ġrun Blocking { ĊĠĠĠĠĠĠĠ Ġval Ġobserver Ġ= Ġmock < Observer < List < F avour ites >> >() ĊĠĠĠĠĠĠĠ Ġval ĠviewModel Ġ= ĠF av ViewModel ( repository ) ĊĠĠĠĠĠĠĠ ĠviewModel . fav our ites . observe Fore ver ( observer ) ĊĠĠĠĠĠĠĠ Ġval Ġexpected Ġ= Ġfav s ĊĊĠĠĠĠĠĠĠ Ġ_ fav LiveData . value Ġ= Ġexpected ĊĊĠĠĠĠĠĠĠ Ġverify ( observer ). on Changed ( check Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( it [ 0 ]. id , Ġexpected [ 0 ]. id ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( it [ 1 ]. id , Ġexpected [ 1 ]. id ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( it . size , Ġexpected . size ) ĊĠĠĠĠĠĠĠ Ġ}) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest _ delete History () Ġ= Ġrun Blocking { ĊĠĠĠĠĠĠĠ Ġval ĠviewModel Ġ= ĠF av ViewModel ( repository ) ĊĠĠĠĠĠĠĠ Ġval Ġexpected Ġ= Ġfav s [ 0 ] ĊĊĠĠĠĠĠĠĠ ĠviewModel . delete ( expected ) ĊĊĠĠĠĠĠĠĠ Ġverify ( repository ). delete From F avour ite ( expected ) ĊĠĠĠ Ġ} Ċ }