package Ġorg . simple . clin ic . help Ċ Ċ import Ġcom . n ha ar man . mockito _ kotlin . any Ċ import Ġcom . n ha ar man . mockito _ kotlin . mock Ċ import Ġcom . n ha ar man . mockito _ kotlin . verify Ċ import Ġcom . n ha ar man . mockito _ kotlin . wh enever Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġorg . simple . clin ic . storage . files . Delete File Result Ċ import Ġorg . simple . clin ic . storage . files . File Storage Ċ import Ġorg . simple . clin ic . storage . files . Get File Result Ċ import Ġorg . simple . clin ic . storage . files . WriteFile Result Ċ import Ġorg . simple . clin ic . util . None Ċ import Ġorg . simple . clin ic . util . Rx Errors Rule Ċ import Ġorg . simple . clin ic . util . to Optional Ċ import Ġjava . io . File Ċ Ċ class ĠHelp Repository Test Ġ{ ĊĊĠ Ġ@ get : Rule ĊĠ Ġval Ġrx Errors Rule Ġ= ĠRx Errors Rule () ĊĊĠ Ġprivate Ġval Ġfile Storage Ġ= Ġmock < File Storage >() ĊĠ Ġprivate Ġval Ġfile Ġ= Ġmock < File >() ĊĠ Ġprivate Ġval Ġhelp FileName Ġ= Ġ" test . html " ĊĠ Ġprivate Ġval Ġrepository Ġ= ĠHelp Repository ( file Storage , Ġhelp FileName ) ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` updating Ġthe Ġhelp Ġshould Ġsave Ġit Ġto Ġthe Ġfile `() Ġ{ ĊĠĠĠ Ġwhenever ( file Storage . getFile ( any ())). thenReturn ( Get File Result . Success ( file )) ĊĠĠĠ Ġwhenever ( file Storage . write ToFile ( any (), Ġany ())). thenReturn ( WriteFile Result . Success ( file )) ĊĊĠĠĠ Ġval Ġhelp Content Ġ= Ġ" Help Ġcontents " ĊĠĠĠ Ġrepository . update Help ( help Content ). blocking Await () ĊĊĠĠĠ Ġverify ( file Storage ). write ToFile ( file , Ġhelp Content ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` getting Ġan Ġempty Ġfile Ġshould Ġemit ĠNone `() Ġ{ ĊĠĠĠ Ġwhenever ( file . length ()). thenReturn ( 0 L ) ĊĠĠĠ Ġwhenever ( file Storage . getFile ( any ())). thenReturn ( Get File Result . Success ( file )) ĊĊĠĠĠ Ġval Ġfile Stream Observer Ġ= Ġrepository . help File (). test () ĊĊĠĠĠ Ġfile Stream Observer . assert Value ( None ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` when Ġthe Ġhelp Ġfile Ġpath Ġis Ġnot Ġa Ġfile , Ġit Ġshould Ġemit ĠNone `() Ġ{ ĊĠĠĠ Ġwhenever ( file . length ()). thenReturn ( 0 L ) ĊĠĠĠ Ġwhenever ( file Storage . getFile ( any ())). thenReturn ( Get File Result . Not A File (" test ")) ĊĊĠĠĠ Ġval Ġrepository Ġ= ĠHelp Repository ( file Storage , Ġ" test ") ĊĊĠĠĠ Ġval Ġfile Stream Observer Ġ= Ġrepository . help File (). test () ĊĊĠĠĠ Ġfile Stream Observer . assert Value ( None ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` when Ġsub scri bing Ġto Ġthe Ġhelp Ġfile Ġstream , Ġthe Ġinitial Ġevent Ġshould Ġbe Ġemitted Ġwith Ġthe Ġfile `() Ġ{ ĊĠĠĠ Ġwhenever ( file . length ()). thenReturn ( 1 L ) ĊĠĠĠ Ġwhenever ( file Storage . getFile ( any ())). thenReturn ( Get File Result . Success ( file )) ĊĊĠĠĠ Ġval Ġfile Stream Observer Ġ= Ġrepository . help File (). test () ĊĊĠĠĠ Ġfile Stream Observer . assert Value ( file . to Optional ()) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` when Ġthe Ġhelp Ġfile Ġis Ġupdated , Ġthe Ġchange Ġnotification Ġshould Ġpublish Ġchanges `() Ġ{ ĊĠĠĠ Ġwhenever ( file . length ()). thenReturn ( 1 L ) ĊĠĠĠ Ġwhenever ( file Storage . getFile ( any ())). thenReturn ( Get File Result . Success ( file )) ĊĠĠĠ Ġwhenever ( file Storage . write ToFile ( any (), Ġany ())). thenReturn ( WriteFile Result . Success ( file )) ĊĊĠĠĠ Ġval Ġfile Stream Observer Ġ= Ġrepository . help File (). test () ĊĊĠĠĠ Ġrepository . update Help (" new Ġhelp Ġ 1 "). blocking Await () ĊĊĠĠĠ Ġfile Stream Observer . assert Values ( ĊĠĠĠĠĠĠĠ Ġfile . to Optional (), ĊĠĠĠĠĠĠĠ Ġfile . to Optional ()) ĊĊĠĠĠ Ġrepository . update Help (" new Ġhelp Ġ 2 "). blocking Await () ĊĊĠĠĠ Ġfile Stream Observer . assert Values ( ĊĠĠĠĠĠĠĠ Ġfile . to Optional (), ĊĠĠĠĠĠĠĠ Ġfile . to Optional (), ĊĠĠĠĠĠĠĠ Ġfile . to Optional ()) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` when Ġwriting Ġto Ġthe Ġhelp Ġfile Ġfails , Ġchange Ġnotification Ġshould Ġnot Ġbe Ġpublished `() Ġ{ ĊĠĠĠ Ġwhenever ( file . length ()). thenReturn ( 1 L ) ĊĠĠĠ Ġwhenever ( file Storage . getFile ( any ())). thenReturn ( Get File Result . Success ( file )) ĊĠĠĠ Ġwhenever ( file Storage . write ToFile ( any (), Ġany ())) ĊĠĠĠĠĠĠĠ Ġ. thenReturn ( WriteFile Result . Success ( file ), ĠWrite File Result . Failure ( RuntimeException (" Test ĠException ! "))) ĊĊĠĠĠ Ġval Ġfile Stream Observer Ġ= Ġrepository . help File (). test () ĊĊĠĠĠ Ġrepository . update Help (" new Ġhelp Ġ 1 "). blocking Await () ĊĊĠĠĠ Ġfile Stream Observer . assert Values ( ĊĠĠĠĠĠĠĠ Ġfile . to Optional (), ĊĠĠĠĠĠĠĠ Ġfile . to Optional ()) ĊĊĠĠĠ Ġrepository . update Help (" new Ġhelp Ġ 2 "). blocking Await () ĊĊĠĠĠ Ġfile Stream Observer . assert Values ( ĊĠĠĠĠĠĠĠ Ġfile . to Optional (), ĊĠĠĠĠĠĠĠ Ġfile . to Optional ()) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` when Ġfile Ġis Ġdeleted Ġthen Ġtrigger Ġa ĠNone Ġfile Ġnotification `() Ġ{ ĊĠĠĠ Ġwhenever ( file Storage . delete ( file )). thenReturn ( Delete File Result . Success ) ĊĠĠĠ Ġwhenever ( file . length ()). thenReturn ( 1 ) ĊĠĠĠ Ġwhenever ( file Storage . getFile ( help FileName )). thenReturn ( Get File Result . Success ( file )) ĊĊĠĠĠ Ġval Ġhelp FileStream Ġ= Ġrepository . help File (). test () ĊĠĠĠ Ġrepository . delete Help File (). test (). assert No Errors () ĊĊĠĠĠ Ġhelp FileStream . assert Values ( file . to Optional (), ĠNone ) ĊĠ Ġ} Ċ } Ċ