package Ġcom . r ab ind ra . app . weather app . dao Ċ Ċ import Ġandroid . os . Build Ċ import Ġandroidx . arch . core . executor . testing . Instant Task Executor Rule Ċ import Ġandroidx . room . Room Ċ import Ġandroidx . test . core . app . Application Provider Ċ import Ġandroidx . test . ext . junit . runners . Android JUnit 4 Ċ import Ġcom . r ab ind ra . app . weather app . db . Weather Database Ċ import Ġcom . r ab ind ra . app . weather app . db . dao . Current Weather Dao Ċ import Ġcom . r ab ind ra . app . weather app . util . generate Current Weather Entity Ċ import Ġcom . r ab ind ra . app . weather app . util . get Or Await Value Ċ import Ġcom . google . common . truth . Truth Ċ 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 . annotation . Config Ċ Ċ /** Ċ Ġ* ĠCreated Ġby ĠF ur kan Ġon Ġ 2 0 1 9 - 1 1 - 2 2 Ċ Ġ*/ Ċ Ċ @ Config ( sdk Ġ= Ġ[ Build . VERSION _ CODES . P ]) Ċ @ RunWith ( Android JUnit 4 :: class ) Ċ class ĠCurrent Weather Dao Test Ġ{ ĊĊĠĠĠ Ġ@ Rule ĊĠĠĠ Ġ@ Jvm Field ĊĠĠĠ Ġval Ġinstant Executor Rule Ġ= ĠInstant Task Executor Rule () ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġweather Database : ĠWeather Database ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġcurrent Weather Dao : ĠCurrent Weather Dao ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun ĠsetUp () Ġ{ ĊĠĠĠĠĠĠĠ Ġweather Database Ġ= ĠRoom . in Memory Database Builder ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠApplication Provider . getApplicationContext (), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠWeather Database :: class . java ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. allow MainThread Queries () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. build () ĊĊĠĠĠĠĠĠĠ Ġcurrent Weather Dao Ġ= Ġweather Database . current Weather Dao () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ After ĊĠĠĠ Ġfun Ġclose Database () Ġ{ ĊĠĠĠĠĠĠĠ Ġweather Database . close () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` empty Ġdatabase Ġcount Ġmust Ġbe Ġzero `() Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠWhen ĊĠĠĠĠĠĠĠ Ġval Ġcount Ġ= Ġcurrent Weather Dao . getCount () ĊĊĠĠĠĠĠĠĠ Ġ// ĠThen ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( count ). isEqualTo ( 0 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` insert Ġone Ġentity Ġand Ġcount Ġmust Ġbe Ġone `() Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠWhen ĊĠĠĠĠĠĠĠ Ġcurrent Weather Dao . insert Current Weather ( generate Current Weather Entity (" I stan bul ", Ġ 1 )) ĊĊĠĠĠĠĠĠĠ Ġ// ĠThen ĊĠĠĠĠĠĠĠ Ġval Ġcount Ġ= Ġcurrent Weather Dao . getCount () ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( count ). isEqualTo ( 1 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` insert Ġone Ġentity Ġand Ġtest Ġget Ġfunction `() Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠWhen ĊĠĠĠĠĠĠĠ Ġcurrent Weather Dao . insert Current Weather ( generate Current Weather Entity (" I stan bul ", Ġ 1 )) ĊĊĠĠĠĠĠĠĠ Ġ// ĠThen ĊĠĠĠĠĠĠĠ Ġval Ġentity Ġ= Ġcurrent Weather Dao . getCurrent Weather (). get Or Await Value () ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( entity . name ). isEqualTo (" I stan bul ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` delete Ġand Ġinsert Ġa Ġcurrent Ġweather `() Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠWhen ĊĠĠĠĠĠĠĠ Ġcurrent Weather Dao . delete And Insert ( generate Current Weather Entity (" I stan bul ", Ġ 1 )) ĊĠĠĠĠĠĠĠ Ġval Ġcount Ġ= Ġcurrent Weather Dao . getCount () ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( count ). isEqualTo ( 1 ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠThen ĊĠĠĠĠĠĠĠ Ġcurrent Weather Dao . delete And Insert ( generate Current Weather Entity (" Ad ana ", Ġ 2 )) ĊĠĠĠĠĠĠĠ Ġval Ġnew Count Ġ= Ġcurrent Weather Dao . getCount () ĊĠĠĠĠĠĠĠ Ġval Ġvalue Ġ= Ġcurrent Weather Dao . getCurrent Weather (). get Or Await Value () ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( new Count ). isEqualTo ( 1 ) ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( value . name ). isEqualTo (" Ad ana ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` first Ġinsert Ġa Ġcurrent Ġweather Ġthen Ġdelete Ġand Ġcount Ġmust Ġbe Ġzero `() Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠWhen ĊĠĠĠĠĠĠĠ Ġcurrent Weather Dao . delete And Insert ( generate Current Weather Entity (" I stan bul ", Ġ 1 )) ĊĠĠĠĠĠĠĠ Ġval Ġcount Ġ= Ġcurrent Weather Dao . getCount () ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( count ). isEqualTo ( 1 ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠThen ĊĠĠĠĠĠĠĠ Ġcurrent Weather Dao . delete Current Weather () ĊĠĠĠĠĠĠĠ Ġval Ġnew Count Ġ= Ġcurrent Weather Dao . getCount () ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( new Count ). isEqualTo ( 0 ) ĊĠĠĠ Ġ} Ċ } Ċ