package Ġcom . ny times . android . external . fs 3 Ċ Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . mock Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . wh enever Ċ import Ġcom . ny times . android . external . store 3 . base . Fetcher Ċ import Ġcom . ny times . android . external . store 3 . base . Pers ister Ċ import Ġcom . ny times . android . external . store 3 . base . Record Provider Ċ import Ġcom . ny times . android . external . store 3 . base . Record State Ċ import Ġcom . ny times . android . external . store 3 . base . impl . Bar Code Ċ import Ġcom . ny times . android . external . store 3 . base . impl . Store Builder Ċ import Ġkotlinx . coroutines . run Blocking Ċ import Ġok io . Buffered Source Ċ import Ġorg . assertj . core . api . Assertions . assertThat Ċ import Ġorg . assertj . core . api . Assertions . fail Ċ import Ġorg . junit . Test Ċ import Ġorg . mockito . Mockito . times Ċ import Ġorg . mockito . Mockito . verify Ċ Ċ class ĠStore Network Before St ale Fail Test Ġ{ ĊĠĠĠ Ġprivate Ġval Ġfetch er : ĠFetch er < Buffered Source , ĠBar Code > Ġ= Ġmock () ĊĠĠĠ Ġprivate Ġval Ġstore Ġ= ĠStore Builder . barcode < Buffered Source >() ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. fetcher ( fetcher ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. pers ister ( Test Pers ister ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. network Before St ale () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. open () ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġnetwork Before St ale No Network Response () Ġ= Ġrun Blocking < Unit > Ġ{ ĊĠĠĠĠĠĠĠ Ġwhenever ( fetcher . fetch ( bar Code )). then Throw ( SOR RY ) ĊĠĠĠĠĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġstore . get ( bar Code ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfail (" Exception Ġnot Ġthrown ") ĊĠĠĠĠĠĠĠ Ġ} Ġcatch Ġ( e : ĠException ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( e . localized Message ). isEqualTo ( SOR RY . localized Message ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġverify ( fetcher , Ġtimes ( 1 )). fetch ( bar Code ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġclass ĠTest Pers ister Ġ: ĠPers ister < Buffered Source , ĠBar Code >, ĠRecord Provider < Bar Code > Ġ{ ĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġget Record State ( bar Code : ĠBar Code ): ĠRecord State Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn ĠRecord State . MISSING ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġoverride Ġsuspend Ġfun Ġread ( key : ĠBar Code ): ĠBuffered Source ? Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġthrow ĠS OR RY ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġoverride Ġsuspend Ġfun Ġwrite ( key : ĠBar Code , Ġraw : ĠBuffered Source ) Ġ= Ġtrue ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġprivate Ġval ĠS OR RY Ġ= ĠRuntimeException (" sor ry ") ĊĠĠĠĠĠĠĠ Ġprivate Ġval Ġbar Code Ġ= ĠBar Code (" key ", Ġ" value ") ĊĠĠĠ Ġ} Ċ } Ċ