package Ġcom . mat b ade v . dab ir va . example Ċ Ċ import Ġandroid . os . Parcelable Ċ import Ġandroidx . recyclerview . widget . RecyclerView Ċ import Ġcom . mat b ade v . dab ir va . example . ui . test . Test Activity Ċ import Ġcom . mat b ade v . dab ir va . example . ui . test . Test Activity Event Ċ import Ġcom . mat b ade v . dab ir va . example . ui . test . Test Activity ViewModel Ċ import Ġcom . mat b ade v . dab ir va . example . util . Test Decoration Ċ import Ġcom . mat b ade v . dab ir va . example . util . loop MainThread Until Idle Ċ import Ġcom . mat b ade v . dab ir va . example . util . use Activity Ċ import Ġcom . mat b ade v . dab ir va . util . decor ations Ċ import Ġcom . mat b ade v . dab ir va . util . value Ċ import Ġorg . junit . Assert . assertEquals Ċ import Ġorg . junit . Assert . assertTrue Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ Ċ class ĠRecyclerView Binding Adapters Test Ġ: ĊĠĠĠ ĠBase Instrument ed Test < Parcelable , ĠTest Activity Event , ĠTest Activity ViewModel , ĠTest Activity >( ĊĠĠĠĠĠĠĠ Ġactivity Class Ġ= ĠTest Activity :: class , ĊĠĠĠ Ġ) Ġ{ ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġre cyclerView : ĠRecyclerView ĊĊĠĠĠ Ġprivate Ġvar Ġlayout Changes Count Ġ= Ġ 0 ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun Ġinit View () Ġ{ ĊĠĠĠĠĠĠĠ Ġre cyclerView Ġ= Ġscenario . use Activity Ġ{ Ġit . findViewById ( R . id . recycler _ view ) Ġ} ĊĠĠĠĠĠĠĠ Ġre cyclerView . add On Layout ChangeListener Ġ{ Ġ_, Ġ_, Ġ_, Ġ_, Ġ_, Ġ_, Ġ_, Ġ_, Ġ_ Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġlayout Changes Count ++ ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġnull Decor ations () Ġ{ ĊĠĠĠĠĠĠĠ ĠviewModel . item Decor ations . value Ġ= Ġnull ĊĠĠĠĠĠĠĠ Ġloop MainThread Until Idle () ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( null , ĠviewModel . item Decor ations . value ) ĊĠĠĠĠĠĠĠ ĠassertTrue ( re cyclerView . decor ations . isEmpty ()) ĊĠĠĠĠĠĠĠ ĠassertEquals ( 0 , Ġlayout Changes Count ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġsingle Decoration () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġdecor ations Ġ= ĠlistOf ( Test Decoration ( 1 )) ĊĊĠĠĠĠĠĠĠ ĠviewModel . item Decor ations . value Ġ= Ġdecor ations ĊĠĠĠĠĠĠĠ Ġloop MainThread Until Idle () ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( decor ations , ĠviewModel . item Decor ations . value ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( decor ations , Ġre cyclerView . decor ations ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( 1 , Ġlayout Changes Count ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġmultiple Decor ations () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġdecor ations Ġ= ĠlistOf ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠTest Decoration ( 1 ), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠTest Decoration ( 2 ), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠTest Decoration ( 3 ), ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ ĠviewModel . item Decor ations . value Ġ= Ġdecor ations ĊĠĠĠĠĠĠĠ Ġloop MainThread Until Idle () ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( decor ations , ĠviewModel . item Decor ations . value ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( decor ations , Ġre cyclerView . decor ations ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( 1 , Ġlayout Changes Count ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġdecor ations Diff ing Equal () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġdecor ations Ġ= ĠlistOf ( Test Decoration ( 1 ), ĠTest Decoration ( 2 )) ĊĠĠĠĠĠĠĠ Ġval Ġdecor ations Flat Copy Ġ= Ġdecor ations . toList () ĊĠĠĠĠĠĠĠ Ġval Ġequal Decor ations Ġ= ĠlistOf ( Test Decoration ( 1 ), ĠTest Decoration ( 2 )) ĊĊĠĠĠĠĠĠĠ ĠviewModel . item Decor ations . value Ġ= Ġdecor ations ĊĠĠĠĠĠĠĠ Ġloop MainThread Until Idle () ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( decor ations , ĠviewModel . item Decor ations . value ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( decor ations , Ġre cyclerView . decor ations ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( 1 , Ġlayout Changes Count ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠThe Ġfollowing Ġshould Ġnot Ġtrigger Ġa Ġlayout Ġchange Ġas Ġthe Ġdecor ations Ġare Ġidentical . ĊĠĠĠĠĠĠĠ ĠviewModel . item Decor ations . value Ġ= Ġdecor ations Flat Copy ĊĠĠĠĠĠĠĠ Ġloop MainThread Until Idle () ĊĊĠĠĠĠĠĠĠ Ġ// ĠThe Ġfollowing Ġshould Ġnot Ġtrigger Ġa Ġlayout Ġchange Ġas Ġthe Ġdecor ations Ġare Ġequal . ĊĠĠĠĠĠĠĠ ĠviewModel . item Decor ations . value Ġ= Ġequal Decor ations ĊĠĠĠĠĠĠĠ Ġloop MainThread Until Idle () ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( decor ations , ĠviewModel . item Decor ations . value ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( decor ations , Ġre cyclerView . decor ations ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( 1 , Ġlayout Changes Count ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġdecor ations Diff ing NotEqual () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġinitial Decor ations Ġ= ĠlistOf ( Test Decoration ( 1 ), ĠTest Decoration ( 2 )) ĊĠĠĠĠĠĠĠ Ġval Ġupdated Decor ations Ġ= ĠlistOf ( Test Decoration ( 1 ), ĠTest Decoration ( 3 )) ĊĊĠĠĠĠĠĠĠ ĠviewModel . item Decor ations . value Ġ= Ġinitial Decor ations ĊĠĠĠĠĠĠĠ Ġloop MainThread Until Idle () ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( initial Decor ations , ĠviewModel . item Decor ations . value ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( initial Decor ations , Ġre cyclerView . decor ations ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( 1 , Ġlayout Changes Count ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠThe Ġfollowing Ġshould Ġtrigger Ġa Ġlayout Ġchange Ġas Ġthe Ġdecor ations Ġare Ġnot Ġequal . ĊĠĠĠĠĠĠĠ ĠviewModel . item Decor ations . value Ġ= Ġupdated Decor ations ĊĠĠĠĠĠĠĠ Ġloop MainThread Until Idle () ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( updated Decor ations , ĠviewModel . item Decor ations . value ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( updated Decor ations , Ġre cyclerView . decor ations ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( 2 , Ġlayout Changes Count ) ĊĠĠĠ Ġ} Ċ Ċ } Ċ