Ċ package Ġdev . d ante hem erson . per uv ian food . data . local . dao Ċ Ċ import Ġandroidx . room . Room Ċ import Ġandroidx . test . core . app . Application Provider Ċ import Ġandroidx . test . ext . junit . runners . Android JUnit 4 Ċ import Ġdev . d ante hem erson . per uv ian food . data . local . Per uv ian Food Posts Database Ċ import Ġdev . d ante hem erson . per uv ian food . model . Post Ċ import Ġkotlinx . coroutines . flow . toList Ċ import Ġkotlinx . coroutines . run Blocking Ċ import Ġorg . hamcrest . Core Matchers . equalTo Ċ import Ġorg . hamcrest . Matcher Assert . assertThat Ċ import Ġorg . junit . After Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ Ċ @ RunWith ( Android JUnit 4 :: class ) Ċ class ĠPosts Dao Test Ġ{ ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġm Database : ĠPer uv ian Food Posts Database ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun Ġinit () Ġ{ ĊĠĠĠĠĠĠĠ Ġm Database Ġ= ĠRoom . in Memory Database Builder ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠApplication Provider . getApplicationContext (), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠPer uv ian Food Posts Database :: class . java ĊĠĠĠĠĠĠĠ Ġ). build () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Throws ( InterruptedException :: class ) ĊĠĠĠ Ġfun Ġinsert _ and _ select _ posts () Ġ= Ġrun Blocking Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġposts Ġ= ĠlistOf ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠPost ( 1 , Ġ" Test Ġ 1 ", Ġ" Test Ġ 1 ", Ġ" Test Ġ 1 "), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠPost ( 2 , Ġ" Test Ġ 2 ", Ġ" Test Ġ 2 ", Ġ" Test Ġ 3 ") ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġm Database . get Posts Dao (). insert Posts ( posts ) ĊĊĠĠĠĠĠĠĠ Ġval Ġdb Posts Ġ= Ġm Database . get Posts Dao (). getAll Posts (). toList ()[ 0 ] ĊĊĠĠĠĠĠĠĠ ĠassertThat ( db Posts , ĠequalTo ( posts )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Throws ( InterruptedException :: class ) ĊĠĠĠ Ġfun Ġselect _ post _ by _ id () Ġ= Ġrun Blocking Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġposts Ġ= ĠlistOf ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠPost ( 1 , Ġ" Test Ġ 1 ", Ġ" Test Ġ 1 ", Ġ" Test Ġ 1 "), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠPost ( 2 , Ġ" Test Ġ 2 ", Ġ" Test Ġ 2 ", Ġ" Test Ġ 3 ") ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġm Database . get Posts Dao (). insert Posts ( posts ) ĊĊĠĠĠĠĠĠĠ Ġvar Ġdb Post Ġ= Ġm Database . get Posts Dao (). getPost ById ( 1 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( db Post . toList ()[ 0 ], ĠequalTo ( posts [ 0 ])) ĊĊĠĠĠĠĠĠĠ Ġdb Post Ġ= Ġm Database . get Posts Dao (). getPost ById ( 1 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( db Post . toList ()[ 1 ], ĠequalTo ( posts [ 1 ])) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ After ĊĠĠĠ Ġfun Ġcleanup () Ġ{ ĊĠĠĠĠĠĠĠ Ġm Database . close () ĊĠĠĠ Ġ} Ċ } Ċ