package Ġcom . github . a ak ira . expand able layout . uit est Ċ Ċ import Ġandroid . app . Activity Ċ import Ġandroid . support . test . Instrumentation Registry Ċ import Ġandroid . support . test . espress o . Esp ress o Ċ import Ġandroid . support . test . espress o . Esp ress o . on View Ċ import Ġandroid . support . test . espress o . Ui Controller Ċ import Ġandroid . support . test . espress o . View Action Ċ import Ġandroid . support . test . espress o . action . View Actions Ċ 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 . is Displayed Ċ import Ġandroid . support . test . espress o . matcher . View Matchers . with Id Ċ import Ġandroid . support . test . runner . Android JUnit 4 Ċ import Ġandroid . support . v 7 . widget . RecyclerView Ċ import Ġandroid . test . Activity Instrumentation TestCase 2 Ċ import Ġandroid . view . View Ċ import Ġcom . github . a ak ira . expand able layout . uit est . Expand able RecyclerView Activity . RecyclerView Adapter . Expand able ViewHolder Ċ import Ġcom . github . a ak ira . expand able layout . uit est . utils . Elapsed Id L ing Resource Ċ import Ġorg . hamcrest . Description Ċ import Ġorg . hamcrest . Matcher Assert . assertThat Ċ import Ġorg . hamcrest . Type Safe Matcher Ċ import Ġorg . hamcrest . core . IsNull . notNull Value Ċ import Ġorg . junit . After Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . hamcrest . Core Matchers .` is ` Ġas Ġ_ is Ċ Ċ @ RunWith ( Android JUnit 4 :: class ) Ċ class ĠExpand able RecyclerView Activity Test Ġ: ĠActivity Instrumentation TestCase 2 < Expand able RecyclerView Activity > Ċ ( Expand able RecyclerView Activity :: class . java ) Ġ{ ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġ@ Throws ( Exception :: class ) ĊĠĠĠ Ġpublic Ġoverride Ġfun ĠsetUp () Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . setUp () ĊĠĠĠĠĠĠĠ Ġinject Instrumentation ( Instrumentation Registry . get Instrumentation ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ After ĊĠĠĠ Ġ@ Throws ( Exception :: class ) ĊĠĠĠ Ġpublic Ġoverride Ġfun ĠtearDown () Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . te ar Down () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Expand able RecyclerView Activity () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġactivity Ġ= Ġactivity ĊĠĠĠĠĠĠĠ Ġval Ġinstrument ation Ġ= Ġinstrument ation ĊĊĠĠĠĠĠĠĠ Ġ// Ġcheck Ġactivity ĊĠĠĠĠĠĠĠ ĠassertThat < Activity >( activity , Ġnot NullValue ()) ĊĠĠĠĠĠĠĠ ĠassertThat ( instrumentation , Ġnot NullValue ()) ĊĊĠĠĠĠĠĠĠ Ġ// Ġcount Ġitems Ġin Ġre cycler Ġview Ġfor Ġtest ĊĠĠĠĠĠĠĠ Ġval Ġre cyclerView Ġ= Ġactivity . findViewById ( R . id . re cyclerView ) Ġas ĠRecyclerView ĊĠĠĠĠĠĠĠ ĠassertThat ( re cyclerView . adapter . item Count , Ġ_ is ( 1 0 1 )) ĊĊĠĠĠĠĠĠĠ Ġval Ġduration Ġ= ĠExpand able RecyclerView Activity . DURATION Ġ+ Ġ 1 0 0 // Ġadd Ġscroll Ġbuffer ( 1 0 0 ) ĊĊĠĠĠĠĠĠĠ Ġ// Ġexpand Ġ: Ġ 0 ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . re cyclerView )). perform ( expand ( 0 )) ĊĠĠĠĠĠĠĠ Ġvar Ġid ling Resource Ġ= ĠE lapsed Id L ing Resource ( duration ) ĊĠĠĠĠĠĠĠ ĠE sp ress o . register Id ling Resources ( id ling Resource ) ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . re cyclerView )). check ( matches ( correct Height ( 0 , Ġtrue ))) ĊĠĠĠĠĠĠĠ ĠE sp ress o . unregister Id ling Resources ( id ling Resource ) ĊĊĠĠĠĠĠĠĠ Ġ// Ġscroll ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . re cyclerView )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. perform ( RecyclerView Actions . scrollTo Position < Expand able ViewHolder >( 1 0 0 )) ĊĠĠĠĠĠĠĠ Ġid ling Resource Ġ= ĠE lapsed Id L ing Resource ( duration ) ĊĠĠĠĠĠĠĠ ĠE sp ress o . register Id ling Resources ( id ling Resource ) ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . re cyclerView )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. perform ( RecyclerView Actions . scrollTo Position < Expand able ViewHolder >( 0 )) ĊĠĠĠĠĠĠĠ ĠE sp ress o . unregister Id ling Resources ( id ling Resource ) ĊĊĠĠĠĠĠĠĠ Ġ// Ġrestore Ġexpanded Ġ: Ġ 0 ĊĠĠĠĠĠĠĠ Ġid ling Resource Ġ= ĠE lapsed Id L ing Resource ( duration ) ĊĠĠĠĠĠĠĠ ĠE sp ress o . register Id ling Resources ( id ling Resource ) ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . re cyclerView )). check ( matches ( correct Height ( 0 , Ġtrue ))) ĊĠĠĠĠĠĠĠ ĠE sp ress o . unregister Id ling Resources ( id ling Resource ) ĊĊĠĠĠĠĠĠĠ Ġ// Ġexpand Ġ: Ġ 1 6 ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . re cyclerView )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. perform ( RecyclerView Actions . scrollTo Position < Expand able ViewHolder >( 2 1 )) ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . re cyclerView )). perform ( expand ( 1 6 )) ĊĠĠĠĠĠĠĠ Ġid ling Resource Ġ= ĠE lapsed Id L ing Resource ( duration ) ĊĠĠĠĠĠĠĠ ĠE sp ress o . register Id ling Resources ( id ling Resource ) ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . re cyclerView )). check ( matches ( correct Height ( 1 6 , Ġtrue ))) ĊĠĠĠĠĠĠĠ ĠE sp ress o . unregister Id ling Resources ( id ling Resource ) ĊĊĠĠĠĠĠĠĠ Ġ// Ġexpand Ġ: Ġ 1 7 ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . re cyclerView )). perform ( expand ( 1 7 )) ĊĠĠĠĠĠĠĠ Ġid ling Resource Ġ= ĠE lapsed Id L ing Resource ( duration ) ĊĠĠĠĠĠĠĠ ĠE sp ress o . register Id ling Resources ( id ling Resource ) ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . re cyclerView )). check ( matches ( correct Height ( 1 7 , Ġtrue ))) ĊĠĠĠĠĠĠĠ ĠE sp ress o . unregister Id ling Resources ( id ling Resource ) ĊĊĠĠĠĠĠĠĠ Ġ// Ġexpand Ġ: Ġ 5 3 ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . re cyclerView )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. perform ( RecyclerView Actions . scrollTo Position < Expand able ViewHolder >( 5 5 )) ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . re cyclerView )). perform ( expand ( 5 3 )) ĊĠĠĠĠĠĠĠ Ġid ling Resource Ġ= ĠE lapsed Id L ing Resource ( duration ) ĊĠĠĠĠĠĠĠ ĠE sp ress o . register Id ling Resources ( id ling Resource ) ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . re cyclerView )). check ( matches ( correct Height ( 5 3 , Ġtrue ))) ĊĠĠĠĠĠĠĠ ĠE sp ress o . unregister Id ling Resources ( id ling Resource ) ĊĊĠĠĠĠĠĠĠ Ġ// Ġscroll ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . re cyclerView )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. perform ( RecyclerView Actions . scrollTo Position < Expand able ViewHolder >( 1 5 )) ĊĠĠĠĠĠĠĠ Ġ// Ġrestore Ġexpanded Ġ: Ġ 1 6 , Ġ 1 7 ĊĠĠĠĠĠĠĠ Ġid ling Resource Ġ= ĠE lapsed Id L ing Resource ( duration ) ĊĠĠĠĠĠĠĠ ĠE sp ress o . register Id ling Resources ( id ling Resource ) ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . re cyclerView )). check ( matches ( correct Height ( 1 6 , Ġtrue ))) ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . re cyclerView )). check ( matches ( correct Height ( 1 7 , Ġtrue ))) ĊĠĠĠĠĠĠĠ ĠE sp ress o . unregister Id ling Resources ( id ling Resource ) ĊĊĠĠĠĠĠĠĠ Ġ// Ġcollapse Ġ: Ġ 1 6 ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . re cyclerView )). perform ( collapse ( 1 6 )) ĊĠĠĠĠĠĠĠ Ġid ling Resource Ġ= ĠE lapsed Id L ing Resource ( duration ) ĊĠĠĠĠĠĠĠ ĠE sp ress o . register Id ling Resources ( id ling Resource ) ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . re cyclerView )). check ( matches ( correct Height ( 1 6 , Ġfalse ))) ĊĠĠĠĠĠĠĠ ĠE sp ress o . unregister Id ling Resources ( id ling Resource ) ĊĊĠĠĠĠĠĠĠ Ġ// Ġscroll ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . re cyclerView )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. perform ( RecyclerView Actions . scrollTo Position < Expand able ViewHolder >( 0 )) ĊĠĠĠĠĠĠĠ Ġ// Ġrestore Ġexpanded Ġ: Ġ 0 ĊĠĠĠĠĠĠĠ Ġid ling Resource Ġ= ĠE lapsed Id L ing Resource ( duration ) ĊĠĠĠĠĠĠĠ ĠE sp ress o . register Id ling Resources ( id ling Resource ) ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . re cyclerView )). check ( matches ( correct Height ( 0 , Ġtrue ))) ĊĠĠĠĠĠĠĠ ĠE sp ress o . unregister Id ling Resources ( id ling Resource ) ĊĊĠĠĠĠĠĠĠ Ġ// Ġscroll ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . re cyclerView )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. perform ( RecyclerView Actions . scrollTo Position < Expand able ViewHolder >( 1 8 )) ĊĠĠĠĠĠĠĠ Ġ// Ġrestore Ġcollapse Ġ: Ġ 1 6 ĊĠĠĠĠĠĠĠ Ġid ling Resource Ġ= ĠE lapsed Id L ing Resource ( duration ) ĊĠĠĠĠĠĠĠ ĠE sp ress o . register Id ling Resources ( id ling Resource ) ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . re cyclerView )). check ( matches ( correct Height ( 1 6 , Ġfalse ))) ĊĠĠĠĠĠĠĠ ĠE sp ress o . unregister Id ling Resources ( id ling Resource ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ/** ĊĠĠĠĠ Ġ* Ġmust Ġuse Ġin Ġre cycler Ġview . ĊĠĠĠĠ Ġ* Ġcheck Ġa Ġparent Ġheight Ġis Ġequal Ġto Ġchildren Ġheight . ĊĠĠĠĠ Ġ* ĊĠĠĠĠ Ġ* ĠFor Ġexample Ġ: Ġrow Ġitem ĊĠĠĠĠ Ġ* ĊĠĠĠĠ Ġ* Ġ< Parent > ĊĠĠĠĠ Ġ* ĠĠĠĠ Ġ< Child /> ĊĠĠĠĠ Ġ* ĠĠĠĠ Ġ< Expand able Layout > ĊĠĠĠĠ Ġ* ĠĠĠĠĠĠĠĠ Ġ< Child /> ĊĠĠĠĠ Ġ* ĠĠĠĠ Ġ</ Expand able Layout > ĊĠĠĠĠ Ġ* Ġ</ Parent > ĊĠĠĠĠ Ġ* ĊĠĠĠĠ Ġ* Ġ@ param Ġposition ĊĠĠĠĠ Ġ* Ġ@ param ĊĠĠĠĠ Ġ*/ ĊĠĠĠ Ġprivate Ġfun Ġcorrect Height ( position : ĠInt , Ġis Expanded : ĠBoolean ) Ġ= Ġobject Ġ: ĠType Safe Matcher < View >() Ġ{ ĊĠĠĠĠĠĠĠ Ġvar Ġview Height Ġ= Ġ 0 ĊĠĠĠĠĠĠĠ Ġvar Ġtitle Height Ġ= Ġ 0 ĊĠĠĠĠĠĠĠ Ġvar Ġexpand able Layout Height Ġ= Ġ 0 ĊĠĠĠĠĠĠĠ Ġvar Ġchild Height Ġ= Ġ 0 ĊĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġdescribe To ( description : ĠDescription ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdescription . append Text ( String . format (" The Ġheight Ġof Ġexpand able (% d ) Ġlayout Ġis Ġnot Ġ" Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" equal Ġto Ġa Ġheight Ġof Ġchild (% d ). Ġitem Height (% d ), Ġtitle (% d )", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġexpand able Layout Height , Ġchild Height , Ġview Height , Ġtitle Height )) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġmatches S af ely ( view : ĠView ): ĠBoolean Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ( view Ġ! is ĠRecyclerView ) Ġreturn Ġfalse ĊĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġholder Ġ= Ġview . find ViewHolder For Adapter Position ( position ) Ġas ĠExpand able ViewHolder ĊĠĠĠĠĠĠĠĠĠĠĠ Ġview Height Ġ= Ġholder . item View . height ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtitle Height Ġ= Ġholder . title . height ĊĠĠĠĠĠĠĠĠĠĠĠ Ġexpand able Layout Height Ġ= Ġholder . expand able Layout . height ĊĠĠĠĠĠĠĠĠĠĠĠ Ġchild Height Ġ= Ġholder . description . height ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn Ġexpand able Layout Height Ġ== Ġchild Height ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ&& Ġexpand able Layout Height Ġ== Ġview Height Ġ- Ġtitle Height ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ&& Ġif Ġ( is Expanded ) Ġexpand able Layout Height Ġ> Ġ 0 Ġelse Ġexpand able Layout Height Ġ== Ġ 0 ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġexpand ( position : ĠInt ) Ġ= ĠView Actions . action With Assertions ( Expand Action ( position )) ĊĊĠĠĠ Ġprivate Ġclass ĠExpand Action ( val Ġposition : ĠInt ) Ġ: ĠView Action Ġ{ ĊĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġget Constraints () Ġ= Ġis Displayed () ĊĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġperform ( ui Controller : ĠUi Controller , Ġview : ĠView ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ( view Ġ! is ĠRecyclerView ) Ġreturn ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġholder Ġ= Ġview . find ViewHolder For Adapter Position ( position ) Ġas ĠExpand able ViewHolder ĊĠĠĠĠĠĠĠĠĠĠĠ Ġholder . expand able Layout . expand () ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġoverride Ġfun ĠgetDescription () Ġ= Ġ" Expand ." ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġcollapse ( position : ĠInt ) Ġ= ĠView Actions . action With Assertions ( Collapse Action ( position )) ĊĊĠĠĠ Ġprivate Ġclass ĠCol lapse Action ( val Ġposition : ĠInt ) Ġ: ĠView Action Ġ{ ĊĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġget Constraints () Ġ= Ġis Displayed () ĊĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġperform ( ui Controller : ĠUi Controller , Ġview : ĠView ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ( view Ġ! is ĠRecyclerView ) Ġreturn ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġholder Ġ= Ġview . find ViewHolder For Adapter Position ( position ) Ġas ĠExpand able ViewHolder ĊĠĠĠĠĠĠĠĠĠĠĠ Ġholder . expand able Layout . collapse () ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġoverride Ġfun ĠgetDescription () Ġ= Ġ" Collapse ." ĊĠĠĠ Ġ} Ċ }