package Ġcom . book stores imple . app . presentation . view model Ċ Ċ import Ġandroidx . arch . core . executor . testing . Instant Task Executor Rule Ċ import Ġcom . book stores imple . app . TestData Factory Ċ import Ġcom . book stores imple . app . domain . model . Book Ċ import Ġcom . book stores imple . app . presentation . data . Resource State Ċ import Ġcom . book stores imple . app . use case . Get Book List UseCase Ċ import Ġcom . n ha ar man . mockito _ kotlin . K Argument Captor Ċ import Ġcom . n ha ar man . mockito _ kotlin . any Ċ import Ġcom . n ha ar man . mockito _ kotlin . any OrNull Ċ import Ġcom . n ha ar man . mockito _ kotlin . argument Captor Ċ import Ġcom . n ha ar man . mockito _ kotlin . eq Ċ import Ġcom . n ha ar man . mockito _ kotlin . mock Ċ import Ġcom . n ha ar man . mockito _ kotlin . times Ċ import Ġcom . n ha ar man . mockito _ kotlin . verify Ċ import Ġio . reactivex . subscribers . Disposable Subscriber Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . junit . runners . JUnit 4 Ċ import Ġorg . mockito . Captor Ċ Ċ @ RunWith ( JUnit 4 :: class ) Ċ class ĠBook ViewModel Test Ġ{ ĊĊĠĠĠ Ġ@ Captor ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġcapt or : ĠK Argument Captor < Disposable Subscriber < List < Book >>> ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġmock UseCase : ĠGet Book List UseCase ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar ĠviewModel : ĠBook ViewModel ĊĊĠĠĠ Ġ@ Rule ĊĠĠĠ Ġ@ Jvm Field ĊĠĠĠ Ġvar Ġinstant Task Executor Rule Ġ= ĠInstant Task Executor Rule () ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun ĠsetUp () Ġ{ ĊĊĠĠĠĠĠĠĠ Ġcapt or Ġ= Ġargument Captor () ĊĠĠĠĠĠĠĠ Ġmock UseCase Ġ= Ġmock () ĊĠĠĠĠĠĠĠ ĠviewModel Ġ= ĠBook ViewModel ( mock UseCase ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġfetch Book List _ with UseCase () Ġ{ ĊĊĠĠĠĠĠĠĠ ĠviewModel . fetch Book List () ĊĠĠĠĠĠĠĠ Ġverify ( mock UseCase , Ġtimes ( 1 )). execute ( any (), Ġany OrNull ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġfetch Book List _ with Call () Ġ{ ĊĊĠĠĠĠĠĠĠ Ġval Ġmock Book List Ġ= ĠTest Data Factory . make Book List () ĊĊĠĠĠĠĠĠĠ ĠviewModel . fetch Book List () ĊĊĠĠĠĠĠĠĠ Ġverify ( mock UseCase ). execute ( capt or . capture (), Ġeq ( null )) ĊĠĠĠĠĠĠĠ Ġcapt or . first Value . onNext ( mock Book List ) ĊĊĠĠĠĠĠĠĠ Ġassert ( viewModel . book List . value ?. status Ġ== ĠResource State . SUCCESS ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġfetch Book List _ with Result Data On Success () Ġ{ ĊĊĠĠĠĠĠĠĠ Ġval Ġmock Book List Ġ= ĠTest Data Factory . make Book List () ĊĊĠĠĠĠĠĠĠ ĠviewModel . fetch Book List () ĊĊĠĠĠĠĠĠĠ Ġverify ( mock UseCase ). execute ( capt or . capture (), Ġeq ( null )) ĊĠĠĠĠĠĠĠ Ġcapt or . first Value . onNext ( mock Book List ) ĊĊĠĠĠĠĠĠĠ Ġassert ( viewModel . book List . value ?. data Ġ== Ġmock Book List ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġfetch Book List _ with NoError On Success () Ġ{ ĊĊĠĠĠĠĠĠĠ Ġval Ġmock Book List Ġ= ĠTest Data Factory . make Book List () ĊĊĠĠĠĠĠĠĠ ĠviewModel . fetch Book List () ĊĊĠĠĠĠĠĠĠ Ġverify ( mock UseCase ). execute ( capt or . capture (), Ġeq ( null )) ĊĠĠĠĠĠĠĠ Ġcapt or . first Value . onNext ( mock Book List ) ĊĊĠĠĠĠĠĠĠ Ġassert ( viewModel . book List . value ?. throwable Ġ== Ġnull ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġfetch Book List _ with Result Error On Failure () Ġ{ ĊĊĠĠĠĠĠĠĠ ĠviewModel . fetch Book List () ĊĊĠĠĠĠĠĠĠ Ġverify ( mock UseCase ). execute ( capt or . capture (), Ġeq ( null )) ĊĠĠĠĠĠĠĠ Ġcapt or . first Value . onError ( RuntimeException ()) ĊĊĠĠĠĠĠĠĠ Ġassert ( viewModel . book List . value ?. status Ġ== ĠResource State . ERROR ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġfetch Book List _ with Error On Failure () Ġ{ ĊĊĠĠĠĠĠĠĠ ĠviewModel . fetch Book List () ĊĊĠĠĠĠĠĠĠ Ġverify ( mock UseCase ). execute ( capt or . capture (), Ġeq ( null )) ĊĠĠĠĠĠĠĠ Ġcapt or . first Value . onError ( RuntimeException ()) ĊĊĠĠĠĠĠĠĠ Ġassert ( viewModel . book List . value ?. data Ġ== Ġnull ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġfetch Book List _ with Loading () Ġ{ ĊĊĠĠĠĠĠĠĠ ĠviewModel . fetch Book List () ĊĊĠĠĠĠĠĠĠ Ġassert ( viewModel . book List . value ?. status Ġ== ĠResource State . LOADING ) ĊĠĠĠ Ġ} Ċ }