package Ġcom . kaz ak ago . sto ref low able Ċ Ċ import Ġkotlinx . coroutines . Experimental Cor outines Api Ċ import Ġkotlinx . coroutines . test . run Test Ċ import Ġorg . am sh ove . k lu ent . co Inv oking Ċ import Ġorg . am sh ove . k lu ent . shouldBe EqualTo Ċ import Ġorg . am sh ove . k lu ent . should Throw Ċ import Ġorg . junit . Test Ċ Ċ @ Experimental Cor outines Api Ċ class ĠStore Flow able Required Data Test Ġ{ ĊĊĠĠĠ Ġprivate Ġenum Ġclass ĠTest Data ( val Ġneed Refresh : ĠBoolean ) Ġ{ ĊĠĠĠĠĠĠĠ ĠValid Data ( false ), ĊĠĠĠĠĠĠĠ ĠInvalid Data ( true ), ĊĠĠĠĠĠĠĠ ĠF etched Data ( false ), ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġclass ĠTest Flow able Factory ( private Ġvar Ġdata Cache : ĠTest Data ?) Ġ: ĠStore Flow able Factory < Unit , ĠTest Data > Ġ{ ĊĊĠĠĠĠĠĠĠ Ġoverride Ġval Ġflow able Data StateManager : ĠFlow able Data StateManager < Unit > Ġ= Ġobject Ġ: ĠFlow able Data StateManager < Unit >() Ġ{} ĊĊĠĠĠĠĠĠĠ Ġoverride Ġsuspend Ġfun Ġload Data From Cache ( param : ĠUnit ): ĠTest Data ? Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn Ġdata Cache ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġoverride Ġsuspend Ġfun Ġsave DataTo Cache ( new Data : ĠTest Data ?, Ġparam : ĠUnit ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdata Cache Ġ= ĠnewData ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġoverride Ġsuspend Ġfun Ġfetch Data From Origin ( param : ĠUnit ): ĠTest Data Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn ĠTest Data . F etched Data ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġoverride Ġsuspend Ġfun Ġneed Refresh ( cached Data : ĠTest Data , Ġparam : ĠUnit ): ĠBoolean Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn Ġcached Data . need Refresh ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġrequired Data _ Both _ No Cache () Ġ= Ġrun Test Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġstore Flow able Ġ= ĠTest Flow able Factory ( data Cache Ġ= Ġnull ). create ( Unit ) ĊĠĠĠĠĠĠĠ Ġstore Flow able . require Data ( Getting From . Both ) ĠshouldBe EqualTo ĠTest Data . F etched Data ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġrequired Data _ Both _ Valid Cache () Ġ= Ġrun Test Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġstore Flow able Ġ= ĠTest Flow able Factory ( data Cache Ġ= ĠTest Data . Valid Data ). create ( Unit ) ĊĠĠĠĠĠĠĠ Ġstore Flow able . require Data ( Getting From . Both ) ĠshouldBe EqualTo ĠTest Data . Valid Data ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġrequired Data _ Both _ Invalid Cache () Ġ= Ġrun Test Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġstore Flow able Ġ= ĠTest Flow able Factory ( data Cache Ġ= ĠTest Data . Invalid Data ). create ( Unit ) ĊĠĠĠĠĠĠĠ Ġstore Flow able . require Data ( Getting From . Both ) ĠshouldBe EqualTo ĠTest Data . F etched Data ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġrequired Data _ Cache _ No Cache () Ġ= Ġrun Test Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġstore Flow able Ġ= ĠTest Flow able Factory ( data Cache Ġ= Ġnull ). create ( Unit ) ĊĠĠĠĠĠĠĠ Ġco Inv oking Ġ{ Ġstore Flow able . require Data ( Getting From . Cache ) Ġ} Ġshould Throw ĠNoSuch ElementException :: class ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġrequired Data _ Cache _ Valid Cache () Ġ= Ġrun Test Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġstore Flow able Ġ= ĠTest Flow able Factory ( data Cache Ġ= ĠTest Data . Valid Data ). create ( Unit ) ĊĠĠĠĠĠĠĠ Ġstore Flow able . require Data ( Getting From . Cache ) ĠshouldBe EqualTo ĠTest Data . Valid Data ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġrequired Data _ Cache _ Invalid Cache () Ġ= Ġrun Test Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġstore Flow able Ġ= ĠTest Flow able Factory ( data Cache Ġ= ĠTest Data . Invalid Data ). create ( Unit ) ĊĠĠĠĠĠĠĠ Ġco Inv oking Ġ{ Ġstore Flow able . require Data ( Getting From . Cache ) Ġ} Ġshould Throw ĠNoSuch ElementException :: class ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġrequired Data _ Origin _ No Cache () Ġ= Ġrun Test Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġstore Flow able Ġ= ĠTest Flow able Factory ( data Cache Ġ= Ġnull ). create ( Unit ) ĊĠĠĠĠĠĠĠ Ġstore Flow able . require Data ( Getting From . Origin ) ĠshouldBe EqualTo ĠTest Data . F etched Data ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġrequired Data _ Origin _ Valid Cache () Ġ= Ġrun Test Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġstore Flow able Ġ= ĠTest Flow able Factory ( data Cache Ġ= ĠTest Data . Valid Data ). create ( Unit ) ĊĠĠĠĠĠĠĠ Ġstore Flow able . require Data ( Getting From . Origin ) ĠshouldBe EqualTo ĠTest Data . F etched Data ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġrequired Data _ Origin _ Invalid Cache () Ġ= Ġrun Test Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġstore Flow able Ġ= ĠTest Flow able Factory ( data Cache Ġ= ĠTest Data . Invalid Data ). create ( Unit ) ĊĠĠĠĠĠĠĠ Ġstore Flow able . require Data ( Getting From . Origin ) ĠshouldBe EqualTo ĠTest Data . F etched Data ĊĠĠĠ Ġ} Ċ } Ċ