package Ġcom . hod inv . mvp demo . screens . users ĊĊ Ċ import Ġandroid . support . test . espress o . Esp ress o . on View Ċ import Ġandroid . support . test . espress o . action . View Actions .* Ċ import Ġandroid . support . test . espress o . assertion . View Assertions . does NotExist Ċ import Ġandroid . support . test . espress o . assertion . View Assertions . matches Ċ import Ġandroid . support . test . espress o . contrib . RecyclerView Actions Ċ import Ġandroid . support . test . espress o . matcher . View Matchers .* Ċ import Ġandroid . support . test . filters . Large Test Ċ import Ġandroid . support . test . rule . Activity Test Rule Ċ import Ġandroid . support . test . runner . Android JUnit 4 Ċ import Ġcom . hod inv . mvp demo . R Ċ import Ġcom . hod inv . mvp demo . model . User Ċ import Ġorg . hamcrest . Matchers . all Of Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . mockito . Mockito ĊĊ Ċ /** Ċ Ġ* ĠInstrument ed Ġtest , Ġwhich Ġwill Ġexecute Ġon Ġan ĠAndroid Ġdevice . Ċ Ġ* Ċ Ġ* ĠSee Ġ[ testing Ġdocumentation ]( http :// d . android . com / tools / testing ). Ċ Ġ*/ Ċ @ RunWith ( Android JUnit 4 :: class ) Ċ @ Large Test Ċ class ĠUsers View Test Ġ{ ĊĊĠĠĠ Ġval Ġpresenter Ġ= ĠMockito . mock ( Users Contract . Presenter :: class . java ) ĊĠĠĠ Ġval Ġlist 1 Ġ= ĠlistOf ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠUser ( 1 , Ġ" User 1 ", Ġ" email 1 @ mail . com ", Ġ" 1 1 1 1 1 ", Ġ' A '), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠUser ( 2 , Ġ" User 2 ", Ġ" email 2 @ mail . com ", Ġ" 2 2 2 2 2 ", Ġ' B '), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠUser ( 3 , Ġ" User 3 ", Ġ" email 3 @ mail . com ", Ġ" 3 3 3 3 3 ", Ġ' C ') ĊĠĠĠ Ġ) ĊĠĠĠ Ġval Ġlist 2 Ġ= ĠlistOf ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠUser ( 4 , Ġ" User 4 ", Ġ" email 4 @ mail . com ", Ġ" 4 4 4 4 4 ", Ġ' A '), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠUser ( 3 , Ġ" User 3 ", Ġ" email 3 @ mail . com ", Ġ" 3 3 3 3 3 ", Ġ' C ') ĊĠĠĠ Ġ) ĊĠĠĠ Ġval Ġlist 3 Ġ= ĠlistOf ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠUser ( 1 , Ġ" User 1 ", Ġ" email 1 @ mail . com ", Ġ" 1 1 1 1 1 ", Ġ' A ') ĊĠĠĠ Ġ) ĊĊĊĠĠĠ Ġ@ Rule ĊĠĠĠ Ġ@ Jvm Field ĊĠĠĠ Ġvar Ġm Activity Rule Ġ= Ġobject Ġ: ĠActivity Test Rule < Users Activity >( Users Activity :: class . java ) Ġ{ ĊĊĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġafter Activity La unched () Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġsuper . after Activity La unched () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġactivity . presenter Ġ= Ġpresenter ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġcheck New On Fab () Ġ{ ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . add New User )). perform ( click ()) ĊĠĠĠĠĠĠĠ ĠMockito . verify ( presenter )?. add New User () ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Users Are Visible () Ġ{ ĊĠĠĠĠĠĠĠ Ġm Activity Rule . activity . set Users ( list 1 ) ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . list )). check ( matches ( is Displayed ())); ĊĠĠĠĠĠĠĠ ĠThread . sleep ( 5 0 0 0 ) ĊĠĠĠĠĠĠĠ Ġfor Ġ( pos Ġin Ġ 0 .. list 1 . size Ġ- Ġ 1 ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġon View ( with Text ( list 1 [ pos ]. name )). check ( matches ( is Displayed ())); ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Users Changed () Ġ{ ĊĠĠĠĠĠĠĠ Ġm Activity Rule . activity . set Users ( list 1 ) ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . list )). check ( matches ( is Displayed ())); ĊĠĠĠĠĠĠĠ ĠThread . sleep ( 5 0 0 0 ) ĊĠĠĠĠĠĠĠ Ġm Activity Rule . activity . set Users ( list 2 ) ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . list )). check ( matches ( is Displayed ())); ĊĠĠĠĠĠĠĠ ĠThread . sleep ( 5 0 0 0 ) ĊĠĠĠĠĠĠĠ Ġfor Ġ( pos Ġin Ġ 0 .. list 2 . size Ġ- Ġ 1 ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġon View ( with Text ( list 2 [ pos ]. name )). check ( matches ( is Displayed ())); ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġm Activity Rule . activity . set Users ( list 3 ) ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . list )). check ( matches ( is Displayed ())); ĊĠĠĠĠĠĠĠ ĠThread . sleep ( 5 0 0 0 ) ĊĠĠĠĠĠĠĠ Ġfor Ġ( pos Ġin Ġ 0 .. list 2 . size Ġ- Ġ 1 ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġon View ( with Text ( list 2 [ pos ]. name )). check ( does NotExist ()); ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Users Click Go es To Detail () Ġ{ ĊĠĠĠĠĠĠĠ Ġm Activity Rule . activity . set Users ( list 1 ) ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . list )). check ( matches ( is Displayed ())); ĊĠĠĠĠĠĠĠ ĠThread . sleep ( 5 0 0 0 ) ĊĠĠĠĠĠĠĠ Ġon View ( all Of ( with Id ( R . id . name ), Ġwith Text ( list 1 [ 0 ]. name ))). check ( matches ( is Displayed ())) ĊĠĠĠĠĠĠĠ Ġon View ( all Of ( with Id ( R . id . name ), Ġwith Text ( list 1 [ 0 ]. name ))). perform ( click ()) ĊĠĠĠĠĠĠĠ ĠMockito . verify ( presenter )?. open User Detail ( list 1 [ 0 ]) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Swipe Remov es User () Ġ{ ĊĠĠĠĠĠĠĠ Ġm Activity Rule . activity . set Users ( list 1 ) ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . list )). check ( matches ( is Displayed ())); ĊĠĠĠĠĠĠĠ ĠThread . sleep ( 5 0 0 0 ) ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . list )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. perform ( RecyclerView Actions . action On Item At Position < User ViewHolder >( 0 , Ġswipe Left ())); ĊĠĠĠĠĠĠĠ ĠMockito . verify ( presenter )?. delete User ( list 1 [ 0 ]) ĊĠĠĠ Ġ} Ċ Ċ } Ċ