/* Ċ Ġ* ĠCopyright Ġ( c ) Ġ 2 0 2 1 Ġmar lon lom . Ċ Ġ* Ċ Ġ* ĠLicensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License "); Ċ Ġ* Ġyou Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ Ġ* ĠYou Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ċ Ġ* Ċ Ġ* ĠĠĠĠĠ Ġhttp :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ġ* Ċ Ġ* ĠUnless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ Ġ* Ġdistributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ Ġ* ĠWITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ Ġ* ĠSee Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ Ġ* Ġlimitations Ġunder Ġthe ĠLicense . Ċ Ġ*/ Ċ Ċ package Ġdev . mar lon lom . apps . book bar . search Ċ Ċ import Ġandroidx . paging . Paging Data Ċ import Ġdev . mar lon lom . apps . book bar . model . network . Book Search ApiResponse . Companion . EMPTY _ RESPONSE Ċ import Ġdev . mar lon lom . apps . book bar . search . Se ar ched Books Contract . Repository Ċ import Ġdev . mar lon lom . apps . book bar . search . Se ar ched Books Contract . ViewModel Ċ import Ġdev . mar lon lom . apps . book bar . utils . Remote Data . sear ched Kotlin Books ApiResponse Ċ import Ġdev . mar lon lom . apps . book bar . utils . Test Coroutine Rule Ċ import Ġjunit . framework . TestCase Ċ import Ġkotlinx . coroutines . Experimental Cor outines Api Ċ import Ġkotlinx . coroutines . Internal Cor outines Api Ċ import Ġkotlinx . coroutines . flow . distinct Until Changed Ċ import Ġkotlinx . coroutines . flow . first Ċ import Ġkotlinx . coroutines . flow . flow Of Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . mockito . Mockito Ċ import Ġorg . mockito . Mockito .` when ` Ċ import Ġorg . mockito . Mockito . mock Ċ import Ġorg . mockito . junit . Mockito JUnit Runner Ċ Ċ @ Internal Cor outines Api Ċ @ Experimental Cor outines Api Ċ @ RunWith ( Mockito JUnit Runner :: class ) Ċ class ĠViewModel Test Ġ: ĠTestCase () Ġ{ ĊĊĠĠĠ Ġ@ get : Rule ĊĠĠĠ Ġval Ġtest Coroutine Rule Ġ= ĠTest Coroutine Rule () ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar ĠviewModel : ĠViewModel ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġrepository : ĠRepository ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġpublic Ġoverride Ġfun ĠsetUp () Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . setUp () ĊĠĠĠĠĠĠĠ Ġrepository Ġ= Ġmock ( Repository :: class . java ) ĊĠĠĠĠĠĠĠ ĠviewModel Ġ= ĠViewModel ( repository ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` Should Ġnot Ġreturn Ġsearch Ġresults Ġusing Ġtext Ġat Ġpage Ġ 1 `() Ġ= ĊĠĠĠĠĠĠĠ Ġtest Coroutine Rule . run Blocking Test Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ` when `( repository . search Books ( Mockito . any String ())) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. thenReturn ( flow Of ( Paging Data . from ( EMPTY _ RESPONSE . books !! ))) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= ĠviewModel . search Books (" kotlin "). distinct Until Changed (). first () ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertNotNull ( response ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` Should Ġreturn Ġsearch Ġresult Ġerror Ġusing Ġtext Ġat Ġpage Ġ 1 `() Ġ= ĊĠĠĠĠĠĠĠ Ġtest Coroutine Rule . run Blocking Test Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ` when `( repository . search Books ( Mockito . any String ())) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. thenReturn ( flow Of ( Paging Data . empty ())) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= ĠviewModel . search Books (" anything "). distinct Until Changed (). first () ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertNotNull ( response ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` Should Ġreturn Ġsearch Ġresults Ġusing Ġtext Ġat Ġpage Ġ 1 `() Ġ= ĊĠĠĠĠĠĠĠ Ġtest Coroutine Rule . run Blocking Test Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ` when `( repository . search Books ( Mockito . any String ())). thenReturn ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġflow Of ( Paging Data . from ( sear ched Kotlin Books ApiResponse . books !! )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= ĠviewModel . search Books (" kotlin "). distinct Until Changed (). first () ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertNotNull ( response ) ĊĠĠĠĠĠĠĠ Ġ} Ċ Ċ } Ċ