package Ġcom . code arms . ma o q iq i . app . task detail Ċ Ċ import Ġandroid . content . Intent Ċ import Ġandroidx . test . espress o . Esp ress o . on View Ċ import Ġandroidx . test . espress o . Id ling Registry Ċ import Ġandroidx . test . espress o . assertion . View Assertions Ċ import Ġandroidx . test . espress o . matcher . View Matchers Ċ import Ġandroidx . test . rule . Activity Test Rule Ċ import Ġandroidx . test . ext . junit . runners . Android JUnit 4 Ċ import Ġcom . code arms . ma o q iq i . app . R Ċ import Ġcom . code arms . ma o q iq i . app . data . Task Bean Ċ import Ġcom . code arms . ma o q iq i . app . data . source . Task Repository Ċ import Ġcom . code arms . ma o q iq i . app . data . source . remote . Task Remote DataSource Ċ import Ġcom . code arms . ma o q iq i . app . tasks . Tasks Activity Ċ import Ġcom . code arms . ma o q iq i . app . utils . Esp ress o Id ling Resource Ċ import Ġcom . code arms . ma o q iq i . app . utils . TestUtils Ċ import Ġorg . hamcrest . Matchers Ċ import Ġorg . junit . After Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ Ċ /** Ċ Ġ* ĠTests Ġfor Ġthe Ġtask Ġdetail Ġscreen . Ċ Ġ* ĠAuthor : Ġf eng qi . ma o . m arch @ gmail . com Ċ Ġ* ĠDate : Ġ 2 0 1 9 / 3 / 1 5 Ġ 1 0 : 0 0 Ċ Ġ*/ Ċ @ RunWith ( Android JUnit 4 :: class ) Ċ class ĠTask Detail Screen Test Ġ{ ĊĊĠĠĠ Ġ/** ĊĠĠĠĠ Ġ* Ġ[ Activity Test Rule ] Ġis Ġa ĠJ Unit Ġ[@ Rule ][ Rule ] Ġto Ġlaunch Ġyour Ġactivity Ġunder Ġtest . ĊĠĠĠĠ Ġ*/ ĊĠĠĠ Ġ@ get : Rule ĊĠĠĠ Ġvar Ġtask Detail Activity Test Rule Ġ= ĠActivity Test Rule ( Task Detail Activity :: class . java , Ġtrue , Ġfalse ) ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun Ġregister Id ling Resource () Ġ{ ĊĠĠĠĠĠĠĠ ĠId ling Registry . getInstance (). register ( Esp ress o Id ling Resource . count ing Id ling Resource ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ After ĊĠĠĠ Ġfun Ġunregister Id ling Resource () Ġ{ ĊĠĠĠĠĠĠĠ ĠId ling Registry . getInstance (). unregister ( Esp ress o Id ling Resource . count ing Id ling Resource ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġload Active Task () Ġ{ ĊĠĠĠĠĠĠĠ ĠstartActivity ( ACTIVE _ TASK ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠCheck Ġthat Ġthe Ġtask Ġtitle Ġand Ġdescription Ġare Ġdisplayed ĊĠĠĠĠĠĠĠ Ġon View ( View Matchers . with Id ( R . id . tv Title )). check ( View Assertions . matches ( View Matchers . with Text ( TITLE ))) ĊĠĠĠĠĠĠĠ Ġon View ( View Matchers . with Id ( R . id . tv Description )). check ( View Assertions . matches ( View Matchers . with Text ( DESCRIPTION ))) ĊĠĠĠĠĠĠĠ Ġon View ( View Matchers . with Id ( R . id . cb Complete )). check ( View Assertions . matches ( Matchers . not ( View Matchers . isChecked ()))) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġload Completed Task () Ġ{ ĊĠĠĠĠĠĠĠ ĠstartActivity ( COMPLETED _ TASK ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠCheck Ġthat Ġthe Ġtask Ġtitle Ġand Ġdescription Ġare Ġdisplayed ĊĠĠĠĠĠĠĠ Ġon View ( View Matchers . with Id ( R . id . tv Title )). check ( View Assertions . matches ( View Matchers . with Text ( TITLE ))) ĊĠĠĠĠĠĠĠ Ġon View ( View Matchers . with Id ( R . id . tv Description )). check ( View Assertions . matches ( View Matchers . with Text ( DESCRIPTION ))) ĊĠĠĠĠĠĠĠ Ġon View ( View Matchers . with Id ( R . id . cb Complete )). check ( View Assertions . matches ( View Matchers . isChecked ())) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġrotation () Ġ{ ĊĠĠĠĠĠĠĠ Ġload Active Task () ĊĊĠĠĠĠĠĠĠ Ġ// ĠCheck Ġdelete Ġmenu Ġitem Ġis Ġdisplayed Ġand Ġis Ġunique ĊĠĠĠĠĠĠĠ Ġon View ( View Matchers . with Id ( R . id . menu _ delete )). check ( View Assertions . matches ( View Matchers . is Displayed ())) ĊĊĠĠĠĠĠĠĠ Ġ// ĠRotate Ġactivity ĊĠĠĠĠĠĠĠ ĠTestUtils . rotate Orientation ( task Detail Activity Test Rule . activity ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠCheck Ġthat Ġthe Ġtask Ġis Ġshown ĊĠĠĠĠĠĠĠ Ġon View ( View Matchers . with Id ( R . id . tv Title )). check ( View Assertions . matches ( View Matchers . with Text ( TITLE ))) ĊĠĠĠĠĠĠĠ Ġon View ( View Matchers . with Id ( R . id . tv Description )). check ( View Assertions . matches ( View Matchers . with Text ( DESCRIPTION ))) ĊĊĠĠĠĠĠĠĠ Ġ// ĠCheck Ġdelete Ġmenu Ġitem Ġis Ġdisplayed Ġand Ġis Ġunique ĊĠĠĠĠĠĠĠ Ġon View ( View Matchers . with Id ( R . id . menu _ delete )). check ( View Assertions . matches ( View Matchers . is Displayed ())) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun ĠstartActivity ( task Bean : ĠTask Bean ) Ġ{ ĊĠĠĠĠĠĠĠ ĠTask Repository . destroy Instance () ĊĠĠĠĠĠĠĠ ĠTask Remote DataSource . getInstance (). add Task ( task Bean ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠL az ily Ġstart Ġthe ĠActivity Ġfrom Ġthe ĠActivity Test Rule Ġthis Ġtime Ġto Ġinject Ġthe Ġstart ĠIntent ĊĠĠĠĠĠĠĠ Ġval Ġstart Intent Ġ= ĠIntent () ĊĠĠĠĠĠĠĠ Ġstart Intent . putExtra ( Tasks Activity . EXTRA _ TASK _ ID , Ġtask Bean . id ) ĊĠĠĠĠĠĠĠ Ġtask Detail Activity Test Rule . launch Activity ( start Intent ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġprivate Ġconst Ġval ĠTITLE Ġ= Ġ" TITLE " ĊĠĠĠĠĠĠĠ Ġprivate Ġconst Ġval ĠDESCRIPTION Ġ= Ġ" DESCRIPTION " ĊĊĠĠĠĠĠĠĠ Ġprivate Ġval ĠACT IVE _ TASK Ġ= ĠTask Bean ( TITLE , ĠDESCRIPTION , Ġfalse ) ĊĠĠĠĠĠĠĠ Ġprivate Ġval ĠCOMP LETED _ TASK Ġ= ĠTask Bean ( TITLE , ĠDESCRIPTION , Ġtrue ) ĊĠĠĠ Ġ} Ċ }