/** Ċ Ġ* ĠCreated Ġby Ġan and w ana 0 0 1 Ġon Ċ Ġ* Ġ 2 7 , ĠFebruary , Ġ 2 0 2 2 Ċ Ġ**/ Ċ Ċ package Ġcom . ak sh ay . room accounting . dao Ċ Ċ import Ġcom . ak sh ay . room accounting . data . Mock Data Ċ import Ġcom . ak sh ay . room accounting . data . dao . Invoice Dao Ċ import Ġcom . ak sh ay . room accounting . data . model . Status Invoice Ċ import Ġcom . ak sh ay . room accounting . data . persistence . App Database Ċ import Ġcom . ak sh ay . room accounting . di . module . Database Module Ċ import Ġcom . google . common . truth . Truth . assertThat Ċ import Ġdagger . h ilt . android . testing . H ilt Android Rule Ċ import Ġdagger . h ilt . android . testing . H ilt Android Test Ċ import Ġdagger . h ilt . android . testing . H ilt Test Application Ċ import Ġdagger . h ilt . android . testing . Un install Modules Ċ import Ġkotlinx . coroutines . flow . first Ċ import Ġkotlinx . coroutines . run Blocking Ċ import Ġorg . junit . After Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . ro bo lectric . Ro bo lectric TestRunner Ċ import Ġorg . ro bo lectric . annotation . Config Ċ import Ġjavax . inject . Inject Ċ Ċ /** Ċ Ġ* ĠUnit ĠTest Ġfor Ġ[ Invoice Dao ]. Ċ Ġ*/ Ċ @ H ilt Android Test Ċ @ RunWith ( Ro bo lectric TestRunner :: class ) Ċ @ Un install Modules ( Database Module :: class ) Ċ @ Config ( application Ġ= ĠH ilt Test Application :: class ) Ċ class ĠInvoice Dao UnitTest Ġ{ ĊĊĠ Ġ@ get : Rule ĊĠ Ġvar Ġh ilt Rule Ġ= ĠH ilt Android Rule ( this ) ĊĊĠ Ġ@ Inject ĊĠ Ġlateinit Ġvar Ġapp Database : ĠApp Database ĊĊĠ Ġ@ Inject ĊĠ Ġlateinit Ġvar Ġinvoice Dao : ĠInvoice Dao ĊĊĠ Ġ@ Before ĊĠ Ġfun ĠsetUp () Ġ{ ĊĠĠĠ Ġh ilt Rule . inject () ĊĠ Ġ} ĊĊĠ Ġ@ After ĊĠ Ġfun Ġclose Db () Ġ{ ĊĠĠĠ Ġapp Database . close () ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun ĠtestGet All In voices _ insert Invoice _ fetch _ is Successful () Ġ= Ġrun Blocking Ġ{ ĊĠĠĠ Ġval Ġinvoice Ġ= ĠMock Data . pending Invoice ĊĠĠĠ Ġinvoice Dao . insert Invoice ( invoice ) ĊĊĠĠĠ Ġval Ġminimal Invoice List Ġ= Ġinvoice Dao . getAll Minimal In voices (). first () ĊĊĠĠĠ ĠassertThat ( minimal Invoice List [ 0 ]. id ). isEqualTo ( invoice . id ) ĊĠĠĠ ĠassertThat ( minimal Invoice List [ 0 ]. client Name ). isEqualTo ( invoice . client Name ) ĊĠĠĠ ĠassertThat ( minimal Invoice List [ 0 ]. status ). isEqualTo ( invoice . status ) ĊĠĠĠ ĠassertThat ( minimal Invoice List [ 0 ]. payment Due ). isEqualTo ( invoice . payment Due ) ĊĠĠĠ ĠassertThat ( minimal Invoice List [ 0 ]. total ). isEqualTo ( invoice . total ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun ĠtestGet All In voices _ insert None _ fetch _ emptyList Received () Ġ= Ġrun Blocking Ġ{ ĊĠĠĠ Ġval Ġminimal Invoice List Ġ= Ġinvoice Dao . getAll Minimal In voices (). first () ĊĠĠĠ ĠassertThat ( minimal Invoice List ). isEmpty () ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun ĠtestGet Invoice _ insert Invoice _ fetch _ is Successful () Ġ= Ġrun Blocking Ġ{ ĊĠĠĠ Ġval Ġexcept ed Invoice Ġ= ĠMock Data . pending Invoice ĊĠĠĠ Ġinvoice Dao . insert Invoice ( except ed Invoice ) ĊĊĠĠĠ Ġval Ġinvoice Ġ= Ġinvoice Dao . get Invoice ( except ed Invoice . id ). first () ĊĊĠĠĠ ĠassertThat ( invoice ?. id ). isEqualTo ( except ed Invoice . id ) ĊĠĠĠ ĠassertThat ( invoice ?. client Name ). isEqualTo ( except ed Invoice . client Name ) ĊĠĠĠ ĠassertThat ( invoice ?. client Email ). isEqualTo ( except ed Invoice . client Email ) ĊĠĠĠ ĠassertThat ( invoice ?. items ). isEqualTo ( except ed Invoice . items ) ĊĠĠĠ ĠassertThat ( invoice ?. client Address ). isEqualTo ( except ed Invoice . client Address ) ĊĠĠĠ ĠassertThat ( invoice ?. sender Address ). isEqualTo ( except ed Invoice . sender Address ) ĊĠĠĠ ĠassertThat ( invoice ?. status ). isEqualTo ( except ed Invoice . status ) ĊĠĠĠ ĠassertThat ( invoice ?. createdAt ). isEqualTo ( except ed Invoice . createdAt ) ĊĠĠĠ ĠassertThat ( invoice ?. description ). isEqualTo ( except ed Invoice . description ) ĊĠĠĠ ĠassertThat ( invoice ?. payment Terms ). isEqualTo ( except ed Invoice . payment Terms ) ĊĠĠĠ ĠassertThat ( invoice ?. payment Due ). isEqualTo ( except ed Invoice . payment Due ) ĊĠĠĠ ĠassertThat ( invoice ?. total ). isEqualTo ( except ed Invoice . total ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun ĠtestGet Invoice _ insert None _ fetch _ null Invoice Received () Ġ= Ġrun Blocking Ġ{ ĊĠĠĠ Ġval Ġinvoice Ġ= Ġinvoice Dao . get Invoice ("# 1 3 AB CD "). first () ĊĠĠĠ ĠassertThat ( invoice ). isNull () ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Insert ListOf Invoice _ insert Invoice List _ fetch _ is Successful () Ġ= Ġrun Blocking Ġ{ ĊĠĠĠ Ġval Ġexcept ed Invoice List Ġ= ĠMock Data . invoice List ĊĠĠĠ Ġinvoice Dao . insert ListOf Invoice ( except ed Invoice List ) ĊĊĠĠĠ Ġval Ġitem 1 Ġ= Ġinvoice Dao . get Invoice ( except ed Invoice List [ 0 ]. id ). first () ĊĠĠĠ ĠassertThat ( item 1 ?. id ). isEqualTo ( except ed Invoice List [ 0 ]. id ) ĊĊĠĠĠ Ġval Ġitem 2 Ġ= Ġinvoice Dao . get Invoice ( except ed Invoice List [ 1 ]. id ). first () ĊĠĠĠ ĠassertThat ( item 2 ?. id ). isEqualTo ( except ed Invoice List [ 1 ]. id ) ĊĊĠĠĠ Ġval Ġitem 3 Ġ= Ġinvoice Dao . get Invoice ( except ed Invoice List [ 2 ]. id ). first () ĊĠĠĠ ĠassertThat ( item 3 ?. id ). isEqualTo ( except ed Invoice List [ 2 ]. id ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Delete Invoice _ insert Invoice _ delete _ deleted Successfully () Ġ= Ġrun Blocking Ġ{ ĊĠĠĠ Ġval Ġinvoice Ġ= ĠMock Data . pending Invoice ĊĠĠĠ Ġinvoice Dao . insert Invoice ( invoice ) ĊĊĠĠĠ Ġval Ġsaved Invoice Ġ= Ġinvoice Dao . get Invoice ( invoice . id ). first () ĊĠĠĠ ĠassertThat ( saved Invoice ). isEqualTo ( invoice ) ĊĊĠĠĠ Ġinvoice Dao . delete Invoice ( invoice . id ) ĊĊĠĠĠ Ġval Ġfetch Deleted Invoice Ġ= Ġinvoice Dao . get Invoice ( invoice . id ). first () ĊĠĠĠ ĠassertThat ( fetch Deleted Invoice ). isNull () ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Mark Invoice As Paid _ insert Invoice _ mark Paid _ status Updated Successfully () Ġ= Ġrun Blocking Ġ{ ĊĠĠĠ Ġval Ġinvoice Ġ= ĠMock Data . pending Invoice ĊĠĠĠ Ġinvoice Dao . insert Invoice ( invoice ) ĊĊĠĠĠ Ġval Ġupdated Invoice Status Ġ= ĠMock Data . get Update Invoice Status To Paid ( invoice . id ) ĊĠĠĠ Ġinvoice Dao . mark Invoice As Paid ( updated Invoice Status ) ĊĊĠĠĠ Ġval Ġupdated Invoice Ġ= Ġinvoice Dao . get Invoice ( invoice . id ). first () ĊĠĠĠ ĠassertThat ( updated Invoice ?. status ). isEqualTo ( Status Invoice . PA ID ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Save Updated Invoice _ insert Invoice _ update Fields _ Invoice Updated Successfully () Ġ= Ġrun Blocking Ġ{ ĊĠĠĠ Ġ// ĠID Ġfor Ġboth Ġthe Ġinvoice Ġshould Ġbe Ġsame Ġin Ġorder Ġto Ġupdate Ġthe Ġsame Ġinvoice . ĊĠĠĠ Ġval Ġinvoice Ġ= ĠMock Data . pending Invoice ĊĠĠĠ Ġinvoice Dao . insert Invoice ( invoice ) ĊĊĠĠĠ Ġval Ġold Invoice Ġ= Ġinvoice Dao . get Invoice ( invoice . id ). first () ĊĠĠĠ ĠassertThat ( old Invoice ?. id ). isEqualTo ( invoice . id ) ĊĠĠĠ ĠassertThat ( old Invoice ?. client Name ). isEqualTo ( invoice . client Name ) ĊĊĠĠĠ Ġval Ġnew Invoice Ġ= ĠMock Data . modified Pending Invoice ĊĠĠĠ Ġinvoice Dao . save Updated Invoice ( new Invoice ) ĊĊĠĠĠ Ġval Ġmodified Invoice Ġ= Ġinvoice Dao . get Invoice ( invoice . id ). first () ĊĠĠĠ ĠassertThat ( modified Invoice ?. id ). isEqualTo ( invoice . id ) ĊĠĠĠ ĠassertThat ( modified Invoice ?. client Name ). isEqualTo ( new Invoice . client Name ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Check If Id Exist _ insert Invoice _ check _ delete _ check _ ex istence Checked Successfully () Ġ= ĊĠĠĠ Ġrun Blocking Ġ{ ĊĠĠĠĠĠ Ġval Ġinvoice Ġ= ĠMock Data . pending Invoice ĊĠĠĠĠĠ Ġinvoice Dao . insert Invoice ( invoice ) ĊĊĠĠĠĠĠ Ġval Ġis Present Ġ= Ġinvoice Dao . check If Id Exist ( invoice . id ) ĊĠĠĠĠĠ ĠassertThat ( isPresent ). isTrue () ĊĊĠĠĠĠĠ Ġinvoice Dao . delete Invoice ( invoice . id ) ĊĊĠĠĠĠĠ Ġval Ġis Present After Delete Ġ= Ġinvoice Dao . check If Id Exist ( invoice . id ) ĊĠĠĠĠĠ ĠassertThat ( isPresent After Delete ). isFalse () ĊĠĠĠ Ġ} Ċ Ċ } Ċ