package Ġes . np atar ino . android . got challenge . house s . presentation Ċ Ċ import Ġandroidx . arch . core . executor . testing . Instant Task Executor Rule Ċ import Ġcom . n ha ar man . mockito _ kotlin .* Ċ import Ġes . np atar ino . android . got challenge . house s . domain . factory . Go TH ouse s Data Factory Ċ import Ġes . np atar ino . android . got challenge . house s . domain . model . Go TH ouse Ċ import Ġes . np atar ino . android . got challenge . house s . domain . use case . Go TH ouse s UseCase Ċ import Ġes . np atar ino . android . got challenge . house s . presentation . model . Go TH ouse List Ui State Ċ import Ġes . np atar ino . android . got challenge . house s . presentation . view model . Go TH ouse s ViewModel Ċ import Ġio . reactivex . ob servers . Disposable Single Observer Ċ import Ġorg . junit . Assert Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ Ċ class ĠGo TH ouse s ViewModel Test Ġ{ ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar ĠviewModel : ĠGo TH ouse s ViewModel ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġhouse s UseCase : ĠGo TH ouse s UseCase ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġget House s Executor Captor : ĊĠĠĠĠĠĠĠĠĠĠĠ ĠK Argument Captor < Disposable Single Observer < List < Go TH ouse >>> ĊĊĠĠĠ Ġ@ get : Rule ĊĠĠĠ Ġval Ġrule Ġ= ĠInstant Task Executor Rule () ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun Ġbefore () Ġ{ ĊĠĠĠĠĠĠĠ Ġhouse s UseCase Ġ= Ġmock () ĊĠĠĠĠĠĠĠ ĠviewModel Ġ= ĠGo TH ouse s ViewModel ( house s UseCase ) ĊĠĠĠĠĠĠĠ Ġget House s Executor Captor Ġ= Ġargument Captor () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġcall ViewModel Should Execute UseCase () Ġ{ ĊĠĠĠĠĠĠĠ ĠviewModel . get House s () ĊĠĠĠĠĠĠĠ Ġverify ( house s UseCase ). execute ( get House s Executor Captor . capture (), Ġeq ( null )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġcall ViewModel On Start Should Show Loading State () Ġ{ ĊĠĠĠĠĠĠĠ ĠviewModel . get House s () ĊĠĠĠĠĠĠĠ Ġverify ( house s UseCase ). execute ( get House s Executor Captor . capture (), Ġeq ( null )) ĊĠĠĠĠĠĠĠ Ġget House s Executor Captor . first Value . on Subscribe ( get House s Executor Captor . first Value ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( Go TH ouse List Ui State . Loading , ĠviewModel . house List Ui State . value ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġcall ViewModel Should Load s Data () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= ĠlistOf ( Go TH ouse s Data Factory . make Go TH ouse ()) ĊĠĠĠĠĠĠĠ ĠviewModel . get House s () ĊĊĠĠĠĠĠĠĠ Ġverify ( house s UseCase ). execute ( get House s Executor Captor . capture (), Ġeq ( null )) ĊĠĠĠĠĠĠĠ Ġget House s Executor Captor . first Value . on Success ( result ) ĊĊĠĠĠĠĠĠĠ Ġassert ( viewModel . house List Ui State . value Ġis ĠGo TH ouse List Ui State . Data ) ĊĠĠĠĠĠĠĠ Ġassert (( viewModel . house List Ui State . value Ġas ĠGo TH ouse List Ui State . Data ). house s Ġ== ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġresult ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġcall ViewModel Should Show Error OnError State () Ġ{ ĊĠĠĠĠĠĠĠ ĠviewModel . get House s () ĊĠĠĠĠĠĠĠ Ġverify ( house s UseCase ). execute ( get House s Executor Captor . capture (), Ġeq ( null )) ĊĠĠĠĠĠĠĠ Ġget House s Executor Captor . first Value . onError ( Exception ()) ĊĊĠĠĠĠĠĠĠ Ġassert ( viewModel . house List Ui State . value Ġis ĠGo TH ouse List Ui State . Error ) ĊĠĠĠ Ġ} Ċ }