package Ġin fix soft . im rank st 1 2 2 1 . android . starter . data Ċ Ċ import Ġandroidx . room . Room Ċ import Ġandroidx . test . espress o . matcher . View Matchers . assertThat Ċ import Ġandroidx . test . ext . junit . runners . Android JUnit 4 Ċ import Ġandroidx . test . platform . app . Instrumentation Registry Ċ import Ġin fix soft . im rank st 1 2 2 1 . android . starter . data . model . UserDetails Ċ import Ġin fix soft . im rank st 1 2 2 1 . android . starter . data . model . UserDetails Dao Ċ import Ġin fix soft . im rank st 1 2 2 1 . android . starter . utilities . get LiveData Value Ċ import Ġin fix soft . im rank st 1 2 2 1 . android . starter . data . Dummy DataSet . D UMMY _ USER 1 Ċ import Ġin fix soft . im rank st 1 2 2 1 . android . starter . data . Dummy DataSet . D UMMY _ USER 2 Ċ import Ġin fix soft . im rank st 1 2 2 1 . android . starter . data . Dummy DataSet . D UMMY _ USER 3 Ċ import Ġin fix soft . im rank st 1 2 2 1 . android . starter . data . Dummy DataSet . D UMMY _ USER 1 _ DETAILS Ċ import Ġin fix soft . im rank st 1 2 2 1 . android . starter . data . Dummy DataSet . D UMMY _ USER 2 _ DETAILS Ċ import Ġin fix soft . im rank st 1 2 2 1 . android . starter . data . Dummy DataSet . D UMMY _ USER 3 _ DETAILS Ċ import Ġkotlinx . coroutines . run Blocking Ċ import Ġorg . hamcrest . Core Matchers . equalTo Ċ import Ġorg . junit . After Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġkotlin . jvm . Throws Ċ Ċ /** Ċ Ġ* Ġ@ author Ġim ran . ch ou dh ury Ċ Ġ* Ġ 1 8 / 9 / 2 1 Ċ Ġ*/ Ċ Ċ @ RunWith ( Android JUnit 4 :: class ) Ċ class ĠUser Details Dao Test Ġ{ ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġdatabase : ĠApp Database ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġuser Details Dao : ĠUser Details Dao ĊĊĠĠĠ Ġ@ Before Ġfun Ġcreate Db () Ġ= Ġrun Blocking { ĊĠĠĠĠĠĠĠ Ġval Ġcontext Ġ= ĠInstrument ation Registry . get Instrumentation (). target Context ĊĠĠĠĠĠĠĠ Ġdatabase Ġ= Ġ ĠRoom . in Memory Database Builder ( context , ĠApp Database :: class . java ). build () ĊĠĠĠĠĠĠĠ Ġuser Details Dao Ġ= Ġdatabase . user Details Dao () ĊĊĠĠĠĠĠĠĠ Ġinsert UserDetails () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ After Ġfun Ġclose Db () Ġ{ ĊĠĠĠĠĠĠĠ Ġdatabase . close () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġinsert UserDetails () Ġ= Ġrun Blocking { ĊĠĠĠĠĠĠĠ Ġdatabase . user Dao Dao (). insert All ( listOf ( D UMMY _ USER 1 , ĠD UMMY _ USER 2 , ĠD UMMY _ USER 3 )) ĊĊĠĠĠĠĠĠĠ Ġuser Details Dao . insert UserDetails ( D UMMY _ USER 1 _ DETAILS ) ĊĠĠĠĠĠĠĠ Ġuser Details Dao . insert UserDetails ( D UMMY _ USER 2 _ DETAILS ) ĊĠĠĠĠĠĠĠ Ġuser Details Dao . insert UserDetails ( D UMMY _ USER 3 _ DETAILS ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Throws ( InterruptedException :: class ) ĊĠĠĠ Ġfun Ġtest UserDetails By Login () Ġ= Ġrun Blocking { ĊĠĠĠĠĠĠĠ ĠassertThat ( get LiveData Value ( user Details Dao . getUser Details By Login ( D UMMY _ USER 1 . login )), ĠequalTo ( D UMMY _ USER 1 _ DETAILS )) ĊĠĠĠĠĠĠĠ ĠassertThat ( get LiveData Value ( user Details Dao . getUser Details By Login ( D UMMY _ USER 2 . login )), ĠequalTo ( D UMMY _ USER 2 _ DETAILS )) ĊĠĠĠĠĠĠĠ ĠassertThat ( get LiveData Value ( user Details Dao . getUser Details By Login ( D UMMY _ USER 3 . login )), ĠequalTo ( D UMMY _ USER 3 _ DETAILS )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Ġfun Ġtest Is UserDetails Available () Ġ= Ġrun Blocking Ġ{ ĊĠĠĠĠĠĠĠ ĠassertThat ( user Details Dao . is UserDetails Available ( 1 ), ĠequalTo ( true )) ĊĠĠĠĠĠĠĠ ĠassertThat ( user Details Dao . is UserDetails Available ( 2 ), ĠequalTo ( true )) ĊĠĠĠĠĠĠĠ ĠassertThat ( user Details Dao . is UserDetails Available ( 3 ), ĠequalTo ( true )) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( user Details Dao . is UserDetails Available ( 0 ), ĠequalTo ( false )) ĊĠĠĠĠĠĠĠ ĠassertThat ( user Details Dao . is UserDetails Available ( 5 ), ĠequalTo ( false )) ĊĠĠĠĠĠĠĠ ĠassertThat ( user Details Dao . is UserDetails Available ( 6 ), ĠequalTo ( false )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Ġfun ĠtestGet UserDetails () Ġ= Ġrun Blocking Ġ{ ĊĠĠĠĠĠĠĠ ĠassertThat ( user Details Dao . getUser Details ( 1 ), ĠequalTo ( D UMMY _ USER 1 _ DETAILS )) ĊĠĠĠĠĠĠĠ ĠassertThat ( user Details Dao . getUser Details ( 2 ), ĠequalTo ( D UMMY _ USER 2 _ DETAILS )) ĊĠĠĠĠĠĠĠ ĠassertThat ( user Details Dao . getUser Details ( 3 ), ĠequalTo ( D UMMY _ USER 3 _ DETAILS )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Ġfun Ġtest Update All UserDetails () Ġ= Ġrun Blocking { ĊĠĠĠĠĠĠĠ Ġval Ġuser Details A 1 Ġ= ĠUser Details ( 1 , Ġ" user 1 "," User ĠA ", Ġ"", 1 , Ġ 1 , Ġ" Google ", Ġ"") ĊĠĠĠĠĠĠĠ Ġval Ġuser Details B 1 Ġ= ĠUser Details ( 2 , Ġ" user 2 "," User ĠB ", Ġ"", 1 , Ġ 1 , Ġ" Google ", Ġ"") ĊĠĠĠĠĠĠĠ Ġval Ġuser Details C 1 Ġ= ĠUser Details ( 3 , Ġ" user 3 "," User ĠC ", Ġ"", 1 , Ġ 1 , Ġ" Google ", Ġ"") ĊĊĠĠĠĠĠĠĠ Ġ// Ġinsert Ġnew Ġvalues ĊĠĠĠĠĠĠĠ Ġuser Details Dao . insert UserDetails ( user Details A 1 ) ĊĠĠĠĠĠĠĠ Ġuser Details Dao . insert UserDetails ( user Details B 1 ) ĊĠĠĠĠĠĠĠ Ġuser Details Dao . insert UserDetails ( user Details C 1 ) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( user Details Dao . getUser Details ( 1 ), ĠequalTo ( user Details A 1 )) ĊĠĠĠĠĠĠĠ ĠassertThat ( user Details Dao . getUser Details ( 2 ), ĠequalTo ( user Details B 1 )) ĊĠĠĠĠĠĠĠ ĠassertThat ( user Details Dao . getUser Details ( 3 ), ĠequalTo ( user Details C 1 )) ĊĊĠĠĠĠĠĠĠ Ġ// Ġback Ġto Ġprevious Ġvalue ĊĠĠĠĠĠĠĠ Ġinsert UserDetails () ĊĠĠĠĠĠĠĠ Ġtest Is UserDetails Available () ĊĠĠĠĠĠĠĠ ĠtestGet UserDetails () ĊĠĠĠ Ġ} Ċ }