package Ġcom . bol aware . movie pro app . presentation Ċ Ċ import Ġandroidx . arch . core . executor . testing . Instant Task Executor Rule Ċ import Ġcom . bol aware . movie pro app . domain . inter actor . details . Get Movie UseCase Ċ import Ġcom . bol aware . movie pro app . domain . inter actor . search . Search Movies UseCase Ċ import Ġcom . bol aware . movie pro app . domain . model . Movie Summary Ċ import Ġcom . n ha ar man . mockito _ kotlin .* Ċ import Ġkon veyor . base . random Build Ċ import Ġorg . junit . Assert Ċ 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 . Mock Ċ import Ġorg . mockito . Mockito Annotations ĊĊ Ċ @ RunWith ( JUnit 4 :: class ) Ċ class ĠMain ViewModel Test Ġ{ ĊĠĠĠ Ġ@ get : Rule ĊĠĠĠ Ġvar Ġinstant Task Executor Rule Ġ= ĠInstant Task Executor Rule () ĊĊĠĠĠ Ġlateinit Ġvar Ġmain ViewModel : ĠMain ViewModel ĊĊĠĠĠ Ġ@ Mock Ġlateinit Ġvar Ġsearch Movies UseCase : ĠSearch Movies UseCase ĊĠĠĠ Ġ@ Mock Ġlateinit Ġvar Ġget Movie UseCase : ĠGet Movie UseCase ĊĠĠĠ Ġ@ Mock Ġlateinit Ġvar Ġget Movies Subscriber : ĠMain ViewModel . Get Movies Subscriber ĊĠĠĠ Ġ@ Mock Ġlateinit Ġvar Ġget Movie Subscriber : ĠMain ViewModel . Get Movie Subscriber ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun ĠsetUp (){ ĊĠĠĠĠĠĠĠ ĠMockito Annotations . init Mocks ( this ) ĊĠĠĠĠĠĠĠ Ġmain ViewModel Ġ= ĠMain ViewModel ( search Movies UseCase , Ġget Movie UseCase ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` test Ġsearch Term () Ġcalls Ġsearch Movies UseCase ` (){ ĊĠĠĠĠĠĠĠ Ġval Ġsearch Term Ġ: ĠString Ġ= Ġ" King " ĊĠĠĠĠĠĠĠ Ġmain ViewModel . search Movie ( search Term ) ĊĠĠĠĠĠĠĠ Ġverify ( search Movies UseCase ). execute ( any (), Ġany ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` test Ġsearch Term () Ġdoesnt Ġcall Ġsearch Movies UseCase Ġwhen Ġsearch Ġterm Ġis Ġempty ` (){ ĊĠĠĠĠĠĠĠ Ġval Ġsearch Term Ġ= Ġ"" ĊĠĠĠĠĠĠĠ Ġmain ViewModel . search Movie ( search Term ) ĊĠĠĠĠĠĠĠ Ġverify ( search Movies UseCase , Ġnever ()). execute ( any (), Ġany ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` test Ġsearch Term () Ġcalls Ġloader ` (){ ĊĠĠĠĠĠĠĠ Ġval Ġsearch Term Ġ: ĠString Ġ= Ġ" King " ĊĠĠĠĠĠĠĠ Ġmain ViewModel . search Movie ( search Term ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( main ViewModel . progress Indicator Ld . value , Ġtrue ) ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` test Ġsearch Term () Ġparam Ġis Ġpassed Ġcorrectly ` (){ ĊĠĠĠĠĠĠĠ Ġval Ġobserver Captor Ġ= Ġargument Captor < Main ViewModel . Get Movies Subscriber >() ĊĠĠĠĠĠĠĠ Ġval Ġparams Captor Ġ= Ġargument Captor < Search Movies UseCase . Params >() ĊĊĠĠĠĠĠĠĠ Ġval Ġsearch Term Ġ= Ġ" L ion " ĊĊĠĠĠĠĠĠĠ Ġmain ViewModel . search Movie ( search Term ) ĊĊĠĠĠĠĠĠĠ Ġverify ( search Movies UseCase ). execute ( observer Captor . capture (), Ġparams Captor . capture ()) ĊĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( search Term , Ġobserver Captor . first Value . current Search Term ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( search Term , Ġparams Captor . first Value . term ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` test Ġget Movie Details () Ġcalls Ġget Movie UseCase ` (){ ĊĠĠĠĠĠĠĠ Ġval Ġmovie Summary Ġ= Ġrandom Build < Movie Summary >() ĊĠĠĠĠĠĠĠ Ġmain ViewModel . get Movie Details ( movie Summary ) ĊĠĠĠĠĠĠĠ Ġverify ( get Movie UseCase ). execute ( any (), Ġany ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` test Ġget Movie Details () Ġclears Ġpreviously Ġselected ĠviewModel ` (){ ĊĠĠĠĠĠĠĠ Ġval Ġmovie Summary Ġ= Ġrandom Build < Movie Summary >() ĊĠĠĠĠĠĠĠ Ġmain ViewModel . get Movie Details ( movie Summary ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( main ViewModel . movie Ld . value , Ġnull ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( main ViewModel . movie Summary Ld . value , Ġmovie Summary ) ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` test Ġget Movie Details () Ġparam Ġis Ġpassed Ġcorrectly ` (){ ĊĠĠĠĠĠĠĠ Ġval Ġparams Captor Ġ= Ġargument Captor < Get Movie UseCase . Params >() ĊĊĠĠĠĠĠĠĠ Ġval Ġmovie Summary Ġ= Ġrandom Build < Movie Summary >() ĊĊĠĠĠĠĠĠĠ Ġmain ViewModel . get Movie Details ( movie Summary ) ĊĊĠĠĠĠĠĠĠ Ġverify ( get Movie UseCase ). execute ( any (), Ġparams Captor . capture ()) ĊĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( movie Summary . imdb ID , Ġparams Captor . first Value . imdb Id ) ĊĠĠĠ Ġ} Ċ Ċ }