package Ġfr . n sp u . dev . record voice learning . db Ċ Ċ import Ġandroid . arch . core . executor . testing . Instant Task Executor Rule Ċ import Ġandroid . arch . persistence . room . Room Ċ import Ġandroid . database . sqlite . SQLite Constraint Exception Ċ import Ġandroid . support . test . Instrumentation Registry Ċ import Ġandroid . support . test . runner . Android JUnit 4 Ċ Ċ import Ġorg . junit . After Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ Ċ import Ġfr . n sp u . dev . record voice learning . LiveData TestUtil Ċ import Ġfr . n sp u . dev . record voice learning . controller . App Database Ċ import Ġfr . n sp u . dev . record voice learning . controller . dao . Folder Dao Ċ import Ġfr . n sp u . dev . record voice learning . controller . dao . Peer Dao Ċ import Ġfr . n sp u . dev . record voice learning . controller . entity . Peer Entity Ċ import Ġjunit . framework . Assert . assertTrue Ċ import Ġjunit . framework . Assert . fail Ċ import Ġorg . hamcrest . Matchers .` is ` Ċ import Ġorg . junit . Assert . assertThat Ċ Ċ /** Ċ Ġ* ĠCreated Ġby Ġn sp u Ġon Ġ 1 8 - 0 2 - 0 7 . Ċ Ġ*/ Ċ @ RunWith ( Android JUnit 4 :: class ) Ċ class ĠPeer Dao Test Ġ{ ĊĊĠĠĠ Ġ@ get : Rule ĊĠĠĠ Ġvar Ġinstant Task Executor Rule Ġ= ĠInstant Task Executor Rule () ĊĊĠĠĠ Ġprivate Ġvar Ġm Database : ĠApp Database ? Ġ= Ġnull ĊĊĠĠĠ Ġprivate Ġvar Ġm Peer Dao : ĠPeer Dao ? Ġ= Ġnull ĊĊĠĠĠ Ġprivate Ġvar Ġm Folder Dao : ĠFolder Dao ? Ġ= Ġnull ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġ@ Throws ( Exception :: class ) ĊĠĠĠ Ġfun Ġinit Db () Ġ{ ĊĠĠĠĠĠĠĠ Ġ// Ġusing Ġan Ġin - memory Ġdatabase Ġbecause Ġthe Ġinformation Ġstored Ġhere Ġdis appe ars Ġwhen Ġthe ĊĠĠĠĠĠĠĠ Ġ// Ġprocess Ġis Ġkilled ĊĠĠĠĠĠĠĠ Ġm Database Ġ= ĠRoom . in Memory Database Builder ( Instrumentation Registry . getContext (), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠApp Database :: class . java ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ// Ġallowing Ġmain Ġthread Ġqueries , Ġjust Ġfor Ġtesting ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. allow MainThread Queries () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. build () ĊĊĠĠĠĠĠĠĠ Ġm Peer Dao Ġ= Ġm Database !!. peer Dao () ĊĠĠĠĠĠĠĠ Ġm Folder Dao Ġ= Ġm Database !!. folder Dao () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ After ĊĠĠĠ Ġ@ Throws ( Exception :: class ) ĊĠĠĠ Ġfun Ġclose Db () Ġ{ ĊĠĠĠĠĠĠĠ Ġm Database !!. close () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Throws ( InterruptedException :: class ) ĊĠĠĠ Ġfun Ġget Peers When No Peer Inserted () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcomments Ġ= ĠLive Data TestUtil . getValue ( m Peer Dao !!. load Peer By Folder Id ( TestData . PEER _ ENTITY . folder Id !! )) ĊĊĠĠĠĠĠĠĠ ĠassertTrue ( comments . isEmpty ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Throws ( InterruptedException :: class ) ĊĠĠĠ Ġfun Ġcant Insert Peer Without Product () Ġ{ ĊĠĠĠĠĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġm Peer Dao !!. insert Peers Sync ( TestData . PE ERS ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfail (" SQLite Constraint Exception Ġexpected ") ĊĠĠĠĠĠĠĠ Ġ} Ġcatch Ġ( ignored : ĠSQLite Constraint Exception ) Ġ{ ĊĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Throws ( InterruptedException :: class ) ĊĠĠĠ Ġfun Ġget Peers After Inserted () Ġ{ ĊĠĠĠĠĠĠĠ Ġm Folder Dao !!. insert Folders Sync ( TestData . FOLDER S ) ĊĠĠĠĠĠĠĠ Ġm Peer Dao !!. insert Peers Sync ( TestData . PE ERS ) ĊĊĠĠĠĠĠĠĠ Ġval Ġcomments Ġ= ĠLive Data TestUtil . getValue ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġm Peer Dao !!. load Peer By Folder Id ( TestData . PEER _ ENTITY . folder Id !! )) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( comments . size , Ġ` is `( 1 )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Throws ( InterruptedException :: class ) ĊĠĠĠ Ġfun Ġget Peer By Folder Id () Ġ{ ĊĠĠĠĠĠĠĠ Ġm Folder Dao !!. insert Folders Sync ( TestData . FOLDER S ) ĊĠĠĠĠĠĠĠ Ġm Peer Dao !!. insert Peers Sync ( TestData . PE ERS ) ĊĊĠĠĠĠĠĠĠ Ġval Ġcomments Ġ= ĠLive Data TestUtil . getValue ( m Peer Dao !!. load Peer By Folder Id ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠTest Data . PEER _ ENTITY . folder Id !! )) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( comments . size , Ġ` is `( 1 )) ĊĠĠĠ Ġ} Ċ } Ċ