package Ġcom . example . android . architecture . blueprint s . todo app . task detail Ċ Ċ import Ġandroidx . fragment . app . testing . launch Fragment In Container Ċ import Ġandroidx . test . espress o . Esp ress o . on View Ċ import Ġandroidx . test . espress o . assertion . View Assertions . matches Ċ import Ġandroidx . test . espress o . matcher . View Matchers .* Ċ import Ġandroidx . test . ext . junit . runners . Android JUnit 4 Ċ import Ġandroidx . test . filters . Medium Test Ċ import Ġcom . example . android . architecture . blueprint s . todo app . Main Coroutine Rule Ċ import Ġcom . example . android . architecture . blueprint s . todo app . R Ċ import Ġcom . example . android . architecture . blueprint s . todo app . Service Locator Ċ import Ġcom . example . android . architecture . blueprint s . todo app . data . Task Ċ import Ġcom . example . android . architecture . blueprint s . todo app . data . source . IT ask s Repository Ċ import Ġcom . example . android . architecture . blueprint s . todo app . source . Fake Test Repository Ċ import Ġkotlinx . coroutines . Experimental Cor outines Api Ċ import Ġkotlinx . coroutines . test . run Blocking Test Ċ import Ġorg . hamcrest . core . IsNot . not Ċ import Ġorg . junit . After Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ Ċ @ Experimental Cor outines Api Ċ @ RunWith ( Android JUnit 4 :: class ) Ċ @ Medium Test Ċ class ĠTask Detail Fragment Test Ġ{ ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġrepository Ġ: ĠI Tasks Repository ĊĊĠĠĠ Ġ@ get : Rule ĊĠĠĠ Ġvar Ġmain Coroutine Rule Ġ= ĠMain Coroutine Rule () ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun Ġinit Repository () Ġ{ ĊĠĠĠĠĠĠĠ Ġrepository Ġ= ĠFake Test Repository () ĊĠĠĠĠĠĠĠ ĠService Locator . tasks Repository Ġ= Ġrepository ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ After ĊĠĠĠ Ġfun Ġclean Up () Ġ= Ġmain Coroutine Rule . run Blocking Test Ġ{ ĊĠĠĠĠĠĠĠ ĠService Locator . reset Repository () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġactive Task Details _ Displayed In Ui () Ġ= Ġmain Coroutine Rule . run Blocking Test Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠG IV EN Ġ- ĠAdd Ġactive Ġ( in complete ) Ġtask Ġto Ġthe ĠDB ĊĠĠĠĠĠĠĠ Ġval Ġactive Task Ġ= ĠTask (" Active ĠTask ", Ġ" Active ĠTask ĠDescription ", Ġfalse ) ĊĠĠĠĠĠĠĠ Ġrepository . save Task ( active Task ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠWHEN Ġ- ĠDetails Ġfragment Ġlaunched Ġto Ġdisplay Ġtask ĊĠĠĠĠĠĠĠ Ġval Ġbundle Ġ= ĠTask Detail Fragment Args ( active Task . id ). to Bundle () ĊĠĠĠĠĠĠĠ Ġlaunch Fragment In Container < Task Detail Fragment >( bundle , ĠR . style . App Theme ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠTHEN Ġ- ĠTask Ġdetails Ġare Ġdisplayed Ġon Ġthe Ġscreen ĊĠĠĠĠĠĠĠ Ġ// Ġmake Ġsure Ġthat Ġthe Ġtitle / description Ġare Ġboth Ġshown Ġand Ġcorrect ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . task _ detail _ title _ text )). check ( matches ( is Displayed ())) ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . task _ detail _ title _ text )). check ( matches ( with Text (" Active ĠTask "))) ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . task _ detail _ description _ text )). check ( matches ( is Displayed ())) ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . task _ detail _ description _ text )). check ( matches ( with Text (" Active ĠTask ĠDescription "))) ĊĠĠĠĠĠĠĠ Ġ// Ġand Ġmake Ġsure Ġthe Ġ" active " Ġcheckbox Ġis Ġshown Ġunchecked ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . task _ detail _ complete _ checkbox )). check ( matches ( is Displayed ())) ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . task _ detail _ complete _ checkbox )). check ( matches ( not ( isChecked ()))) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġcompleted Task Details _ Displayed In Ui () Ġ= Ġmain Coroutine Rule . run Blocking Test Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠG IV EN Ġ- ĠAdd Ġcompleted Ġtask Ġto Ġthe ĠDB ĊĠĠĠĠĠĠĠ Ġval Ġcompleted Task Ġ= ĠTask (" Completed ĠTask ", Ġ" Completed ĠTask ĠDescription ", Ġtrue ) ĊĠĠĠĠĠĠĠ Ġrepository . save Task ( completed Task ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠWHEN Ġ- ĠDetails Ġfragment Ġlaunched Ġto Ġdisplay Ġtask ĊĠĠĠĠĠĠĠ Ġval Ġbundle Ġ= ĠTask Detail Fragment Args ( completed Task . id ). to Bundle () ĊĠĠĠĠĠĠĠ Ġlaunch Fragment In Container < Task Detail Fragment >( bundle , ĠR . style . App Theme ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠTHEN Ġ- ĠTask Ġdetails Ġare Ġdisplayed Ġon Ġthe Ġscreen ĊĠĠĠĠĠĠĠ Ġ// Ġmake Ġsure Ġthat Ġthe Ġtitle / description Ġare Ġboth Ġshown Ġand Ġcorrect ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . task _ detail _ title _ text )). check ( matches ( is Displayed ())) ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . task _ detail _ title _ text )). check ( matches ( with Text (" Completed ĠTask "))) ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . task _ detail _ description _ text )). check ( matches ( is Displayed ())) ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . task _ detail _ description _ text )). check ( matches ( with Text (" Completed ĠTask ĠDescription "))) ĊĠĠĠĠĠĠĠ Ġ// Ġand Ġmake Ġsure Ġthe Ġ" active " Ġcheckbox Ġis Ġshown Ġunchecked ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . task _ detail _ complete _ checkbox )). check ( matches ( is Displayed ())) ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . task _ detail _ complete _ checkbox )). check ( matches ( isChecked ())) ĊĠĠĠ Ġ} Ċ }