/* Ċ Ġ* Ċ Ġ* ĠCopyright Ġ( c ) ĠMicrosoft ĠCorporation . ĠAll Ġrights Ġreserved . Ċ Ġ* ĠLicensed Ġunder Ġthe ĠMIT ĠLicense . Ċ Ġ* Ċ Ġ*/ Ċ Ċ package Ġcom . microsoft . device . samples . dual screen experience . domain . order . use cases Ċ Ċ import Ġandroidx . arch . core . executor . testing . Instant Task Executor Rule Ċ import Ġcom . microsoft . device . samples . dual screen experience . domain . order . testutil . Mock Order DataSource Ċ import Ġcom . microsoft . device . samples . dual screen experience . domain . order . testutil . first Order Entity Ċ import Ġcom . microsoft . device . samples . dual screen experience . domain . order . testutil . first Order Item Entity Ċ import Ġkotlinx . coroutines . run Blocking Ċ import Ġorg . hamcrest . Matcher Assert . assertThat Ċ import Ġorg . junit . Assert . assertNull Ċ import Ġorg . junit . Assert . assertTrue Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġorg . hamcrest . core . Is .` is ` Ġas Ġiz Ċ Ċ class ĠSubmit Order UseCase Test Ġ{ ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġsubmit Order UseCase : ĠSubmit Order UseCase ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġmock Repo : ĠMock Order DataSource ĊĊĠĠĠ Ġ@ get : Rule ĊĠĠĠ Ġvar Ġinstant Task Executor Rule Ġ= ĠInstant Task Executor Rule () ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun Ġsetup () Ġ{ ĊĠĠĠĠĠĠĠ Ġmock Repo Ġ= ĠMock Order DataSource () ĊĠĠĠĠĠĠĠ Ġsubmit Order UseCase Ġ= ĠSubmit Order UseCase ( mock Repo ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġsubmit Order If There Is AC urrent One () Ġ= Ġrun Blocking Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcopy First Order Item Entity Ġ= Ġfirst Order Item Entity . copy () ĊĠĠĠĠĠĠĠ Ġval Ġcopy First Order Entity Ġ= Ġfirst Order Entity . copy () ĊĊĠĠĠĠĠĠĠ Ġmock Repo . insert ( copy First Order Entity ) ĊĠĠĠĠĠĠĠ Ġmock Repo . insert Items ( copy First Order Item Entity ) ĊĊĠĠĠĠĠĠĠ Ġval Ġsubmitted OrderId Ġ= Ġsubmit Order UseCase . submit () ĊĠĠĠĠĠĠĠ ĠassertThat ( submitted OrderId , Ġiz ( copy First Order Entity . orderId )) ĊĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġmock Repo . getById ( submitted OrderId !! ) !!. order ĊĠĠĠĠĠĠĠ ĠassertTrue ( result . is Submitted ) ĊĠĠĠĠĠĠĠ ĠassertThat ( result . total Price , Ġiz ( copy First Order Entity . total Price )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġdo Nothing If All Orders Are Submitted () Ġ= Ġrun Blocking Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcopy First Order Entity Ġ= Ġfirst Order Entity . copy () ĊĊĠĠĠĠĠĠĠ Ġcopy First Order Entity . is Submitted Ġ= Ġtrue ĊĠĠĠĠĠĠĠ Ġmock Repo . insert ( copy First Order Entity ) ĊĊĠĠĠĠĠĠĠ Ġval Ġsubmitted OrderId Ġ= Ġsubmit Order UseCase . submit () ĊĠĠĠĠĠĠĠ ĠassertNull ( submitted OrderId ) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( mock Repo . getById ( copy First Order Entity . orderId !! )?. order , Ġiz ( copy First Order Entity )) ĊĠĠĠ Ġ} Ċ } Ċ