package Ġdev . sert an . android . paper . data . database Ċ Ċ import Ġandroidx . test . filters . Small Test Ċ import Ġcom . google . common . truth . Truth Ċ import Ġdagger . h ilt . android . testing . H ilt Android Rule Ċ import Ġdagger . h ilt . android . testing . H ilt Android Test Ċ import Ġdev . sert an . android . paper . data . model . Note Ċ import Ġjavax . inject . Inject Ċ import Ġkotlinx . coroutines . flow . last Ċ import Ġkotlinx . coroutines . flow . take Ċ import Ġkotlinx . coroutines . run Blocking Ċ import Ġorg . junit . After Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ Ċ @ Small Test Ċ @ H ilt Android Test Ċ internal Ġclass ĠNote Db Service Test Ġ{ ĊĠĠĠ Ġprivate Ġval Ġuser Uid Ġ= Ġ" 1 " ĊĠĠĠ Ġprivate Ġval Ġnote Ġ= ĠNote ( user Uid Ġ= Ġuser Uid ) ĊĊĠĠĠ Ġ@ get : Rule ĊĠĠĠ Ġval Ġh ilt Rule Ġ= ĠH ilt Android Rule ( this ) ĊĊĠĠĠ Ġ@ Inject ĊĠĠĠ Ġlateinit Ġvar Ġdb Service : ĠNote Db Service ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun ĠsetUp () Ġ= Ġh ilt Rule . inject () ĊĊĠĠĠ Ġ@ After ĊĠĠĠ Ġfun Ġteardown () Ġ{ ĊĠĠĠĠĠĠĠ Ġrun Blocking Ġ{ Ġdb Service . delete ( note ) Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġcreate _ success () Ġ= Ġrun Blocking Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġdb Service . create ( note ) ĊĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( response . is Success ). isTrue () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġdelete _ success () Ġ= Ġrun Blocking Ġ{ ĊĠĠĠĠĠĠĠ Ġdb Service . create ( note ) ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġdb Service . delete ( note ) ĊĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( response . is Success ). isTrue () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġupdate _ success () Ġ= Ġrun Blocking Ġ{ ĊĠĠĠĠĠĠĠ Ġdb Service . create ( note ) ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġdb Service . update ( note . apply Ġ{ Ġtitle Ġ= Ġ" updated " Ġ}) ĊĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( response . is Success ). isTrue () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġget Note _ null Value _ if Not Created () Ġ= Ġrun Blocking Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġdb Service . get Note ( uid Ġ= Ġnote . uid ) ĊĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( response . is Success ). isTrue () ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( response . value ). isNull () ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( response . exception ). isNull () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġget Notes _ success () Ġ= Ġrun Blocking Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġsecond Note Ġ= ĠNote ( user Uid Ġ= Ġuser Uid ) ĊĠĠĠĠĠĠĠ Ġdb Service . create ( note ) ĊĠĠĠĠĠĠĠ Ġdb Service . create ( second Note ) ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġdb Service . get Notes ( user Uid Ġ= Ġuser Uid ). take ( 2 ). last () ĊĠĠĠĠĠĠĠ Ġdb Service . delete ( second Note ) ĊĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( response . is Success ). isTrue () ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( response . value ). contains ( note ) ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( response . value ). contains ( second Note ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġget Notes _ emptyList _ if Not Created () Ġ= Ġrun Blocking Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġdb Service . get Notes ( user Uid Ġ= Ġuser Uid ). take ( 2 ). last () ĊĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( response . is Success ). isTrue () ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( response . value ). isEmpty () ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( response . exception ). isNull () ĊĠĠĠ Ġ} Ċ Ċ } Ċ