package Ġcom . example . feature _ rate _ tracker Ċ Ċ import Ġandroidx . arch . core . executor . testing . Instant Task Executor Rule Ċ import Ġcom . example . core . domain . data delegate . Data Ċ import Ġcom . example . core . test . Rx Java Test Rule Ċ import Ġcom . example . core . test . then Emit Ċ import Ġcom . example . core . test . then Emit Empty Ċ import Ġcom . example . feature _ rate _ tracker . impl . Main Screen Contract Ċ import Ġcom . example . feature _ rate _ tracker . impl . Main State Reducer Ċ import Ġcom . example . feature _ rate _ tracker . impl . Main ViewModel Ċ import Ġcom . example . feature _ rate _ tracker _ api . domain . Get Main Currency Rates UseCase Ċ import Ġcom . example . feature _ rate _ tracker _ api . domain . Ob serve Ad vertisement UseCase Ċ import Ġcom . example . feature _ rate _ tracker _ api . domain . Ob serve Currency Rates UseCase Ċ import Ġcom . n ha ar man . mock it ok otlin 2 .* Ċ import Ġjunit . framework . Assert . assertEquals Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . rules . Test Rule Ċ Ċ class ĠMain ViewModel Test Ġ{ ĊĊĠĠĠ Ġ@ Rule ĊĠĠĠ Ġ@ Jvm Field ĊĠĠĠ Ġval Ġrx Rule : ĠTest Rule Ġ= ĠRx Java Test Rule () ĊĊĠĠĠ Ġ@ Rule ĊĠĠĠ Ġ@ Jvm Field ĊĠĠĠ Ġval Ġlive Data Rule : ĠTest Rule Ġ= ĠInstant Task Executor Rule () ĊĊĠĠĠ Ġprivate Ġval Ġrate Tracker State Reducer : ĠMain State Reducer Ġ= Ġspy ( Main State Reducer ()) ĊĠĠĠ Ġprivate Ġval Ġobserve Ad vertisement : ĠOb serve Ad vertisement UseCase Ġ= Ġmock () ĊĠĠĠ Ġprivate Ġval Ġobserve Currency Rates : ĠOb serve Currency Rates UseCase Ġ= Ġmock () ĊĠĠĠ Ġprivate Ġval Ġget Main Currency UseCase : ĠGet Main Currency Rates UseCase Ġ= Ġmock () ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar ĠviewModel : ĠMain ViewModel ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun Ġsetup () Ġ{ ĊĠĠĠĠĠĠĠ Ġwhenever ( observe Currency Rates . invoke ( any ())) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. then Emit ( Data . Complete ( emptyList ())) ĊĠĠĠĠĠĠĠ Ġwhenever ( get Main Currency UseCase ()). then Emit Empty () ĊĊĠĠĠĠĠĠĠ ĠviewModel Ġ= ĠMain ViewModel ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġrate Tracker State Reducer Ġ= Ġrate Tracker State Reducer , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġobserve Currency Rates Ġ= Ġobserve Currency Rates , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġget Main Currency UseCase Ġ= Ġget Main Currency UseCase , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġobserve Ad vertisement Ġ= Ġobserve Ad vertisement ĊĠĠĠĠĠĠĠ Ġ). apply Ġ{ Ġinfinity Loading Ġ= Ġfalse Ġ} ĊĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun ĠtestGet Initial Currency () Ġ{ ĊĠĠĠĠĠĠĠ ĠviewModel . get Initial Currency () ĊĊĠĠĠĠĠĠĠ Ġverify ( get Main Currency UseCase ). invoke () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun ĠtestGet Initial Currency Amount () Ġ{ ĊĠĠĠĠĠĠĠ ĠassertEquals ( viewModel . get Initial Currency Amount (), ĠMain Screen Contract . Rate Tracker State . EMPTY . amount ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` state Ġ| Ġinit iation `() Ġ{ ĊĠĠĠĠĠĠĠ Ġwhenever ( observe Ad vertisement . invoke ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. then Emit ( Data . Complete ( emptyList ())) ĊĊĠĠĠĠĠĠĠ ĠviewModel . init () ĊĊĠĠĠĠĠĠĠ Ġverify ( observe Ad vertisement ). invoke () ĊĠĠĠ Ġ} Ċ }