package Ġradio graphy . test . compose Ċ Ċ import Ġandroid . view . View Ċ import Ġandroid . widget . TextView Ċ import Ġandroidx . activity . Component Activity Ċ import Ġandroidx . compose . foundation . Text Ċ import Ġandroidx . compose . foundation . layout . Box Ċ import Ġandroidx . compose . foundation . layout . Column Ċ import Ġandroidx . compose . foundation . layout . size Ċ import Ġandroidx . compose . material . Button Ċ import Ġandroidx . compose . ui . Layout Modifier Ċ import Ġandroidx . compose . ui . Meas ur able Ċ import Ġandroidx . compose . ui . Measure Scope Ċ import Ġandroidx . compose . ui . Measure Scope . Measure Result Ċ import Ġandroidx . compose . ui . Modifier Ċ import Ġandroidx . compose . ui . platform . Density Ambient Ċ import Ġandroidx . compose . ui . unit . Constraints Ċ import Ġandroidx . compose . ui . unit . Density Ċ import Ġandroidx . compose . ui . unit . dp Ċ import Ġandroidx . ui . test . create Android Compose Rule Ċ import Ġcom . google . common . truth . Truth . assertThat Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġradio graphy . Sc ann ableView Ċ import Ġradio graphy . Sc ann ableView . Android View Ċ import Ġradio graphy . Sc ann ableView . Compose View Ċ import Ġradio graphy . Experimental Radio graphy Compose Api Ċ import Ġjava . util . concurrent . Count DownLatch Ċ import Ġjava . util . concurrent . TimeUnit Ċ Ċ @ Opt In ( Experimental Radio graphy Compose Api :: class ) Ċ class ĠCompose View Test Ġ{ ĊĊĠ Ġ@ get : Rule ĊĠ Ġval Ġcompose Rule Ġ= Ġcreate Android Compose Rule < Component Activity >() ĊĊĠ Ġ@ Test Ġfun Ġandroid View _ children _ includes _ Compose Views () Ġ{ ĊĠĠĠ Ġcompose Rule . setContent With Explicit Root Ġ{ ĊĠĠĠĠĠ ĠText (" hello ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġval Ġtext Composable Ġ= Ġfind Root Compose View (). all Desc end ents Depth First ĊĠĠĠĠĠĠĠ Ġ. single Ġ{ Ġit . displayName Ġ== Ġ" Text " Ġ} ĊĠĠĠ ĠassertThat ( text Composable . children . as Iterable ()). isEmpty () ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġcompose View _ children _ includes _ Android View () Ġ{ ĊĠĠĠ Ġcompose Rule . setContent With Explicit Root Ġ{ ĊĠĠĠĠĠ ĠColumn Ġ{ ĊĠĠĠĠĠĠĠ Ġandroidx . compose . ui . view interop . Android View (:: TextView ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġval Ġcolumn View Ġ= Ġfind Root Compose View (). all Desc end ents Depth First ĊĠĠĠĠĠĠĠ Ġ. single Ġ{ Ġit . displayName Ġ== Ġ" Column " Ġ} ĊĠĠĠ Ġval Ġandroid Views Ġ= Ġcolumn View . all Desc end ents Depth First ĊĠĠĠĠĠĠĠ Ġ. filter Is Instance < Android View >() ĊĠĠĠĠĠĠĠ Ġ. toList () ĊĠĠĠ ĠassertThat ( android Views . count Ġ{ Ġit . view Ġis ĠTextView Ġ}). isEqualTo ( 1 ) ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġcompose View _ reports _ children () Ġ{ ĊĠĠĠ Ġcompose Rule . setContent With Explicit Root Ġ{ ĊĠĠĠĠĠ ĠColumn Ġ{ ĊĠĠĠĠĠĠĠ ĠText (" hello ") ĊĠĠĠĠĠĠĠ ĠButton ( onClick Ġ= Ġ{}) Ġ{ ĊĠĠĠĠĠĠĠĠĠ ĠBox ( Modifier ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġval Ġcolumn View Ġ= Ġfind Root Compose View () ĊĠĠĠĠĠĠĠ Ġ. all Desc end ents Depth First ĊĠĠĠĠĠĠĠ Ġ. first Ġ{ Ġit . displayName Ġ== Ġ" Column " Ġ} ĊĠĠĠ Ġval Ġcolumn Children Ġ= Ġcolumn View . children . toList () ĊĠĠĠ ĠassertThat ( column Children ). has Size ( 2 ) ĊĠĠĠ ĠassertThat ( column Children [ 0 ]. displayName ). isEqualTo (" Text ") ĊĠĠĠ ĠassertThat ( column Children [ 1 ]. displayName ). isEqualTo (" Button ") ĊĠĠĠ ĠassertThat ( column Children [ 1 ]. all Desc end ents Depth First . count Ġ{ Ġit . displayName Ġ== Ġ" Box " Ġ}) ĊĠĠĠĠĠĠĠ Ġ. isEqualTo ( 1 ) ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġcompose View _ reports _ Layout Modifiers () Ġ{ ĊĠĠĠ Ġcompose Rule . setContent With Explicit Root Ġ{ ĊĠĠĠĠĠ ĠBox ( Test Modifier ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġval Ġbox View Ġ= ĊĠĠĠĠĠ Ġfind Root Compose View (). all Desc end ents Depth First . single Ġ{ Ġit . displayName Ġ== Ġ" Box " Ġ} Ġas ĠCompose View ĊĠĠĠ ĠassertThat ( box View . modifiers ). contains ( Test Modifier ) ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġcompose View _ reports _ size () Ġ{ ĊĠĠĠ Ġvar Ġdensity : ĠD ensity ? Ġ= Ġnull ĊĠĠĠ Ġcompose Rule . setContent With Explicit Root Ġ{ ĊĠĠĠĠĠ Ġdensity Ġ= ĠD ensity Ambient . current ĊĠĠĠĠĠ ĠBox ( Modifier . size ( 3 0 . dp , Ġ 4 0 . dp )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġval Ġ( width Px , Ġheight Px ) Ġ= Ġcompose Rule . run On Idle Ġ{ ĊĠĠĠĠĠ Ġwith ( density !! ) Ġ{ ĊĠĠĠĠĠĠĠ ĠPair ( 3 0 . dp . toInt Px (), Ġ 4 0 . dp . toInt Px ()) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġval Ġbox View Ġ= ĊĠĠĠĠĠ Ġfind Root Compose View (). all Desc end ents Depth First . single Ġ{ Ġit . displayName Ġ== Ġ" Box " Ġ} Ġas ĠCompose View ĊĠĠĠ ĠassertThat ( box View . width ). isEqualTo ( width Px ) ĊĠĠĠ ĠassertThat ( box View . height ). isEqualTo ( height Px ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġobject ĠTest Modifier Ġ: ĠLayout Modifier Ġ{ ĊĠĠĠ Ġoverride Ġfun ĠMeasure Scope . measure ( ĊĠĠĠĠĠ Ġmeas ur able : ĠMe as ur able , ĊĠĠĠĠĠ Ġconstraints : ĠConstraints ĊĠĠĠ Ġ): ĠMeasure Result Ġ= Ġlayout ( 1 , Ġ 2 ) Ġ{} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġfind Root Compose View (): ĠCompose View Ġ= ĊĠĠĠ Ġfind Root Android View (). all Desc end ents Depth First ĊĠĠĠĠĠĠĠ Ġ. filter Is Instance < Compose View >() ĊĠĠĠĠĠĠĠ Ġ. first () ĊĊĠ Ġprivate Ġfun Ġfind Root Android View (): ĠAndroid View Ġ{ ĊĠĠĠ Ġval Ġl atch Ġ= ĠCount DownLatch ( 1 ) ĊĠĠĠ Ġvar Ġandroid View : ĠAndroid View ? Ġ= Ġnull ĊĠĠĠ Ġcompose Rule . activity Rule . scenario . on Activity Ġ{ ĊĠĠĠĠĠ Ġval Ġcontent View Ġ= Ġit . findViewById < View >( android . R . id . content ) ĊĠĠĠĠĠ Ġandroid View Ġ= ĠAndroid View ( content View ) ĊĠĠĠ Ġ} ĊĠĠĠ Ġl atch . await ( 1 , ĠTimeUnit . SECONDS ) ĊĠĠĠ Ġreturn Ġandroid View !! ĊĠ Ġ} ĊĊĠ Ġprivate Ġval ĠSc ann ableView . all Desc end ents Depth First : ĠSequence < Sc ann ableView > ĊĠĠĠ Ġget () Ġ= Ġchildren . flatMap Ġ{ Ġsequence Of ( it ) Ġ+ Ġit . all Desc end ents Depth First Ġ} Ċ } Ċ