package Ġar cs . core . storage . testutil Ċ Ċ import Ġar cs . core . cr dt . Version Map Ċ import Ġar cs . core . data . Collection Type Ċ import Ġar cs . core . data . EntityType Ċ import Ġar cs . core . data . Raw Entity Ċ import Ġar cs . core . entity . testutil . Restricted Dummy Entity Ċ import Ġar cs . core . storage . Active Store Ċ import Ġar cs . core . storage . Proxy Message Ċ import Ġar cs . core . storage . Store Options Ċ import Ġar cs . core . storage . Unt yped Proxy Message Ċ import Ġar cs . core . storage . reference mode . Ref Mode Store Data Ċ import Ġar cs . core . storage . reference mode . Ref Mode Store Op Ċ import Ġar cs . core . storage . reference mode . Ref Mode Store Output Ċ import Ġcom . google . common . truth . Truth . assertThat Ċ import Ġkotlinx . coroutines . Experimental Cor outines Api Ċ import Ġkotlinx . coroutines . test . run Blocking Test Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ Ċ private Ġtype alias ĠProxy Message Operations Ġ= ĊĠ ĠProxy Message . Operations < Ref Mode Store Data , ĠRef Mode Store Op , ĠRef Mode Store Output > Ċ Ċ @ Suppress (" UN CHECK ED _ CAST ") Ċ @ Opt In ( Experimental Cor outines Api :: class ) Ċ class ĠRef Mode Store Helper Test Ġ{ ĊĠ Ġprivate Ġlateinit Ġvar Ġcaptured Proxy Messages : ĠMutable List < Proxy Message Operations > ĊĠ Ġprivate Ġlateinit Ġvar Ġfake Store : ĠActive Store < Ref Mode Store Data , ĠRef Mode Store Op , ĠRef Mode Store Output > ĊĊĠ Ġ@ Before ĊĠ Ġfun ĠsetUp () Ġ{ ĊĠĠĠ Ġcaptured Proxy Messages Ġ= Ġmutable ListOf () ĊĠĠĠ Ġval Ġstore Options Ġ= ĠStore Options ( ĊĠĠĠĠĠ ĠDummy Storage Key (" abc "), ĊĠĠĠĠĠ ĠCollection Type ( EntityType ( Restricted Dummy Entity . SCHEMA )) ĊĠĠĠ Ġ) ĊĠĠĠ Ġfake Store Ġ= Ġobject Ġ: ĠNo op Active Store ( store Options ) Ġ{ ĊĠĠĠĠĠ Ġoverride Ġsuspend Ġfun Ġon Proxy Message ( message : ĠUnt yped Proxy Message ) Ġ{ ĊĠĠĠĠĠĠĠ Ġcaptured Proxy Messages . add ( message Ġas ĠProxy Message Operations ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ġas ĠActive Store < Ref Mode Store Data , ĠRef Mode Store Op , ĠRef Mode Store Output > ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġsend Update Op _ in crements Version Map () Ġ= Ġrun Blocking Test Ġ{ ĊĠĠĠ Ġval Ġhelper Ġ= ĠRef Mode Store Helper ( ACT OR , Ġfake Store ) ĊĊĠĠĠ Ġhelper . send Update Op ( D UMMY _ ENTITY 1 ) ĊĠĠĠ Ġhelper . send Update Op ( D UMMY _ ENTITY 2 ) ĊĊĠĠĠ Ġassert Proxy Messages ( ĊĠĠĠĠĠ ĠRef Mode Store Op . Singleton Update ( ACT OR , ĠVersion Map ( ACT OR Ġto Ġ 1 ), ĠD UMMY _ ENTITY 1 ), ĊĠĠĠĠĠ ĠRef Mode Store Op . Singleton Update ( ACT OR , ĠVersion Map ( ACT OR Ġto Ġ 2 ), ĠD UMMY _ ENTITY 2 ) ĊĠĠĠ Ġ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġsend Add Op _ in crements Version Map () Ġ= Ġrun Blocking Test Ġ{ ĊĠĠĠ Ġval Ġhelper Ġ= ĠRef Mode Store Helper ( ACT OR , Ġfake Store ) ĊĊĠĠĠ Ġhelper . send Add Op ( D UMMY _ ENTITY 1 ) ĊĠĠĠ Ġhelper . send Add Op ( D UMMY _ ENTITY 2 ) ĊĊĠĠĠ Ġassert Proxy Messages ( ĊĠĠĠĠĠ ĠRef Mode Store Op . Set Add ( ACT OR , ĠVersion Map ( ACT OR Ġto Ġ 1 ), ĠD UMMY _ ENTITY 1 ), ĊĠĠĠĠĠ ĠRef Mode Store Op . Set Add ( ACT OR , ĠVersion Map ( ACT OR Ġto Ġ 2 ), ĠD UMMY _ ENTITY 2 ) ĊĠĠĠ Ġ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġsend Remove Op _ does Not Increment Version Map () Ġ= Ġrun Blocking Test Ġ{ ĊĠĠĠ Ġval Ġhelper Ġ= ĠRef Mode Store Helper ( ACT OR , Ġfake Store ) ĊĊĠĠĠ Ġhelper . send Add Op ( D UMMY _ ENTITY 1 ) ĊĠĠĠ Ġhelper . send Remove Op ( D UMMY _ ENTITY 1 . id ) ĊĊĠĠĠ Ġassert Proxy Messages ( ĊĠĠĠĠĠ ĠRef Mode Store Op . Set Add ( ACT OR , ĠVersion Map ( ACT OR Ġto Ġ 1 ), ĠD UMMY _ ENTITY 1 ), ĊĠĠĠĠĠ ĠRef Mode Store Op . Set Remove ( ACT OR , ĠVersion Map ( ACT OR Ġto Ġ 1 ), ĠD UMMY _ ENTITY 1 . id ) ĊĠĠĠ Ġ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġsend Singleton Clear Op _ does Not Increment Version Map () Ġ= Ġrun Blocking Test Ġ{ ĊĠĠĠ Ġval Ġhelper Ġ= ĠRef Mode Store Helper ( ACT OR , Ġfake Store ) ĊĊĠĠĠ Ġhelper . send Update Op ( D UMMY _ ENTITY 1 ) ĊĠĠĠ Ġhelper . send Singleton Clear Op () ĊĊĠĠĠ Ġassert Proxy Messages ( ĊĠĠĠĠĠ ĠRef Mode Store Op . Singleton Update ( ACT OR , ĠVersion Map ( ACT OR Ġto Ġ 1 ), ĠD UMMY _ ENTITY 1 ), ĊĠĠĠĠĠ ĠRef Mode Store Op . Singleton Clear ( ACT OR , ĠVersion Map ( ACT OR Ġto Ġ 1 )) ĊĠĠĠ Ġ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġsend Collection Clear Op _ does Not Increment Version Map () Ġ= Ġrun Blocking Test Ġ{ ĊĠĠĠ Ġval Ġhelper Ġ= ĠRef Mode Store Helper ( ACT OR , Ġfake Store ) ĊĊĠĠĠ Ġhelper . send Add Op ( D UMMY _ ENTITY 1 ) ĊĠĠĠ Ġhelper . send Collection Clear Op () ĊĊĠĠĠ Ġassert Proxy Messages ( ĊĠĠĠĠĠ ĠRef Mode Store Op . Set Add ( ACT OR , ĠVersion Map ( ACT OR Ġto Ġ 1 ), ĠD UMMY _ ENTITY 1 ), ĊĠĠĠĠĠ ĠRef Mode Store Op . Set Clear ( ACT OR , ĠVersion Map ( ACT OR Ġto Ġ 1 )) ĊĠĠĠ Ġ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġsend Ops _ forward s Ops To Store Using Callback Token () Ġ= Ġrun Blocking Test Ġ{ ĊĠĠĠ Ġval Ġhelper Ġ= ĠRef Mode Store Helper ( ACT OR , Ġfake Store , Ġcallback Token Ġ= Ġ 1 2 3 ) ĊĠĠĠ Ġval Ġops Ġ= ĠarrayOf ( ĊĠĠĠĠĠ ĠRef Mode Store Op . Set Add (" a ", ĠVersion Map (" a " Ġto Ġ 1 ), ĠD UMMY _ ENTITY 1 ), ĊĠĠĠĠĠ ĠRef Mode Store Op . Set Add (" b ", ĠVersion Map (" b " Ġto Ġ 1 ), ĠD UMMY _ ENTITY 2 ) ĊĠĠĠ Ġ) ĊĊĠĠĠ Ġhelper . send Ops (* ops ) ĊĊĠĠĠ ĠassertThat ( captured Proxy Messages ). contains Exactly ( ĊĠĠĠĠĠ ĠProxy Message Operations ( ops . toList (), Ġid Ġ= Ġ 1 2 3 ) ĊĠĠĠ Ġ) ĊĠ Ġ} ĊĊĠ Ġ/** ĠChecks Ġthat Ġthe Ġ[ Proxy Message Operations ] Ġsent Ġto Ġthe Ġstore Ġmatch Ġthe Ġgiven Ġ[ ops ], Ġin Ġorder . Ġ*/ ĊĠ Ġprivate Ġfun Ġassert Proxy Messages ( var arg Ġops : ĠRef Mode Store Op ) Ġ{ ĊĠĠĠ Ġval Ġexpected Ġ= Ġops . map Ġ{ ĠProxy Message Operations ( listOf ( it ), Ġid Ġ= ĠDEFAULT _ CALLBACK _ TOKEN ) Ġ} ĊĠĠĠ ĠassertThat ( captured Proxy Messages ). contains Exactly Elements In ( expected ). in Order () ĊĠ Ġ} ĊĊĠ Ġprivate Ġcompanion Ġobject Ġ{ ĊĠĠĠ Ġprivate Ġconst Ġval ĠA CTOR Ġ= Ġ" ACT OR " ĊĠĠĠ Ġprivate Ġconst Ġval ĠDEFAULT _ CALLBACK _ TOKEN Ġ= Ġ 1 ĊĊĠĠĠ Ġprivate Ġval ĠD UMMY _ ENTITY 1 Ġ= ĠRaw Entity ( ĊĠĠĠĠĠ Ġid Ġ= Ġ" id 1 ", ĊĠĠĠĠĠ Ġsing letons Ġ= Ġempty Map (), ĊĠĠĠĠĠ Ġcollections Ġ= Ġempty Map () ĊĠĠĠ Ġ) ĊĠĠĠ Ġprivate Ġval ĠD UMMY _ ENTITY 2 Ġ= ĠRaw Entity ( ĊĠĠĠĠĠ Ġid Ġ= Ġ" id 2 ", ĊĠĠĠĠĠ Ġsing letons Ġ= Ġempty Map (), ĊĠĠĠĠĠ Ġcollections Ġ= Ġempty Map () ĊĠĠĠ Ġ) ĊĠ Ġ} Ċ } Ċ