package Ġcom . k rypt kode . card info finder . ui . card info Ċ Ċ import Ġandroidx . arch . core . executor . testing . Instant Task Executor Rule Ċ import Ġapp . cash . tur bine . test Ċ import Ġcom . google . common . truth . Truth . assertThat Ċ import Ġcom . k rypt kode . card info finder . data . model . Card Info Ċ import Ġcom . k rypt kode . card info finder . data . model . Data State Ċ import Ġcom . k rypt kode . card info finder . data . use case . Get Card Info UseCase Ċ import Ġcom . k rypt kode . card info finder . utils . Fake Data Factory . make Fake Card Info Ċ import Ġcom . k rypt kode . card info finder . utils . Main Coroutine Rule Ċ import Ġcom . k rypt kode . card info finder . utils . run Blocking Test Ċ import Ġio . mock k . Mock K Annotations Ċ import Ġio . mock k . every Ċ import Ġio . mock k . impl . annotations . Mock K Ċ import Ġio . mock k . un mock k All Ċ import Ġkotlinx . coroutines . flow . flow Of Ċ import Ġorg . junit . After Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ Ċ class ĠCard Info ViewModel Test Ġ{ ĊĊĠĠĠ Ġ@ get : Rule ĊĠĠĠ Ġval Ġinstant Task Executor Rule Ġ= ĠInstant Task Executor Rule () ĊĊĠĠĠ Ġ@ get : Rule ĊĠĠĠ Ġval Ġmain Coroutine Rule Ġ= ĠMain Coroutine Rule () ĊĊĠĠĠ Ġ@ Mock K ĊĠĠĠ Ġlateinit Ġvar Ġget Card Info UseCase : ĠGet Card Info UseCase ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġsut : ĠCard Info ViewModel ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun ĠsetUp () Ġ{ ĊĠĠĠĠĠĠĠ ĠMock K Annotations . init ( this ) ĊĠĠĠĠĠĠĠ Ġsut Ġ= ĠCard Info ViewModel ( get Card Info UseCase ) ĊĊĠĠĠĠĠĠĠ Ġstub Get Card Info UseCase ( Data State . Success ( make Fake Card Info ())) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` get Card Info Ġemits Ġcard Number `() Ġ= Ġmain Coroutine Rule . run Blocking Test Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcard Number Ġ= Ġ" 4 2 4 2 4 " ĊĠĠĠĠĠĠĠ Ġsut . card Number . test Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġsut . get Card Info ( card Number ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( expect Item ()). isEqualTo ( card Number ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcancel And Ignore Remaining Events () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` get Card Info Ġsets Ġrefresh Ġstate `() Ġ= Ġmain Coroutine Rule . run Blocking Test Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcard Number Ġ= Ġ" 4 2 4 2 4 " ĊĠĠĠĠĠĠĠ Ġsut . get Card Info ( card Number , Ġtrue ) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( sut . refresh ). isTrue () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` are Equivalent Ġwith Ġrefresh Ġreturns Ġfalse `() Ġ= Ġmain Coroutine Rule . run Blocking Test Ġ{ ĊĊĠĠĠĠĠĠĠ Ġsut . refresh Ġ= Ġtrue ĊĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġsut . are Equivalent . invoke (" 4 2 4 2 4 ", Ġ" 4 2 4 2 4 ") ĊĊĠĠĠĠĠĠĠ ĠassertThat ( result ). isFalse () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` are Equivalent Ġwith Ġsame Ġstrings Ġand Ġwithout Ġrefresh Ġreturns Ġtrue `() Ġ= Ġmain Coroutine Rule . run Blocking Test Ġ{ ĊĊĠĠĠĠĠĠĠ Ġsut . refresh Ġ= Ġfalse ĊĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġsut . are Equivalent . invoke (" 4 2 4 2 4 ", Ġ" 4 2 4 2 4 ") ĊĊĠĠĠĠĠĠĠ ĠassertThat ( result ). isTrue () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` are Equivalent Ġwith Ġdifferent Ġstrings Ġand Ġwithout Ġrefresh Ġreturns Ġfalse `() Ġ= Ġmain Coroutine Rule . run Blocking Test Ġ{ ĊĊĠĠĠĠĠĠĠ Ġsut . refresh Ġ= Ġfalse ĊĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġsut . are Equivalent . invoke (" 4 2 4 ", Ġ" 4 2 4 2 4 ") ĊĊĠĠĠĠĠĠĠ ĠassertThat ( result ). isFalse () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` state Reducer Ġwhen Ġon ĠData State ĠError Ġreturns Ġerror Ġstate `() Ġ= Ġmain Coroutine Rule . run Blocking Test Ġ{ ĊĠĠĠĠĠĠĠ Ġval ĠinitialState Ġ= ĠCard Info ViewState () ĊĊĠĠĠĠĠĠĠ Ġval ĠerrorMessage Ġ= Ġ" Error Ġoccurred " ĊĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġsut . state Reducer . invoke ( initialState , ĠData State . Error ( errorMessage )) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( result . loading ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( result . error ). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( result . errorMessage ). isEqualTo ( errorMessage ) ĊĠĠĠĠĠĠĠ ĠassertThat ( result . card Info ). isEqualTo ( initialState . card Info ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` state Reducer Ġwhen Ġon ĠData State ĠLoading Ġreturns Ġloading Ġstate `() Ġ= Ġmain Coroutine Rule . run Blocking Test Ġ{ ĊĠĠĠĠĠĠĠ Ġval ĠinitialState Ġ= ĠCard Info ViewState () ĊĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġsut . state Reducer . invoke ( initialState , ĠData State . Loading ) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( result . loading ). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( result . error ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( result . errorMessage ). isEqualTo ( initialState . errorMessage ) ĊĠĠĠĠĠĠĠ ĠassertThat ( result . card Info ). isEqualTo ( initialState . card Info ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` state Reducer Ġwhen Ġon ĠData State ĠSuccess Ġreturns Ġsuccess Ġstate `() Ġ= Ġmain Coroutine Rule . run Blocking Test Ġ{ ĊĠĠĠĠĠĠĠ Ġval ĠinitialState Ġ= ĠCard Info ViewState () ĊĠĠĠĠĠĠĠ Ġval Ġcard Info Ġ= Ġmake Fake Card Info () ĊĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġsut . state Reducer . invoke ( initialState , ĠData State . Success ( card Info )) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( result . loading ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( result . error ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( result . errorMessage ). isEqualTo ( initialState . errorMessage ) ĊĠĠĠĠĠĠĠ ĠassertThat ( result . card Info ). isEqualTo ( card Info ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` get Card Info Ġon ĠData State ĠLoading Ġposts Ġview Ġstate `() Ġ= Ġmain Coroutine Rule . run Blocking Test Ġ{ ĊĠĠĠĠĠĠĠ Ġstub Get Card Info UseCase ( Data State . Loading ) ĊĊĠĠĠĠĠĠĠ Ġsut . get Card Info (" 4 2 4 2 4 ") ĊĊĠĠĠĠĠĠĠ Ġsut . view State . test Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġitem Ġ= Ġexpect Item () ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( item . loading ). isTrue () ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( item . error ). isFalse () ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġcancel And Ignore Remaining Events () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` get Card Info Ġon ĠData State ĠSuccess Ġposts Ġview Ġstate `() Ġ= Ġmain Coroutine Rule . run Blocking Test Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcard Info Ġ= Ġmake Fake Card Info () ĊĊĠĠĠĠĠĠĠ Ġstub Get Card Info UseCase ( Data State . Success ( card Info )) ĊĊĠĠĠĠĠĠĠ Ġsut . get Card Info (" 4 2 4 2 4 ") ĊĊĠĠĠĠĠĠĠ Ġsut . view State . test Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġitem Ġ= Ġexpect Item () ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( item . loading ). isFalse () ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( item . error ). isFalse () ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( item . card Info ). isEqualTo ( card Info ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġcancel And Ignore Remaining Events () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` get Card Info Ġon ĠData State ĠError Ġposts Ġview Ġstate `() Ġ= Ġmain Coroutine Rule . run Blocking Test Ġ{ ĊĠĠĠĠĠĠĠ Ġval ĠerrorMessage Ġ= Ġ" Error Ġoccurred " ĊĊĠĠĠĠĠĠĠ Ġstub Get Card Info UseCase ( Data State . Error ( errorMessage )) ĊĊĠĠĠĠĠĠĠ Ġsut . get Card Info (" 4 2 4 2 4 ") ĊĊĠĠĠĠĠĠĠ Ġsut . view State . test Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġitem Ġ= Ġexpect Item () ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( item . loading ). isFalse () ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( item . error ). isTrue () ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( item . errorMessage ). isEqualTo ( errorMessage ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġcancel And Ignore Remaining Events () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ After ĊĠĠĠ Ġfun ĠtearDown () Ġ{ ĊĠĠĠĠĠĠĠ Ġun mock k All () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġstub Get Card Info UseCase ( result : ĠData State < Card Info >) Ġ{ ĊĠĠĠĠĠĠĠ Ġevery Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġget Card Info UseCase . execute ( any ()) ĊĠĠĠĠĠĠĠ Ġ} Ġreturns Ġflow Of ( result ) ĊĠĠĠ Ġ} Ċ } Ċ