package Ġorg . od k . collect . android . external Ċ Ċ import Ġandroid . app . Activity Ċ import Ġandroid . app . Application Ċ import Ġandroid . content . Intent Ċ import Ġandroid . net . Uri Ċ import Ġandroidx . test . core . app . Activity Scenario Ċ import Ġandroidx . test . core . app . Application Provider Ċ import Ġandroidx . test . espress o . Esp ress o . on View Ċ import Ġandroidx . test . espress o . action . View Actions . click Ċ import Ġandroidx . test . espress o . assertion . View Assertions . matches Ċ import Ġandroidx . test . espress o . intent . Intent s Ċ import Ġandroidx . test . espress o . intent . matcher . Intent Matchers . has Component Ċ import Ġandroidx . test . espress o . intent . matcher . Intent Matchers . has Data Ċ import Ġandroidx . test . espress o . intent . matcher . Intent Matchers . has Extra Ċ import Ġandroidx . test . espress o . matcher . Root Matchers . is Dialog Ċ import Ġandroidx . test . espress o . matcher . View Matchers . is Displayed Ċ import Ġandroidx . test . espress o . matcher . View Matchers . with Id Ċ import Ġandroidx . test . espress o . matcher . View Matchers . with Text Ċ import Ġandroidx . test . ext . junit . runners . Android JUnit 4 Ċ import Ġcom . google . gson . Gson Ċ import Ġorg . hamcrest . Matcher Assert . assertThat Ċ import Ġorg . hamcrest . Matchers .` is ` Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . mockito . kotlin . mock Ċ import Ġorg . mockito . kotlin . wh enever Ċ import Ġorg . od k . collect . android . R Ċ import Ġorg . od k . collect . android . activities . Form Entry Activity Ċ import Ġorg . od k . collect . android . injection . config . App Dependency Module Ċ import Ġorg . od k . collect . android . preferences . source . Settings Provider Ċ import Ġorg . od k . collect . android . projects . Current Project Provider Ċ import Ġorg . od k . collect . android . support . Collect Helpers Ċ import Ġorg . od k . collect . projects . In Mem Projects Repository Ċ import Ġorg . od k . collect . projects . Project Ċ import Ġorg . od k . collect . projects . Projects Repository Ċ import Ġorg . od k . collect . shared . strings . UUID Generator Ċ import Ġorg . od k . collect . test shared . Re corded Intent s Rule Ċ Ċ @ RunWith ( Android JUnit 4 :: class ) Ċ class ĠForm Uri Activity Test Ġ{ ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġprojects Repository : ĠProjects Repository ĊĠĠĠ Ġprivate Ġval Ġcurrent Project Provider Ġ= Ġmock < Current Project Provider >() ĊĠĠĠ Ġprivate Ġval Ġcontext Ġ= ĠApplication Provider . getApplicationContext < Application >() ĊĠĠĠ Ġprivate Ġval Ġfirst Project Ġ= ĠProject . DEMO _ PROJECT ĊĠĠĠ Ġprivate Ġval Ġsecond Project Ġ= ĠProject . Saved (" 1 2 3 ", Ġ" Second Ġproject ", Ġ" S ", Ġ"# cccccc ") ĊĊĠĠĠ Ġ@ get : Rule ĊĠĠĠ Ġval Ġactivity Rule Ġ= ĠRe corded Intent s Rule () ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun Ġsetup () Ġ{ ĊĠĠĠĠĠĠĠ Ġprojects Repository Ġ= ĠIn Mem Projects Repository () ĊĊĠĠĠĠĠĠĠ ĠCollect Helpers . override App Dependency Module ( object Ġ: ĠApp Dependency Module () Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġfun Ġprovides Projects Repository ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġuuid Generator : ĠUUID Generator ?, ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġgson : ĠGson ?, ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġsettings Provider : ĠSettings Provider ? ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ): ĠProjects Repository Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġreturn Ġprojects Repository ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġfun Ġprovides Current Project Provider ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġsettings Provider : ĠSettings Provider ?, ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġprojects Repository : ĠProjects Repository ? ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ): ĠCurrent Project Provider Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġreturn Ġcurrent Project Provider ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ}) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` When Ġthere Ġare Ġno Ġprojects Ġthen Ġdisplay Ġalert Ġdialog `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġscenario Ġ= ĠActivity Scenario . launch ( Form Uri Activity :: class . java ) ĊĠĠĠĠĠĠĠ Ġon View ( with Text ( R . string . app _ not _ configured )). in Root ( is Dialog ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. check ( matches ( is Displayed ())) ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( android . R . id . button 1 )). perform ( click ()) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( scenario . result . result Code , Ġ` is `( Activity . RESULT _ C ANCE LED )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` When Ġthere Ġis Ġproject Ġid Ġspecified Ġin Ġuri Ġand Ġit Ġdoes Ġnot Ġmatch Ġcurrent Ġproject Ġid Ġthen Ġdisplay Ġalert Ġdialog `() Ġ{ ĊĠĠĠĠĠĠĠ Ġsave Test Projects () ĊĊĠĠĠĠĠĠĠ Ġval Ġscenario Ġ= ĠActivity Scenario . launch < Form Uri Activity >( get Intent ( second Project . uuid )) ĊĊĠĠĠĠĠĠĠ Ġon View ( with Text ( R . string . wrong _ project _ selected _ for _ form )). in Root ( is Dialog ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. check ( matches ( is Displayed ())) ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( android . R . id . button 1 )). perform ( click ()) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( scenario . result . result Code , Ġ` is `( Activity . RESULT _ C ANCE LED )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` When Ġthere Ġis Ġproject Ġid Ġspecified Ġin Ġuri Ġand Ġit Ġmatches Ġcurrent Ġproject Ġid Ġthen Ġstart Ġform Ġfilling `() Ġ{ ĊĠĠĠĠĠĠĠ Ġsave Test Projects () ĊĊĠĠĠĠĠĠĠ ĠActivity Scenario . launch < Form Uri Activity >( get Intent ( first Project . uuid )) ĊĊĠĠĠĠĠĠĠ ĠInt ents . int ended ( has Component ( Form Entry Activity :: class . java . name )) ĊĠĠĠĠĠĠĠ ĠInt ents . int ended ( has Data ( Forms Contract . get Uri ( first Project . uuid , Ġ 1 ))) ĊĠĠĠĠĠĠĠ ĠInt ents . int ended ( has Extra (" KEY _ 1 ", Ġ" Text ")) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` When Ġthere Ġis Ġno Ġproject Ġid Ġspecified Ġin Ġuri Ġand Ġfirst Ġavailable Ġproject Ġid Ġdoes Ġnot Ġmatch Ġcurrent Ġproject Ġid Ġthen Ġdisplay Ġalert Ġdialog `() Ġ{ ĊĠĠĠĠĠĠĠ Ġsave Test Projects () ĊĊĠĠĠĠĠĠĠ Ġwhenever ( current Project Provider . getCurrent Project ()). thenReturn ( second Project ) ĊĊĠĠĠĠĠĠĠ Ġval Ġscenario Ġ= ĠActivity Scenario . launch < Form Uri Activity >( get Intent ()) ĊĊĠĠĠĠĠĠĠ Ġon View ( with Text ( R . string . wrong _ project _ selected _ for _ form )). in Root ( is Dialog ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. check ( matches ( is Displayed ())) ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( android . R . id . button 1 )). perform ( click ()) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( scenario . result . result Code , Ġ` is `( Activity . RESULT _ C ANCE LED )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` When Ġthere Ġis Ġno Ġproject Ġid Ġspecified Ġin Ġuri Ġand Ġfirst Ġavailable Ġproject Ġid Ġmatches Ġcurrent Ġproject Ġid Ġthen Ġstart Ġform Ġfilling `() Ġ{ ĊĠĠĠĠĠĠĠ Ġsave Test Projects () ĊĊĠĠĠĠĠĠĠ ĠActivity Scenario . launch < Form Uri Activity >( get Intent ()) ĊĊĠĠĠĠĠĠĠ ĠInt ents . int ended ( has Component ( Form Entry Activity :: class . java . name )) ĊĠĠĠĠĠĠĠ Ġval Ġuri Ġ= ĠForms Contract . get Uri ("", Ġ 1 ) ĊĠĠĠĠĠĠĠ ĠInt ents . int ended ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġhas Data ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠUri . Builder () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. scheme ( uri . scheme ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. authority ( uri . authority ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. path ( uri . path ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. query ( null ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. build () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ ĠInt ents . int ended ( has Extra (" KEY _ 1 ", Ġ" Text ")) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ// ĠTODO : ĠReplace Ġthe Ġexplicit ĠForm Uri Activity Ġintent Ġwith Ġan Ġimplicit Ġone ĠIntent . ACTION _ EDIT Ġonce Ġit 's Ġpossible Ġhttps :// github . com / android / android - test / issues / 4 9 6 ĊĠĠĠ Ġprivate Ġfun Ġget Intent ( projectId : ĠString ? Ġ= Ġnull ) Ġ= ĊĠĠĠĠĠĠĠ ĠIntent ( context , ĠForm Uri Activity :: class . java ). apply Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdata Ġ= Ġif Ġ( projectId Ġ== Ġnull ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġuri Ġ= ĠForms Contract . get Uri ("", Ġ 1 ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠUri . Builder () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. scheme ( uri . scheme ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. authority ( uri . authority ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. path ( uri . path ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. query ( null ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. build () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠForms Contract . get Uri ( projectId , Ġ 1 ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġput Extra (" KEY _ 1 ", Ġ" Text ") ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġsave Test Projects () Ġ{ ĊĠĠĠĠĠĠĠ Ġprojects Repository . save ( first Project ) ĊĠĠĠĠĠĠĠ Ġprojects Repository . save ( second Project ) ĊĊĠĠĠĠĠĠĠ Ġwhenever ( current Project Provider . getCurrent Project ()). thenReturn ( first Project ) ĊĠĠĠ Ġ} Ċ } Ċ