package Ġcom . squareup . workflow 1 . ui . internal . test Ċ Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . view . View Ċ import Ġandroidx . saved state . Saved State Registry Ċ import Ġandroidx . saved state . View Tree Saved State Registry Owner Ċ import Ġcom . google . common . truth . Truth . assertThat Ċ import Ġcom . squareup . workflow 1 . ui . Workflow Android X Support . Saved State Registry Client Ċ import Ġcom . squareup . workflow 1 . ui . Workflow Android X Support . create Saved State Registry Client Ċ import Ġcom . squareup . workflow 1 . ui . Workflow Ui Experimental Api Ċ import Ġkotlin . test . fail Ċ Ċ /** Ċ Ġ* ĠHelper Ġclass Ġfor Ġtesting Ġinteractions Ġwith Ġa Ġ[ Saved State Registry ]. Ċ Ġ* Ċ Ġ* ĠWrite Ġvalues Ġto Ġ[ states To Save ByName ] Ġbefore Ġasking Ġthe Ġregistry Ġto Ġsave , Ġand Ġlater Ġcheck Ċ Ġ* Ġ[ restore d States ByName ] Ġto Ġsee Ġif Ġthe Ġvalues Ġwere Ġrestored Ġthat Ġyou Ġwere Ġexpecting . Ċ Ġ*/ Ċ @ Workflow Ui Experimental Api Ċ public Ġclass ĠState Registry TestHelper Ġ{ ĊĠ Ġpublic Ġval Ġstates To Save ByName : ĠMutable Map < String , ĠString > Ġ= Ġmutable Map Of () ĊĠ Ġpublic Ġval Ġrestored States ByName : ĠMutable Map < String , ĠString ?> Ġ= Ġmutable Map Of () ĊĊĠ Ġpublic Ġfun Ġinitialize ( activity : ĠAbstract Lifecycle Test Activity ) Ġ{ ĊĠĠĠ Ġvar Ġkey : ĠString ? Ġ= Ġnull ĊĊĠĠĠ Ġval Ġregistry Client Ġ= Ġcreate Saved State Registry Client ( ĊĠĠĠĠĠ Ġobject Ġ: ĠSaved State Registry Client Ġ{ ĊĠĠĠĠĠĠĠ Ġoverride Ġval Ġsaved State Registry Key : ĠString Ġget () Ġ= Ġkey !! ĊĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġon Save To Registry ( bundle : ĠBundle ) Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġbundle . putString (" rendering . name ", Ġkey !! ) ĊĠĠĠĠĠĠĠĠĠ Ġstates To Save ByName [ key !! ]?. let Ġ{ Ġstate Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġbundle . putString (" state ", Ġstate ) ĊĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġon Restore From Registry ( bundle : ĠBundle ?) Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġif Ġ( bundle Ġ!= Ġnull ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( bundle . getString (" rendering . name ")). isEqualTo ( key !! ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġrestored States ByName [ key !! ] Ġ= Ġbundle . getString (" state ") ĊĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ) ĊĊĠĠĠ Ġactivity . on View Attach StateChanged Listener Ġ= Ġ{ Ġview , Ġrendering , Ġattached Ġ-> ĊĠĠĠĠĠ Ġkey Ġ= Ġrendering . compatibility Key ĊĊĠĠĠĠĠ Ġif Ġ( attached ) Ġ{ ĊĠĠĠĠĠĠĠ ĠassertThat ( restore d States ByName ). does Not Contain Key ( key ) ĊĠĠĠĠĠĠĠ Ġregistry Client . on View Attached To Window ( view ) ĊĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠ Ġregistry Client . on View Detached From Window ( view ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠ Ġ} Ċ } Ċ Ċ public Ġfun ĠView . require State Registry (): ĠSaved State Registry Ġ= ĊĠ ĠView Tree Saved State Registry Owner . get ( this )?. saved State Registry ĊĠĠĠ Ġ?: Ġfail (" Expected ĠView Tree Saved State Registry Owner Ġto Ġbe Ġset Ġon Ġview .") Ċ