package Ġcom . to sh . rick and mort y Ċ Ċ import Ġandroidx . arch . core . executor . testing . Instant Task Executor Rule Ċ import Ġcom . to sh . rick and mort y . model . Char Result Ċ import Ġcom . to sh . rick and mort y . model . Character Model Ċ import Ġcom . to sh . rick and mort y . model . Characters Service Ċ import Ġcom . to sh . rick and mort y . view model . Character ViewModel Ċ import Ġio . reactivex . Scheduler Ċ import Ġio . reactivex . Single Ċ import Ġio . reactivex . android . plugins . Rx Android Plugins Ċ import Ġio . reactivex . dis pos ables . Disposable Ċ import Ġio . reactivex . internal . schedul ers . Executor Scheduler Ċ import Ġio . reactivex . plugins . Rx Java Plugins Ċ import Ġjunit . framework . Assert . assertEquals Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġorg . mockito . Inject Mocks Ċ import Ġorg . mockito . Mock Ċ import Ġorg . mockito . Mockito Ċ import Ġorg . mockito . Mockito Annotations Ċ import Ġjava . util . concurrent . Executor Ċ import Ġjava . util . concurrent . TimeUnit Ċ Ċ class ĠCharacter ViewModel Test Ġ{ ĊĊĠĠĠ Ġ@ get : Rule ĊĠĠĠ Ġvar Ġrule Ġ= ĠInstant Task Executor Rule () ĊĊĠĠĠ Ġ@ Mock ĊĠĠĠ Ġlateinit Ġvar Ġcharacters Service : ĠChar acters Service ĊĊĠĠĠ Ġ@ Inject Mocks ĊĠĠĠ Ġvar Ġcharacter ViewModel Ġ= ĠCharacter ViewModel () ĊĊĠĠĠ Ġprivate Ġvar Ġtest Single : ĠSingle < Character Model >? Ġ= Ġnull ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun Ġsetup (){ ĊĠĠĠĠĠĠĠ ĠMockito Annotations . init Mocks ( this ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun Ġsetup Rx chedulers (){ ĊĠĠĠĠĠĠĠ Ġval Ġimmediate Ġ= Ġobject Ġ: ĠScheduler (){ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġfun Ġschedule Direct ( run : ĠRunnable ?, Ġdelay : ĠLong , Ġunit : ĠTimeUnit ?): ĠDis posable Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġreturn Ġsuper . schedule Direct ( run , Ġ 0 , Ġunit ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġfun Ġcreate Worker (): ĠWorker Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġreturn ĠExecutor Scheduler . Executor Worker ( Executor Ġ{ Ġit . run () Ġ}) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ ĠRx Java Plugins . set Init Io Scheduler Handler Ġ{ Ġimmediate Ġ} ĊĠĠĠĠĠĠĠ ĠRx Java Plugins . set Init Computation Scheduler Handler Ġ{ Ġimmediate Ġ} ĊĠĠĠĠĠĠĠ ĠRx Java Plugins . set Init New Thread Scheduler Handler Ġ{ Ġimmediate Ġ} ĊĠĠĠĠĠĠĠ ĠRx Java Plugins . set Init Single Scheduler Handler Ġ{ Ġimmediate Ġ} ĊĠĠĠĠĠĠĠ ĠRx Android Plugins . set Init MainThread Scheduler Handler Ġ{ Ġimmediate Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġget Characters Is Successful (){ ĊĠĠĠĠĠĠĠ Ġval Ġcharacter Ġ= ĠCharacter Model ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠlistOf ( Char Result (" Male ", 1 , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" https :// rick and mort y api . com / api / character / avatar / 1 . jpeg ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" R ick ĠSan che z "," Human "," Alive " Ġ))) ĊĊĊĠĠĠĠĠĠĠ Ġtest Single Ġ= ĠSingle . just ( character ) ĊĊĠĠĠĠĠĠĠ ĠMockito .` when `( characters Service . get Characters ()). thenReturn ( test Single ) ĊĊĠĠĠĠĠĠĠ Ġcharacter ViewModel . refresh () ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( 1 , Ġcharacter ViewModel . characters . value !!. size ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( false , Ġcharacter ViewModel . characters Load Error . value ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( false , Ġcharacter ViewModel . loading . value ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġget Characters Fails (){ ĊĠĠĠĠĠĠĠ Ġtest Single Ġ= ĠSingle . error ( Throwable ()) ĊĊĠĠĠĠĠĠĠ ĠMockito .` when `( characters Service . get Characters ()). thenReturn ( test Single ) ĊĊĠĠĠĠĠĠĠ Ġcharacter ViewModel . refresh () ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( true , Ġcharacter ViewModel . characters Load Error . value ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( false , Ġcharacter ViewModel . loading . value ) ĊĊĠĠĠ Ġ} Ċ Ċ }