package Ġcom . ray w ender lich . android . bus so . ui . view . bus stop Ċ Ċ import Ġandroid . app . Activity Ċ import Ġandroid . content . Context Ċ import Ġandroid . os . Build Ċ import Ġandroid . widget . LinearLayout Ċ import Ġandroidx . recyclerview . widget . RecyclerView Ċ import Ġcom . ray w ender lich . android . bus so . R Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . ro bo lectric . Ro bo lectric Ċ import Ġorg . ro bo lectric . Ro bo lectric TestRunner Ċ import Ġorg . ro bo lectric . android . controller . Activity Controller Ċ import Ġorg . ro bo lectric . annotation . Config Ċ import Ġorg . junit . Assert . assertEquals ĊĊ Ċ @ RunWith ( Ro bo lectric TestRunner :: class ) Ċ @ Config ( sdk Ġ= Ġ[ Build . VERSION _ CODES . P ]) Ċ class ĠBus Stop ListView Binder Impl Test Ġ{ ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġbus Stop ListView Binder : ĠBus Stop ListView Binder ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġfake Bus Stop ItemSelected Listener : ĠFake Bus Stop ItemSelected Listener ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġactivity Controller : ĠActivity Controller < Activity > ĊĠĠĠ Ġprivate Ġlateinit Ġvar ĠtestData : ĠList < Bus Stop ViewModel > ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun ĠsetUp () Ġ{ ĊĠĠĠĠĠĠĠ Ġactivity Controller Ġ= ĠRo bo lectric . build Activity ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠActivity :: class . java ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ ĠtestData Ġ= Ġcreate TestData () ĊĠĠĠĠĠĠĠ Ġfake Bus Stop ItemSelected Listener Ġ= ĠFake Bus Stop ItemSelected Listener () ĊĠĠĠĠĠĠĠ Ġbus Stop ListView Binder Ġ= ĠBus Stop ListView Binder Impl ( fake Bus Stop ItemSelected Listener ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġdisplay Bus Stop List _ when Inv oked _ adapter Contains Data () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġroot View Ġ= Ġcreate Layout For Test ( activity Controller . get ()) ĊĠĠĠĠĠĠĠ Ġwith ( bus Stop ListView Binder ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġinit ( root View ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdisplay Bus Stop List ( testData ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġadapter Ġ= Ġroot View . findViewById < RecyclerView >( R . id . bus stop _ recyclerview ). adapter !! ĊĠĠĠĠĠĠĠ ĠassertEquals ( 3 , Ġadapter . item Count ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġbus Stop ItemSelected Listener _ when Bus Stop Selected _ on Bus Stop Selected Inv oked () Ġ{ ĊĠĠĠĠĠĠĠ Ġval ĠtestData Ġ= Ġcreate TestData () ĊĠĠĠĠĠĠĠ Ġval Ġactivity Ġ= Ġactivity Controller . get () ĊĠĠĠĠĠĠĠ Ġval Ġroot View Ġ= Ġcreate Layout For Test ( activity ) ĊĠĠĠĠĠĠĠ Ġactivity . set ContentView ( root View ) ĊĠĠĠĠĠĠĠ Ġactivity Controller . create (). start (). visible () ĊĠĠĠĠĠĠĠ Ġwith ( bus Stop ListView Binder ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġinit ( root View ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdisplay Bus Stop List ( testData ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġroot View . findViewById < RecyclerView >( R . id . bus stop _ recyclerview ). getChild At ( 2 ). perform Click () ĊĠĠĠĠĠĠĠ ĠassertEquals ( testData [ 2 ], Ġfake Bus Stop ItemSelected Listener . on Bus Stop Selected Inv oked With ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġclass ĠFake Bus Stop ItemSelected Listener Ġ: ĊĠĠĠĠĠĠĠ ĠBus Stop ListView Binder . Bus Stop ItemSelected Listener Ġ{ ĊĊĠĠĠĠĠĠĠ Ġvar Ġon Bus Stop Selected Inv oked With : ĠBus Stop ViewModel ? Ġ= Ġnull ĊĠĠĠĠĠĠĠ Ġvar Ġretry Inv oked Ġ= Ġfalse ĊĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġon Bus Stop Selected ( bus Stop ViewModel : ĠBus Stop ViewModel ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġon Bus Stop Selected Inv oked With Ġ= Ġbus Stop ViewModel ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġretry () Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġretry Inv oked Ġ= Ġtrue ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġcreate TestData () Ġ= ĠlistOf ( ĊĠĠĠĠĠĠĠ Ġcreate Bus Stop ViewModel For Test (" 1 "), ĊĠĠĠĠĠĠĠ Ġcreate Bus Stop ViewModel For Test (" 2 "), ĊĠĠĠĠĠĠĠ Ġcreate Bus Stop ViewModel For Test (" 3 ") ĊĠĠĠ Ġ) ĊĊĠĠĠ Ġprivate Ġfun Ġcreate Bus Stop ViewModel For Test ( id : ĠString ): ĠBus Stop ViewModel Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠBus Stop ViewModel ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" stop Id Ġ$ id ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" stop Name Ġ$ id ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" stop Direction Ġ$ id ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" stop Indicator Ġ$ id ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" stop Distance Ġ$ id " ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġcreate Layout For Test ( context : ĠContext ) Ġ= ĠLinearLayout ( context ). apply Ġ{ ĊĠĠĠĠĠĠĠ Ġadd View ( RecyclerView ( context ). apply Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġid Ġ= ĠR . id . bus stop _ recyclerview ĊĠĠĠĠĠĠĠ Ġ}) ĊĠĠĠ Ġ} Ċ } ĊĊĊĊĊĊĊĊĊĊĊĊĊĊĊĊĊĊĊĊĊĊĊĊĊĊĊĊĊĊĊĊ ĊĊĊĊ