package Ġcom . nat ura . android . expansion Panel Ċ Ċ import Ġandroid . app . Activity Ċ import Ġandroid . view . LayoutInflater Ċ import Ġandroid . view . View Ċ import Ġandroidx . constraint layout . widget . Constraint Layout Ċ import Ġandroidx . core . content . Context Compat Ċ import Ġandroidx . test . ext . junit . runners . Android JUnit 4 Ċ import Ġcom . google . common . truth . Truth Ċ import Ġcom . nat ura . android . R Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . ro bo lectric . Ro bo lectric Ċ Ċ @ RunWith ( Android JUnit 4 :: class ) Ċ class ĠExp ansion Panel Test Ġ{ ĊĊĠĠĠ Ġval Ġactivity Controller Ġ= ĠRo bo lectric . build Activity ( Activity :: class . java ) ĊĠĠĠ Ġlateinit Ġvar Ġexpansion Panel : ĠExp ansion Panel ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun ĠsetUp () Ġ{ ĊĠĠĠĠĠĠĠ Ġactivity Controller . get (). set Theme ( R . style . Theme _ N atura _ Light ) ĊĠĠĠĠĠĠĠ Ġexpansion Panel Ġ= ĠExp ansion Panel ( activity Controller . get ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġbasic Layout () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġlayout Ġ= ĠLayoutInflater . from ( activity Controller . get ()). inflate ( R . layout . ds _ expansion _ panel , Ġnull ) Ġas ĠView ĊĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( layout . findViewById ( R . id . ds _ expansion _ panel _ container ) Ġas ĠView ). isNotNull () ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( layout . findViewById ( R . id . ds _ expansion _ panel _ top ) Ġas ĠView ). isNotNull () ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( layout . findViewById ( R . id . ds _ expansion _ panel _ title ) Ġas ĠView ). isNotNull () ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( layout . findViewById ( R . id . ds _ expansion _ panel _ icon ) Ġas ĠView ). isNotNull () ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( layout . findViewById ( R . id . ds _ expansion _ panel _ content _ area ) Ġas ĠView ). isNotNull () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġcontent Not Visible ByDefault () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcontent Ġ= Ġexpansion Panel . findViewById ( R . id . ds _ expansion _ panel _ content _ area ) Ġas ĠConstraint Layout ĊĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( content . visibility ). isEqualTo ( View . GONE ) ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( expansion Panel . is Expanded ). isFalse () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġborder less When Collapsed () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġexpected Background Ġ= ĠContext Compat . get Drawable ( activity Controller . get (), ĠR . drawable . ds _ expansion _ panel _ border _ collapsed ) ĊĊĠĠĠĠĠĠĠ Ġval Ġcontainer Ġ= Ġexpansion Panel . findViewById ( R . id . ds _ expansion _ panel _ container ) Ġas ĠView ĊĊĠĠĠĠĠĠĠ Ġcontainer . call OnClick () ĊĠĠĠĠĠĠĠ Ġcontainer . call OnClick () ĊĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( container . background . constant State ). isEqualTo ( expected Background ?. constant State ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshow Content When OnClick () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcontainer Ġ= Ġexpansion Panel . findViewById ( R . id . ds _ expansion _ panel _ container ) Ġas ĠView ĊĊĠĠĠĠĠĠĠ Ġcontainer . call OnClick () ĊĊĠĠĠĠĠĠĠ Ġval Ġcontent Ġ= Ġexpansion Panel . findViewById ( R . id . ds _ expansion _ panel _ content _ area ) Ġas ĠConstraint Layout ĊĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( content . visibility ). isEqualTo ( View . VISIBLE ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshow Content When Set Expanded () Ġ{ ĊĠĠĠĠĠĠĠ Ġexpansion Panel . is Expanded Ġ= Ġtrue ĊĊĠĠĠĠĠĠĠ Ġval Ġcontent Ġ= Ġexpansion Panel . findViewById ( R . id . ds _ expansion _ panel _ content _ area ) Ġas ĠConstraint Layout ĊĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( content . visibility ). isEqualTo ( View . VISIBLE ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġinvoke Listener When OnClick () Ġ{ ĊĠĠĠĠĠĠĠ Ġvar Ġis Panel Expanded Ġ= Ġfalse ĊĠĠĠĠĠĠĠ Ġexpansion Panel . setOn State ChangeListener Ġ{ Ġis Panel Expanded Ġ= Ġit Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġcontainer Ġ= Ġexpansion Panel . findViewById ( R . id . ds _ expansion _ panel _ container ) Ġas ĠView ĊĊĠĠĠĠĠĠĠ Ġcontainer . call OnClick () ĊĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( is Panel Expanded ). isTrue () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġwith Border When Expanded () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġexpected Background Ġ= ĠContext Compat . get Drawable ( activity Controller . get (), ĠR . drawable . ds _ expansion _ panel _ border _ expanded ) ĊĊĠĠĠĠĠĠĠ Ġval Ġcontainer Ġ= Ġexpansion Panel . findViewById ( R . id . ds _ expansion _ panel _ container ) Ġas ĠView ĊĊĠĠĠĠĠĠĠ Ġcontainer . call OnClick () ĊĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( container . background . constant State ). isEqualTo ( expected Background ?. constant State ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġhide Content When OnClick After Being Expanded () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcontainer Ġ= Ġexpansion Panel . findViewById ( R . id . ds _ expansion _ panel _ container ) Ġas ĠView ĊĊĠĠĠĠĠĠĠ Ġcontainer . call OnClick () ĊĠĠĠĠĠĠĠ Ġcontainer . call OnClick () ĊĊĠĠĠĠĠĠĠ Ġval Ġcontent Ġ= Ġexpansion Panel . findViewById ( R . id . ds _ expansion _ panel _ content _ area ) Ġas ĠConstraint Layout ĊĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( content . visibility ). isEqualTo ( View . GONE ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġhide Content When Set Collapsed () Ġ{ ĊĠĠĠĠĠĠĠ Ġexpansion Panel . is Expanded Ġ= Ġtrue ĊĠĠĠĠĠĠĠ Ġexpansion Panel . is Expanded Ġ= Ġfalse ĊĊĠĠĠĠĠĠĠ Ġval Ġcontent Ġ= Ġexpansion Panel . findViewById ( R . id . ds _ expansion _ panel _ content _ area ) Ġas ĠConstraint Layout ĊĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( content . visibility ). isEqualTo ( View . GONE ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġinvoke Listener When OnClick After Being Expanded () Ġ{ ĊĠĠĠĠĠĠĠ Ġvar Ġis Panel Expanded Ġ= Ġfalse ĊĠĠĠĠĠĠĠ Ġexpansion Panel . setOn State ChangeListener Ġ{ Ġis Panel Expanded Ġ= Ġit Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġcontainer Ġ= Ġexpansion Panel . findViewById ( R . id . ds _ expansion _ panel _ container ) Ġas ĠView ĊĊĠĠĠĠĠĠĠ Ġcontainer . call OnClick () ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( is Panel Expanded ). isTrue () ĊĊĠĠĠĠĠĠĠ Ġcontainer . call OnClick () ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( is Panel Expanded ). isFalse () ĊĠĠĠ Ġ} Ċ } Ċ