package Ġcom . h af iz code . movies and tv . ui . home . content . helper Ċ Ċ import Ġandroidx . arch . core . executor . testing . Instant Task Executor Rule Ċ import Ġandroidx . lifecycle . Mutable LiveData Ċ import Ġandroidx . lifecycle . Observer Ċ import Ġandroidx . paging . Paged List Ċ import Ġcom . h af iz code . movies and tv . data . entity . Movie Entity Ċ import Ġcom . h af iz code . movies and tv . data . entity . TV Entity Ċ import Ġcom . h af iz code . movies and tv . data . source . Movie Repository Ċ import Ġcom . h af iz code . movies and tv . vo . Resource Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . verify Ċ import Ġorg . junit . Assert . assertEquals Ċ import Ġorg . junit . Assert . assertNotNull Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . mockito . Mock Ċ import Ġorg . mockito . Mockito .` when ` Ċ import Ġorg . mockito . junit . Mockito JUnit Runner Ċ Ċ @ RunWith ( Mockito JUnit Runner :: class ) Ċ class ĠData ViewModel Test Ġ{ ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar ĠviewModel : ĠData ViewModel ĊĊĠĠĠ Ġ@ get : Rule ĊĠĠĠ Ġvar Ġinstant Task Executor Rule Ġ= ĠInstant Task Executor Rule () ĊĊĠĠĠ Ġ@ Mock ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġmovie Repository : ĠMovie Repository ĊĊĠĠĠ Ġ@ Mock ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġmovie Observer : ĠObserver < Resource < Paged List < Movie Entity >>> ĊĊĠĠĠ Ġ@ Mock ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġtv Observer : ĠObserver < Resource < Paged List < TV Entity >>> ĊĊĠĠĠ Ġ@ Mock ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġbookmark Movie Observer : ĠObserver < Paged List < Movie Entity >> ĊĊĠĠĠ Ġ@ Mock ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġbookmark TV Observer : ĠObserver < Paged List < TV Entity >> ĊĊĠĠĠ Ġ@ Mock ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġmovie Paged List : ĠP aged List < Movie Entity > ĊĊĠĠĠ Ġ@ Mock ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġtv Paged List : ĠP aged List < TV Entity > ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun ĠsetUp () Ġ{ ĊĠĠĠĠĠĠĠ ĠviewModel Ġ= ĠData ViewModel ( movie Repository ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġget Movies () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġdummy Movies Ġ= ĠResource . success ( movie Paged List ) ĊĠĠĠĠĠĠĠ Ġ` when `( dummy Movies . data ?. size ). thenReturn ( 3 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġmovies Ġ= ĠMutable LiveData < Resource < Paged List < Movie Entity >> >() ĊĠĠĠĠĠĠĠ Ġmovies . value Ġ= Ġdummy Movies ĊĊĠĠĠĠĠĠĠ Ġ` when `( movie Repository . get Movies ()). thenReturn ( movies ) ĊĊĠĠĠĠĠĠĠ Ġval Ġmovie Ġ= ĠviewModel . get Movies (). value ?. data ĊĠĠĠĠĠĠĠ Ġverify ( movie Repository ). get Movies () ĊĠĠĠĠĠĠĠ ĠassertNotNull ( movie ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( 3 , Ġmovie ?. size ) ĊĊĠĠĠĠĠĠĠ ĠviewModel . get Movies (). observe Fore ver ( movie Observer ) ĊĠĠĠĠĠĠĠ Ġverify ( movie Observer ). on Changed ( dummy Movies ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġget Book marked Movies () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġdummy Movie Ġ= Ġmovie Paged List ĊĠĠĠĠĠĠĠ Ġ` when `( dummy Movie . size ). thenReturn ( 3 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġmovies Ġ= ĠMutable LiveData < Paged List < Movie Entity >>() ĊĠĠĠĠĠĠĠ Ġmovies . value Ġ= Ġdummy Movie ĊĊĠĠĠĠĠĠĠ Ġ` when `( movie Repository . get Book marked Movies ()). thenReturn ( movies ) ĊĠĠĠĠĠĠĠ Ġval Ġmovie Ġ= ĠviewModel . get Book marked Movies (). value ĊĠĠĠĠĠĠĠ Ġverify ( movie Repository ). get Book marked Movies () ĊĠĠĠĠĠĠĠ ĠassertNotNull ( movie ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( 3 , Ġmovie ?. size ) ĊĊĠĠĠĠĠĠĠ ĠviewModel . get Book marked Movies (). observe Fore ver ( bookmark Movie Observer ) ĊĠĠĠĠĠĠĠ Ġverify ( bookmark Movie Observer ). on Changed ( dummy Movie ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġget T Vs () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġdummy T Vs Ġ= ĠResource . success ( tv Paged List ) ĊĠĠĠĠĠĠĠ Ġ` when `( dummy T Vs . data ?. size ). thenReturn ( 3 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġt vs Ġ= ĠMutable LiveData < Resource < Paged List < TV Entity >> >() ĊĠĠĠĠĠĠĠ Ġt vs . value Ġ= Ġdummy T Vs ĊĊĠĠĠĠĠĠĠ Ġ` when `( movie Repository . getT Vs ()). thenReturn ( t vs ) ĊĊĠĠĠĠĠĠĠ Ġval Ġtv Ġ= ĠviewModel . getT vs (). value ?. data ĊĠĠĠĠĠĠĠ Ġverify ( movie Repository ). getT Vs () ĊĠĠĠĠĠĠĠ ĠassertNotNull ( tv ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( 3 , Ġtv ?. size ) ĊĊĠĠĠĠĠĠĠ ĠviewModel . getT vs (). observe Fore ver ( tv Observer ) ĊĠĠĠĠĠĠĠ Ġverify ( tv Observer ). on Changed ( dummy T Vs ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġget Book marked T vs () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġdummy TV Ġ= Ġtv Paged List ĊĠĠĠĠĠĠĠ Ġ` when `( dummy TV . size ). thenReturn ( 3 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġt vs Ġ= ĠMutable LiveData < Paged List < TV Entity >>() ĊĠĠĠĠĠĠĠ Ġt vs . value Ġ= Ġdummy TV ĊĊĠĠĠĠĠĠĠ Ġ` when `( movie Repository . get Book marked T Vs ()). thenReturn ( t vs ) ĊĠĠĠĠĠĠĠ Ġval Ġtv Ġ= ĠviewModel . get Book marked T Vs (). value ĊĠĠĠĠĠĠĠ Ġverify ( movie Repository ). get Book marked T Vs () ĊĠĠĠĠĠĠĠ ĠassertNotNull ( tv ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( 3 , Ġtv ?. size ) ĊĊĠĠĠĠĠĠĠ ĠviewModel . get Book marked T Vs (). observe Fore ver ( bookmark TV Observer ) ĊĠĠĠĠĠĠĠ Ġverify ( bookmark TV Observer ). on Changed ( dummy TV ) ĊĠĠĠ Ġ} Ċ }