package Ġcom . e zi ke . to ben na . star w ars search . character _ search . presentation Ċ Ċ import Ġcom . e zi ke . to ben na . star w ars search . character _ search . Test Post Execution Thread Ċ import Ġcom . e zi ke . to ben na . star w ars search . character _ search . data . Dummy Data Ċ import Ġcom . e zi ke . to ben na . star w ars search . character _ search . f akes . Fake Search History Repository Ċ import Ġcom . e zi ke . to ben na . star w ars search . character _ search . f akes . Fake Search Repository Ċ import Ġcom . e zi ke . to ben na . star w ars search . character _ search . mapper . Character Model Mapper Ċ import Ġcom . e zi ke . to ben na . star w ars search . character _ search . presentation . Search Screen Result . Search Character Result Ċ import Ġcom . e zi ke . to ben na . star w ars search . lib _ character _ search . domain . model . Character Ċ import Ġcom . e zi ke . to ben na . star w ars search . lib _ character _ search . domain . use case . search . Search Characters Ċ import Ġcom . e zi ke . to ben na . star w ars search . lib _ character _ search . domain . use case . search history . Clear Search History Ċ import Ġcom . e zi ke . to ben na . star w ars search . lib _ character _ search . domain . use case . search history . Get Search History Ċ import Ġcom . e zi ke . to ben na . star w ars search . lib _ character _ search . domain . use case . search history . Save Search Ċ import Ġcom . e zi ke . to ben na . star w ars search . presentation . base . View Intent Ċ import Ġcom . e zi ke . to ben na . star w ars search . test utils . ERROR _ MSG Ċ import Ġcom . e zi ke . to ben na . star w ars search . test utils . Flow Recorder Ċ import Ġcom . e zi ke . to ben na . star w ars search . test utils . ResponseType Ċ import Ġcom . e zi ke . to ben na . star w ars search . test utils . contains Elements Ċ import Ġcom . e zi ke . to ben na . star w ars search . test utils . record With Ċ import Ġcom . google . common . truth . Truth . assertThat Ċ import Ġkotlinx . coroutines . flow . collect Ċ import Ġkotlinx . coroutines . test . Test Coroutine Scope Ċ import Ġkotlinx . coroutines . test . run Blocking Test Ċ import Ġorg . junit . Test Ċ import Ġjava . net . Socket TimeoutException Ċ Ċ class ĠSearch Screen Intent Processor Test Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġfake Character Repository Ġ= ĠFake Search Repository () ĊĊĠĠĠ Ġprivate Ġval Ġfake Search History Repository Ġ= ĠFake Search History Repository () ĊĊĠĠĠ Ġprivate Ġval Ġcharacter Model Mapper Ġ= ĠCharacter Model Mapper () ĊĊĠĠĠ Ġprivate Ġval Ġtest Post Execution Thread Ġ= ĠTest Post Execution Thread () ĊĊĠĠĠ Ġprivate Ġval Ġsearch View Intent Processor Ġ= ĊĠĠĠĠĠĠĠ ĠSearch Screen Intent Processor ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠSearch Characters ( fake Character Repository , Ġtest Post Execution Thread ), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠSave Search ( fake Search History Repository , Ġtest Post Execution Thread ), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠGet Search History ( fake Search History Repository , Ġtest Post Execution Thread ), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠClear Search History ( fake Search History Repository , Ġtest Post Execution Thread ), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcharacter Model Mapper ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠ Ġprivate Ġval Ġresult Recorder : ĠFlow Recorder < Search Screen Result > Ġ= ĠFlow Recorder ( Test Coroutine Scope ()) ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` check Ġthat ĠLoad Search History Intent Ġreturns ĠSuccess Result `() Ġ= Ġrun Blocking Test Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġlist : ĠList < Character > Ġ= ĠDummy Data . character List ĊĠĠĠĠĠĠĠ Ġfake Search History Repository . save Search ( list . first ()) ĊĠĠĠĠĠĠĠ Ġrecord Search History Result ( Load Search History ) ĊĠĠĠĠĠĠĠ ĠassertThat ( result Recorder . take All ()). contains Elements ( Search Screen Result . Loaded History ( list )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` check Ġthat ĠLoad Search History Intent Ġreturns ĠEmpty Result `() Ġ= Ġrun Blocking Test Ġ{ ĊĠĠĠĠĠĠĠ Ġrecord Search History Result ( Load Search History ) ĊĠĠĠĠĠĠĠ ĠassertThat ( result Recorder . take All ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. contains Elements ( Search Screen Result . Loaded History ( emptyList ())) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` check Ġthat ĠClear Search History Intent Ġreturns ĠEmpty Result `() Ġ= Ġrun Blocking Test Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġlist : ĠList < Character > Ġ= ĠDummy Data . character List ĊĠĠĠĠĠĠĠ Ġfake Search History Repository . save Search ( list . first ()) ĊĠĠĠĠĠĠĠ Ġrecord Search History Result ( Clear Search History Intent ) ĊĠĠĠĠĠĠĠ ĠassertThat ( result Recorder . take All ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. contains Elements ( Search Screen Result . Loaded History ( emptyList ())) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` check Ġthat ĠUpdate History Intent Ġreturns ĠHistory Ġin Ġorder `() Ġ= Ġrun Blocking Test Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġfirst : ĠCharacter Ġ= ĠDummy Data . character ĊĠĠĠĠĠĠĠ Ġval Ġsecond : ĠCharacter Ġ= ĠDummy Data . character . copy ( name Ġ= Ġ" am ig ") ĊĠĠĠĠĠĠĠ Ġval Ġthird : ĠCharacter Ġ= ĠDummy Data . character . copy ( birth Year Ġ= Ġ" 1 9 9 7 ") ĊĠĠĠĠĠĠĠ Ġfake Search History Repository . save Search ( first ) ĊĠĠĠĠĠĠĠ Ġfake Search History Repository . save Search ( second ) ĊĠĠĠĠĠĠĠ Ġfake Search History Repository . save Search ( third ) ĊĠĠĠĠĠĠĠ Ġrecord Search History Result ( Update History Intent ( character Model Mapper . map To Model ( second ))) ĊĠĠĠĠĠĠĠ ĠassertThat ( result Recorder . take All ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. contains Elements ( Search Screen Result . Loaded History ( listOf ( second ))) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` check Ġthat ĠSearch Character Intent Ġreturns ĠSuccess Result `() Ġ{ ĊĠĠĠĠĠĠĠ Ġrecord SearchResult ( Search Intent ( Dummy Data . query ), ĠResponse Type . DATA ) ĊĠĠĠĠĠĠĠ ĠassertThat ( result Recorder . take All ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. contains Elements ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠSearch Character Result . Searching , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠSearch Character Result . Success ( Dummy Data . character List ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` Search Character Intent Ġreturns Ġempty Search History Result Ġwhen Ġquery Ġis Ġempty Ġand Ġno Ġsearch Ġis Ġsaved `() Ġ{ ĊĠĠĠĠĠĠĠ Ġsearch View Intent Processor . intent To Result ( Search Intent ("")) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. record With ( result Recorder ) ĊĠĠĠĠĠĠĠ ĠassertThat ( result Recorder . take All ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. contains Elements ( Search Screen Result . Loaded History ( emptyList ())) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` Search Character Intent Ġreturns Ġloaded Search History Result Ġwhen Ġquery Ġis Ġempty Ġand Ġsearch Ġis Ġsaved `() Ġ= ĊĠĠĠĠĠĠĠ Ġrun Blocking Test Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġlist : ĠList < Character > Ġ= ĠDummy Data . character List ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfake Search History Repository . save Search ( list . first ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġsearch View Intent Processor . intent To Result ( Search Intent ("")) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. record With ( result Recorder ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( result Recorder . take All ()). contains Elements ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠSearch Screen Result . Loaded History ( list ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` check Ġthat ĠSearch Character Intent Ġreturns ĠError Result `() Ġ{ ĊĠĠĠĠĠĠĠ Ġrecord SearchResult ( Search Intent ( Dummy Data . query ), ĠResponse Type . ERROR ) ĊĠĠĠĠĠĠĠ Ġval Ġresults : ĠList < Search Screen Result > Ġ= Ġresult Recorder . take All () ĊĠĠĠĠĠĠĠ ĠassertThat ( results . map Ġ{ Ġit . java Class Ġ}) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. contains Elements ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠSearch Character Result . Searching :: class . java , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠSearch Character Result . Error :: class . java ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġerror Result : ĠSearch Character Result . Error Ġ= Ġresults . last () Ġas ĠSearch Character Result . Error ĊĠĠĠĠĠĠĠ ĠassertThat ( error Result . throwable ). isInstanceOf ( Socket TimeoutException :: class . java ) ĊĠĠĠĠĠĠĠ ĠassertThat ( error Result . throwable . message ). isEqualTo ( ERROR _ MSG ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` check Ġthat ĠSave Search Intent Ġsaves Ġcurrent Ġcharacter `() Ġ= Ġrun Blocking Test Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġlist : ĠList < Character > Ġ= ĠDummy Data . character List ĊĠĠĠĠĠĠĠ Ġsearch View Intent Processor . intent To Result ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠSave Search Intent ( character Model Mapper . map To Model ( list . first ())) ĊĠĠĠĠĠĠĠ Ġ). collect () ĊĠĠĠĠĠĠĠ Ġrecord Search History Result ( Load Search History ) ĊĠĠĠĠĠĠĠ ĠassertThat ( result Recorder . take All ()). contains Elements ( Search Screen Result . Loaded History ( list )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġrecord SearchResult ( intent : ĠView Intent , Ġtype : ĠResponse Type ) Ġ{ ĊĠĠĠĠĠĠĠ Ġfake Character Repository . response Type Ġ= Ġtype ĊĠĠĠĠĠĠĠ Ġsearch View Intent Processor . intent To Result ( intent ). record With ( result Recorder ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġrecord Search History Result ( intent : ĠView Intent ) Ġ{ ĊĠĠĠĠĠĠĠ Ġsearch View Intent Processor . intent To Result ( intent ). record With ( result Recorder ) ĊĠĠĠ Ġ} Ċ } Ċ