package Ġar cs . sdk . testing Ċ Ċ import Ġar cs . core . testutil . assert Variable Ordering Ċ import Ġar cs . core . testutil . group Ċ import Ġar cs . core . testutil . handles . dispatch Clear Ċ import Ġar cs . core . testutil . handles . dispatch Fetch Ċ import Ġar cs . core . testutil . handles . dispatch Fetch All Ċ import Ġar cs . core . testutil . handles . dispatch IsEmpty Ċ import Ġar cs . core . testutil . handles . dispatch Remove Ċ import Ġar cs . core . testutil . handles . dispatch Size Ċ import Ġar cs . core . testutil . handles . dispatch Store Ċ import Ġar cs . core . testutil . sequence Ċ import Ġcom . google . common . truth . Truth . assertThat Ċ import Ġkotlinx . coroutines . Experimental Cor outines Api Ċ import Ġkotlinx . coroutines . run Blocking Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . Description Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . junit . runners . JUnit 4 Ċ import Ġorg . junit . runners . model . Statement Ċ Ċ @ Opt In ( Experimental Cor outines Api :: class ) Ċ @ RunWith ( JUnit 4 :: class ) Ċ class ĠBase TestHarness Test Ġ{ ĊĠ Ġ@ Test ĊĠ Ġfun Ġhandle Helpers () Ġ{ ĊĠĠĠ Ġ// ĠVerify Ġthat Ġthe Ġeffects Ġof Ġcalling Ġthe Ġh arness Ġhandles Ġare Ġobservable Ġfrom Ġthe ĊĠĠĠ Ġ// Ġparticle Ġhandles . ĊĠĠĠ Ġval Ġh arness Ġ= Ġar cs . core . host . Multi Handle Particle TestHarness Ġ{ ĊĠĠĠĠĠ Ġar cs . core . host . Multi Handle Particle () ĊĠĠĠ Ġ} ĊĠĠĠ Ġrun Test ( h arness , Ġ" handle Helpers ") Ġ{ ĊĠĠĠĠĠ Ġh arness . start () ĊĊĠĠĠĠĠ Ġ// ĠSingleton Ġhandles ĊĠĠĠĠĠ Ġh arness . data . dispatch Store ( arcs . core . host . Multi Handle Particle _ Data ( 7 . 0 )) ĊĠĠĠĠĠ ĠassertThat ( h arness . data . dispatch Fetch ()?. num ). isEqualTo ( 7 . 0 ) ĊĊĠĠĠĠĠ Ġh arness . data . dispatch Clear () ĊĠĠĠĠĠ ĠassertThat ( h arness . data . dispatch Fetch ()). isNull () ĊĊĠĠĠĠĠ Ġ// ĠCollection Ġhandles ĊĠĠĠĠĠ Ġval Ġe 1 Ġ= Ġar cs . core . host . Multi Handle Particle _ List (" element 1 ") ĊĠĠĠĠĠ Ġval Ġe 2 Ġ= Ġar cs . core . host . Multi Handle Particle _ List (" element 2 ") ĊĠĠĠĠĠ Ġval Ġe 3 Ġ= Ġar cs . core . host . Multi Handle Particle _ List (" element 3 ") ĊĊĠĠĠĠĠ Ġh arness . list . dispatch Store ( e 1 , Ġe 2 , Ġe 3 ) ĊĠĠĠĠĠ ĠassertThat ( h arness . list . dispatch Size ()). isEqualTo ( 3 ) ĊĠĠĠĠĠ ĠassertThat ( h arness . list . dispatch IsEmpty ()). isEqualTo ( false ) ĊĠĠĠĠĠ ĠassertThat ( h arness . list . dispatch Fetch All ()). isEqualTo ( set Of ( e 1 , Ġe 2 , Ġe 3 )) ĊĊĠĠĠĠĠ Ġh arness . list . dispatch Remove ( e 2 ) ĊĠĠĠĠĠ ĠassertThat ( h arness . list . dispatch Size ()). isEqualTo ( 2 ) ĊĠĠĠĠĠ ĠassertThat ( h arness . list . dispatch IsEmpty ()). isEqualTo ( false ) ĊĠĠĠĠĠ ĠassertThat ( h arness . list . dispatch Fetch All ()). isEqualTo ( set Of ( e 1 , Ġe 3 )) ĊĊĠĠĠĠĠ Ġh arness . list . dispatch Clear () ĊĠĠĠĠĠ ĠassertThat ( h arness . list . dispatch Size ()). isEqualTo ( 0 ) ĊĠĠĠĠĠ ĠassertThat ( h arness . list . dispatch IsEmpty ()). isEqualTo ( true ) ĊĠĠĠĠĠ ĠassertThat ( h arness . list . dispatch Fetch All ()). isEmpty () ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġsingle Read Handle () Ġ{ ĊĠĠĠ Ġval Ġh arness Ġ= Ġar cs . core . host . Single Read Handle Particle TestHarness Ġ{ ĊĠĠĠĠĠ Ġar cs . core . host . Single Read Handle Particle () ĊĠĠĠ Ġ} ĊĠĠĠ Ġrun Test ( h arness , Ġ" single Read Handle ") Ġ{ ĊĠĠĠĠĠ Ġh arness . start () ĊĠĠĠĠĠ ĠassertThat ( h arness . particle . events ) ĊĠĠĠĠĠĠĠ Ġ. isEqualTo ( listOf (" on First Start ", Ġ" onStart ", Ġ" data . on Ready : null ", Ġ" on Ready : null ")) ĊĠĠĠĠĠ Ġh arness . particle . events . clear () ĊĊĠĠĠĠĠ Ġh arness . data . dispatch Store ( arcs . core . host . Single Read Handle Particle _ Data ( 5 . 0 )) ĊĠĠĠĠĠ ĠassertThat ( h arness . particle . events ) ĊĠĠĠĠĠĠĠ Ġ. isEqualTo ( listOf (" data . on Update : 5 . 0 ", Ġ" on Update : 5 . 0 ")) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġsingle Write Handle () Ġ{ ĊĠĠĠ Ġval Ġh arness Ġ= Ġar cs . core . host . Single Write Handle Particle TestHarness Ġ{ ĊĠĠĠĠĠ Ġar cs . core . host . Single Write Handle Particle () ĊĠĠĠ Ġ} ĊĠĠĠ Ġrun Test ( h arness , Ġ" single Write Handle ") Ġ{ ĊĠĠĠĠĠ Ġh arness . start () ĊĠĠĠĠĠ ĠassertThat ( h arness . particle . events ) ĊĠĠĠĠĠĠĠ Ġ. isEqualTo ( listOf (" on First Start ", Ġ" onStart ", Ġ" on Ready ")) ĊĠĠĠĠĠ Ġh arness . particle . events . clear () ĊĊĠĠĠĠĠ Ġh arness . data . dispatch Store ( arcs . core . host . Single Write Handle Particle _ Data ( 5 . 0 )) ĊĠĠĠĠĠ ĠassertThat ( h arness . particle . events ). isEmpty () ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġmulti Handle () Ġ{ ĊĠĠĠ Ġval Ġh arness Ġ= Ġar cs . core . host . Multi Handle Particle TestHarness Ġ{ ĊĠĠĠĠĠ Ġar cs . core . host . Multi Handle Particle () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġrun Test ( h arness , Ġ" multi Handle ") Ġ{ ĊĠĠĠĠĠ Ġh arness . start () ĊĠĠĠĠĠ Ġh arness . data . dispatch Store ( arcs . core . host . Multi Handle Particle _ Data ( 3 . 2 )) ĊĠĠĠĠĠ Ġh arness . list . dispatch Store ( arcs . core . host . Multi Handle Particle _ List (" hi ")) ĊĠĠĠĠĠ Ġh arness . result . dispatch Store ( arcs . core . host . Multi Handle Particle _ Result ( 1 9 . 0 )) ĊĠĠĠĠĠ Ġh arness . config . dispatch Store ( arcs . core . host . Multi Handle Particle _ Config ( true )) ĊĠĠĠĠĠ Ġassert Variable Ordering ( ĊĠĠĠĠĠĠĠ Ġh arness . particle . events , ĊĠĠĠĠĠĠĠ Ġsequence ( ĊĠĠĠĠĠĠĠĠĠ Ġsequence (" on First Start ", Ġ" onStart "), ĊĠĠĠĠĠĠĠĠĠ Ġ// ĠHandle Ġon Ready Ġevents Ġare Ġnot Ġguaranteed Ġto Ġbe Ġin Ġany Ġspecific Ġorder . ĊĠĠĠĠĠĠĠĠĠ Ġgroup (" data . on Ready : null ", Ġ" list . on Ready : [] ", Ġ" config . on Ready : null "), ĊĠĠĠĠĠĠĠĠĠ Ġsequence ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" on Ready : null : [] : null ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" data . on Update : 3 . 2 ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" on Update : 3 . 2 : [] : null ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" list . on Update :[ hi ]", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" on Update : 3 . 2 :[ hi ]: null ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" config . on Update : true ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" on Update : 3 . 2 :[ hi ]: true " ĊĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ// ĠBase TestHarness Ġis Ġset Ġup Ġas Ġa ĠTest Rule . ĠUsing Ġmore Ġthan Ġone Ġh arness Ġas Ġintended Ġin Ġthe Ġsame ĊĠ Ġ// Ġtest Ġclass Ġdoesn 't Ġwork : Ġevery Ġrule Ġis Ġrun Ġfor Ġevery Ġtest Ġmethod , Ġwhere Ġwe Ġwant Ġeach Ġh arness ĊĠ Ġ// Ġto Ġbe Ġpeg ged Ġto Ġone Ġspecific Ġmethod . ĠThus Ġwe Ġneed Ġto Ġmanually Ġdrive Ġthe Ġh arness Ġclass Ġin Ġthe ĊĠ Ġ// Ġsame Ġway Ġthat Ġthe Ġ@ Rule Ġinvocation Ġdoes . ĊĠ Ġprivate Ġfun Ġrun Test ( h arness : ĠBase TestHarness <* >, Ġmethod : ĠString , Ġblock : Ġsuspend Ġ() Ġ-> ĠUnit ) Ġ{ ĊĠĠĠ Ġval Ġstatement Ġ= Ġobject Ġ: ĠStatement () Ġ{ ĊĠĠĠĠĠ Ġoverride Ġfun Ġevaluate () Ġ{ ĊĠĠĠĠĠĠĠ Ġrun Blocking Ġ{ Ġblock () Ġ} ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠĠĠ Ġval Ġdescription Ġ= ĠDescription . create Test Description (" Base TestHarness Test ", Ġmethod ) ĊĠĠĠ Ġh arness . apply ( statement , Ġdescription ). evaluate () ĊĠ Ġ} Ċ } Ċ